You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ph...@apache.org on 2012/07/03 18:03:10 UTC

svn commit: r1356804 [4/12] - in /xmlgraphics/fop/branches/Temp_RoundedCorners: ./ examples/embedding/java/embedding/ examples/embedding/java/embedding/atxml/ examples/embedding/java/embedding/events/ examples/embedding/java/embedding/intermediate/ src...

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontLoader.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontLoader.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontLoader.java Tue Jul  3 16:01:48 2012
@@ -19,18 +19,13 @@
 
 package org.apache.fop.fonts;
 
-import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
+import java.net.URI;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.truetype.TTFFontLoader;
 import org.apache.fop.fonts.type1.Type1FontLoader;
 
@@ -43,9 +38,9 @@ public abstract class FontLoader {
     protected static final Log log = LogFactory.getLog(FontLoader.class);
 
     /** URI representing the font file */
-    protected String fontFileURI;
-    /** the FontResolver to use for font URI resolution */
-    protected FontResolver resolver;
+    protected final URI fontFileURI;
+    /** the resource resolver to use for font URI resolution */
+    protected final InternalResourceResolver resourceResolver;
     /** the loaded font */
     protected CustomFont returnFont;
 
@@ -65,56 +60,19 @@ public abstract class FontLoader {
      * @param useKerning indicates whether kerning information shall be loaded if available
      * @param useAdvanced indicates whether advanced typographic information shall be loaded if
      * available
-     * @param resolver the font resolver used to resolve URIs
+     * @param resourceResolver the font resolver used to resolve URIs
      */
-    public FontLoader(String fontFileURI, boolean embedded, boolean useKerning,
-            boolean useAdvanced, FontResolver resolver) {
+    public FontLoader(URI fontFileURI, boolean embedded, boolean useKerning,
+            boolean useAdvanced, InternalResourceResolver resourceResolver) {
         this.fontFileURI = fontFileURI;
         this.embedded = embedded;
         this.useKerning = useKerning;
         this.useAdvanced = useAdvanced;
-        this.resolver = resolver;
+        this.resourceResolver = resourceResolver;
     }
 
-    private static boolean isType1(String fontURI) {
-        return fontURI.toLowerCase().endsWith(".pfb");
-    }
-
-    /**
-     * Loads a custom font from a File. In the case of Type 1 fonts, the PFB file must be specified.
-     * @param fontFile the File representation of the font
-     * @param subFontName the sub-fontname of a font (for TrueType Collections, null otherwise)
-     * @param embedded indicates whether the font is embedded or referenced
-     * @param embeddingMode the embedding mode
-     * @param encodingMode the requested encoding mode
-     * @param resolver the font resolver to use when resolving URIs
-     * @return the newly loaded font
-     * @throws IOException In case of an I/O error
-     */
-    public static CustomFont loadFont(File fontFile, String subFontName,
-            boolean embedded, EmbeddingMode embeddingMode, EncodingMode encodingMode,
-            FontResolver resolver) throws IOException {
-        return loadFont(fontFile.toURI().toURL(), subFontName,
-                embedded, embeddingMode, encodingMode, resolver);
-    }
-
-    /**
-     * Loads a custom font from an URL. In the case of Type 1 fonts, the PFB file must be specified.
-     * @param fontUrl the URL representation of the font
-     * @param subFontName the sub-fontname of a font (for TrueType Collections, null otherwise)
-     * @param embedded indicates whether the font is embedded or referenced
-     * @param embeddingMode the embedding mode of the font
-     * @param encodingMode the requested encoding mode
-     * @param resolver the font resolver to use when resolving URIs
-     * @return the newly loaded font
-     * @throws IOException In case of an I/O error
-     */
-    public static CustomFont loadFont(URL fontUrl, String subFontName,
-            boolean embedded, EmbeddingMode embeddingMode, EncodingMode encodingMode,
-            FontResolver resolver) throws IOException {
-        return loadFont(fontUrl.toExternalForm(), subFontName,
-                embedded, embeddingMode, encodingMode, true, true,
-                resolver);
+    private static boolean isType1(URI fontURI) {
+        return fontURI.toASCIIString().toLowerCase().endsWith(".pfb");
     }
 
     /**
@@ -127,14 +85,13 @@ public abstract class FontLoader {
      * @param useKerning indicates whether kerning information should be loaded if available
      * @param useAdvanced indicates whether advanced typographic information shall be loaded if
      * available
-     * @param resolver the font resolver to use when resolving URIs
+     * @param resourceResolver the font resolver to use when resolving URIs
      * @return the newly loaded font
      * @throws IOException In case of an I/O error
      */
-    public static CustomFont loadFont(String fontFileURI, String subFontName,
+    public static CustomFont loadFont(URI fontFileURI, String subFontName,
             boolean embedded, EmbeddingMode embeddingMode, EncodingMode encodingMode,
-            boolean useKerning, boolean useAdvanced, FontResolver resolver) throws IOException {
-        fontFileURI = fontFileURI.trim();
+            boolean useKerning, boolean useAdvanced, InternalResourceResolver resourceResolver) throws IOException {
         boolean type1 = isType1(fontFileURI);
         FontLoader loader;
         if (type1) {
@@ -146,50 +103,15 @@ public abstract class FontLoader {
                 throw new IllegalArgumentException(
                         "Subset embedding for Type 1 fonts is not supported");
             }
-            loader = new Type1FontLoader(fontFileURI, embedded, useKerning, resolver);
+            loader = new Type1FontLoader(fontFileURI, embedded, useKerning, resourceResolver);
         } else {
-            loader = new TTFFontLoader(fontFileURI, subFontName,
-                    embedded, embeddingMode, encodingMode, useKerning, useAdvanced, resolver);
+            loader = new TTFFontLoader(fontFileURI, subFontName, embedded, embeddingMode,
+                    encodingMode, useKerning, useAdvanced, resourceResolver);
         }
         return loader.getFont();
     }
 
     /**
-     * Opens a font URI and returns an input stream.
-     * @param resolver the FontResolver to use for font URI resolution
-     * @param uri the URI representing the font
-     * @return the InputStream to read the font from.
-     * @throws IOException In case of an I/O error
-     * @throws MalformedURLException If an invalid URL is built
-     */
-    public static InputStream openFontUri(FontResolver resolver, String uri)
-                    throws IOException, MalformedURLException {
-        InputStream in = null;
-        if (resolver != null) {
-            Source source = resolver.resolve(uri);
-            if (source == null) {
-                String err = "Cannot load font: failed to create Source for font file "
-                    + uri;
-                throw new IOException(err);
-            }
-            if (source instanceof StreamSource) {
-                in = ((StreamSource) source).getInputStream();
-            }
-            if (in == null && source.getSystemId() != null) {
-                in = new java.net.URL(source.getSystemId()).openStream();
-            }
-            if (in == null) {
-                String err = "Cannot load font: failed to create InputStream from"
-                    + " Source for font file " + uri;
-                throw new IOException(err);
-            }
-        } else {
-            in = new URL(uri).openStream();
-        }
-        return in;
-    }
-
-    /**
      * Reads/parses the font data.
      * @throws IOException In case of an I/O error
      */

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontManager.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontManager.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontManager.java Tue Jul  3 16:01:48 2012
@@ -20,13 +20,10 @@
 package org.apache.fop.fonts;
 
 import java.io.File;
-import java.net.MalformedURLException;
 import java.util.List;
 
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.FontTriplet.Matcher;
 import org.apache.fop.fonts.substitute.FontSubstitutions;
 
@@ -38,14 +35,13 @@ import org.apache.fop.fonts.substitute.F
  * font substitution, referenced fonts and similar.
  */
 public class FontManager {
-    /** Use cache (record previously detected font triplet info) */
-    public static final boolean DEFAULT_USE_CACHE = true;
 
-    /** The base URL for all font URL resolutions. */
-    private String fontBase = null;
+    /** The resource resolver */
+    private InternalResourceResolver resourceResolver;
+
+    private final FontDetector fontDetector;
 
-    /** Font cache to speed up auto-font configuration (null if disabled) */
-    private FontCache fontCache = null;
+    private FontCacheManager fontCacheManager;
 
     /** Font substitutions */
     private FontSubstitutions fontSubstitutions = null;
@@ -56,33 +52,33 @@ public class FontManager {
     /** FontTriplet matcher for fonts that shall be referenced rather than embedded. */
     private FontTriplet.Matcher referencedFontsMatcher;
 
-    /** Enables/disables the use of font caching */
-    private boolean useCache = DEFAULT_USE_CACHE;
-
     /** Provides a font cache file path **/
     private File cacheFile;
 
     /**
      * Main constructor
+     *
+     * @param resourceResolver the URI resolver
+     * @param fontDetector the font detector
+     * @param fontCacheManager the font cache manager
      */
-    public FontManager() {
+    public FontManager(InternalResourceResolver resourceResolver, FontDetector fontDetector,
+            FontCacheManager fontCacheManager) {
+        this.resourceResolver = resourceResolver;
+        this.fontDetector = fontDetector;
+        this.fontCacheManager = fontCacheManager;
     }
 
     /**
-     * Sets the font base URL.
-     * @param fontBase font base URL
-     * @throws MalformedURLException if there's a problem with a URL
+     * Sets the font resource resolver
+     * @param resourceResolver resource resolver
      */
-    public void setFontBaseURL(String fontBase) throws MalformedURLException {
-        this.fontBase = fontBase;
+    public void setResourceResolver(InternalResourceResolver resourceResolver) {
+        this.resourceResolver = resourceResolver;
     }
 
-    /**
-     * Returns the font base URL.
-     * @return the font base URL (or null if none was set)
-     */
-    public String getFontBaseURL() {
-        return this.fontBase;
+    public InternalResourceResolver getResourceResolver() {
+        return this.resourceResolver;
     }
 
     /** @return true if kerning on base 14 fonts is enabled */
@@ -130,29 +126,22 @@ public class FontManager {
      * @return the font cache file
      */
     public File getCacheFile() {
+        return getCacheFile(false);
+    }
+
+    private File getCacheFile(boolean writable) {
         if (cacheFile != null) {
-            return this.cacheFile;
+            return cacheFile;
         }
-        return FontCache.getDefaultCacheFile(false);
+        return FontCache.getDefaultCacheFile(writable);
     }
 
     /**
      * Whether or not to cache results of font triplet detection/auto-config
      * @param useCache use cache or not
      */
-    public void setUseCache(boolean useCache) {
-        this.useCache = useCache;
-        if (!useCache) {
-            this.fontCache = null;
-        }
-    }
-
-    /**
-     * Cache results of font triplet detection/auto-config?
-     * @return true if this font manager uses the cache
-     */
-    public boolean useCache() {
-        return useCache;
+    public void disableFontCache() {
+        fontCacheManager = FontCacheManagerFactory.createDisabled();
     }
 
     /**
@@ -160,19 +149,7 @@ public class FontManager {
      * @return the font cache
      */
     public FontCache getFontCache() {
-        if (fontCache == null) {
-            if (useCache) {
-                if (cacheFile != null) {
-                    fontCache = FontCache.loadFrom(cacheFile);
-                } else {
-                    fontCache = FontCache.load();
-                }
-                if (fontCache == null) {
-                    fontCache = new FontCache();
-                }
-            }
-        }
-        return fontCache;
+        return fontCacheManager.load(getCacheFile());
     }
 
     /**
@@ -181,31 +158,16 @@ public class FontManager {
      * @throws FOPException fop exception
      */
     public void saveCache() throws FOPException {
-        if (useCache) {
-            if (fontCache != null && fontCache.hasChanged()) {
-                if (cacheFile != null) {
-                    fontCache.saveTo(cacheFile);
-                } else {
-                    fontCache.save();
-                }
-            }
-        }
+        fontCacheManager.save(getCacheFile());
     }
 
     /**
      * Deletes the current FontCache file
      * @return Returns true if the font cache file was successfully deleted.
+     * @throws FOPException -
      */
-    public boolean deleteCache() {
-        boolean deleted = false;
-        if (useCache) {
-            if (cacheFile != null) {
-                deleted = cacheFile.delete();
-            } else {
-                deleted = FontCache.getDefaultCacheFile(true).delete();
-            }
-        }
-        return deleted;
+    public void deleteCache() throws FOPException {
+        fontCacheManager.delete(getCacheFile(true));
     }
 
     /**
@@ -225,34 +187,6 @@ public class FontManager {
     }
 
     /**
-     * Minimum implemenation of FontResolver.
-     */
-    public static class MinimalFontResolver implements FontResolver {
-        private boolean useComplexScriptFeatures;
-        MinimalFontResolver(boolean useComplexScriptFeatures) {
-            this.useComplexScriptFeatures = useComplexScriptFeatures;
-        }
-        /** {@inheritDoc} */
-        public Source resolve(String href) {
-            //Minimal functionality here
-            return new StreamSource(href);
-        }
-        /** {@inheritDoc} */
-        public boolean isComplexScriptFeaturesEnabled() {
-            return useComplexScriptFeatures;
-        }
-    }
-
-    /**
-     * Create minimal font resolver.
-     * @param useComplexScriptFeatures true if complex script features enabled
-     * @return a new FontResolver to be used by the font subsystem
-     */
-    public static FontResolver createMinimalFontResolver(boolean useComplexScriptFeatures) {
-        return new MinimalFontResolver ( useComplexScriptFeatures );
-    }
-
-    /**
      * Sets the {@link FontTriplet.Matcher} that can be used to identify the fonts that shall
      * be referenced rather than embedded.
      * @param matcher the font triplet matcher
@@ -298,4 +232,21 @@ public class FontManager {
             }
         }
     }
+
+    /**
+     * Detect fonts from the operating system via FOPs autodetect mechanism.
+     *
+     * @param autoDetectFonts if autodetect has been enabled
+     * @param fontAdder the font adding mechanism
+     * @param strict whether to enforce strict validation
+     * @param listener the listener for font related events
+     * @param fontInfoList a list of font info objects
+     * @throws FOPException if an exception was thrown auto-detecting fonts
+     */
+    public void autoDetectFonts(boolean autoDetectFonts, FontAdder fontAdder, boolean strict,
+            FontEventListener  listener, List<EmbedFontInfo> fontInfoList) throws FOPException {
+        if (autoDetectFonts) {
+            fontDetector.detect(this, fontAdder, strict, listener, fontInfoList);
+        }
+    }
 }

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontManagerConfigurator.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontManagerConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontManagerConfigurator.java Tue Jul  3 16:01:48 2012
@@ -20,8 +20,8 @@
 package org.apache.fop.fonts;
 
 import java.io.File;
-import java.net.MalformedURLException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.List;
 import java.util.regex.Pattern;
 
@@ -31,6 +31,9 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.io.InternalResourceResolver;
+import org.apache.fop.apps.io.ResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.fonts.substitute.FontSubstitutions;
 import org.apache.fop.fonts.substitute.FontSubstitutionsConfigurator;
 import org.apache.fop.util.LogUtil;
@@ -45,24 +48,21 @@ public class FontManagerConfigurator {
 
     private final Configuration cfg;
 
-    private URI baseURI = null;
+    private final URI defaultBaseUri;
 
-    /**
-     * Main constructor
-     * @param cfg the font manager configuration object
-     */
-    public FontManagerConfigurator(Configuration cfg) {
-        this.cfg = cfg;
-    }
+    private final ResourceResolver resourceResolver;
 
     /**
      * Main constructor
      * @param cfg the font manager configuration object
-     * @param baseURI the base URI of the configuration
+     * @param defaultBaseUri the default URI base to use for URI resolution
+     * @param resourceResolver the resource resolver
      */
-    public FontManagerConfigurator(Configuration cfg, URI baseURI) {
+    public FontManagerConfigurator(Configuration cfg, URI defaultBaseUri,
+            ResourceResolver resourceResolver) {
         this.cfg = cfg;
-        this.baseURI = baseURI;
+        this.defaultBaseUri = defaultBaseUri;
+        this.resourceResolver = resourceResolver;
     }
 
     /**
@@ -75,28 +75,29 @@ public class FontManagerConfigurator {
         // caching (fonts)
         if (cfg.getChild("use-cache", false) != null) {
             try {
-                fontManager.setUseCache(cfg.getChild("use-cache").getValueAsBoolean());
-            } catch (ConfigurationException e) {
-                LogUtil.handleException(log, e, true);
-            }
-        }
-        if (cfg.getChild("cache-file", false) != null) {
-            try {
-                fontManager.setCacheFile(new File(cfg.getChild("cache-file").getValue()));
-            } catch (ConfigurationException e) {
-                LogUtil.handleException(log, e, true);
+                if (!cfg.getChild("use-cache").getValueAsBoolean()) {
+                    fontManager.disableFontCache();
+                } else {
+                    if (cfg.getChild("cache-file", false) != null) {
+                        fontManager.setCacheFile(new File(cfg.getChild("cache-file").getValue()));
+                    }
+                }
+            } catch (ConfigurationException mfue) {
+                LogUtil.handleException(log, mfue, true);
             }
         }
         if (cfg.getChild("font-base", false) != null) {
-            String path = cfg.getChild("font-base").getValue(null);
-            if (baseURI != null) {
-                path = baseURI.resolve(path).normalize().toString();
-            }
             try {
-                fontManager.setFontBaseURL(path);
-            } catch (MalformedURLException mfue) {
-                LogUtil.handleException(log, mfue, true);
-            }
+                URI fontBase = InternalResourceResolver.getBaseURI(cfg.getChild("font-base").getValue(
+                        null));
+                fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver(
+                        defaultBaseUri.resolve(fontBase), resourceResolver));
+            } catch (URISyntaxException use) {
+                LogUtil.handleException(log, use, true);
+            }
+        } else {
+            fontManager.setResourceResolver(ResourceResolverFactory.createInternalResourceResolver(
+                    defaultBaseUri, resourceResolver));
         }
 
         // [GA] permit configuration control over base14 kerning; without this,
@@ -114,7 +115,6 @@ public class FontManagerConfigurator {
         // global font configuration
         Configuration fontsCfg = cfg.getChild("fonts", false);
         if (fontsCfg != null) {
-
             // font substitution
             Configuration substitutionsCfg = fontsCfg.getChild("substitutions", false);
             if (substitutionsCfg != null) {
@@ -122,7 +122,6 @@ public class FontManagerConfigurator {
                 new FontSubstitutionsConfigurator(substitutionsCfg).configure(substitutions);
                 fontManager.setFontSubstitutions(substitutions);
             }
-
             // referenced fonts (fonts which are not to be embedded)
             Configuration referencedFontsCfg = fontsCfg.getChild("referenced-fonts", false);
             if (referencedFontsCfg != null) {
@@ -130,7 +129,6 @@ public class FontManagerConfigurator {
                         referencedFontsCfg, strict);
                 fontManager.setReferencedFontsMatcher(matcher);
             }
-
         }
     }
 
@@ -159,6 +157,24 @@ public class FontManagerConfigurator {
         return orMatcher;
     }
 
+    /**
+     * Creates a font triplet matcher from a configuration object.
+     * @param fontFamilies the list of font families
+     * @param strict true for strict configuraton error handling
+     * @return the font matcher
+     * @throws FOPException if an error occurs while building the matcher
+     */
+    public static FontTriplet.Matcher createFontsMatcher(
+            List<String> fontFamilies, boolean strict) throws FOPException {
+        List<FontTriplet.Matcher> matcherList = new java.util.ArrayList<FontTriplet.Matcher>();
+        for (String fontFamily : fontFamilies) {
+                matcherList.add(new FontFamilyRegExFontTripletMatcher(fontFamily));
+        }
+        FontTriplet.Matcher orMatcher = new OrFontTripletMatcher(
+                matcherList.toArray(new FontTriplet.Matcher[matcherList.size()]));
+        return orMatcher;
+    }
+
     private static class OrFontTripletMatcher implements FontTriplet.Matcher {
 
         private final FontTriplet.Matcher[] matchers;

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontReader.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontReader.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontReader.java Tue Jul  3 16:01:48 2012
@@ -21,6 +21,8 @@ package org.apache.fop.fonts;
 
 //Java
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -32,12 +34,12 @@ import javax.xml.parsers.SAXParserFactor
 
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.DefaultHandler;
 
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.apps.TTFReader;
 
 /**
@@ -52,19 +54,30 @@ import org.apache.fop.fonts.apps.TTFRead
  */
 public class FontReader extends DefaultHandler {
 
-    // private Locator locator = null; // not used at present
-    private boolean isCID = false;
-    private CustomFont returnFont = null;
-    private MultiByteFont multiFont = null;
-    private SingleByteFont singleFont = null;
+    private boolean isCID;
+    private CustomFont returnFont;
+    private MultiByteFont multiFont;
+    private SingleByteFont singleFont;
+    private final InternalResourceResolver resourceResolver;
     private StringBuffer text = new StringBuffer();
 
-    private List<Integer> cidWidths = null;
-    private int cidWidthIndex = 0;
+    private List<Integer> cidWidths;
+    //private int cidWidthIndex;
 
-    private Map<Integer, Integer> currentKerning = null;
+    private Map<Integer, Integer> currentKerning;
 
-    private List<CMapSegment> bfranges = null;
+    private List<CMapSegment> bfranges;
+
+    /**
+     * Construct a FontReader object from a path to a metric.xml file
+     * and read metric data
+     * @param source Source of the font metric file
+     * @throws FOPException if loading the font fails
+     */
+    public FontReader(InputSource source, InternalResourceResolver resourceResolver) throws FOPException {
+        this.resourceResolver = resourceResolver;
+        createFont(source);
+    }
 
     private void createFont(InputSource source) throws FOPException {
         XMLReader parser = null;
@@ -81,11 +94,9 @@ public class FontReader extends DefaultH
         }
 
         try {
-            parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
-                              false);
+            parser.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
         } catch (SAXException e) {
-            throw new FOPException("You need a SAX parser which supports SAX version 2",
-                                   e);
+            throw new FOPException("You need a SAX parser which supports SAX version 2", e);
         }
 
         parser.setContentHandler(this);
@@ -104,8 +115,8 @@ public class FontReader extends DefaultH
      * Sets the path to embed a font. A null value disables font embedding.
      * @param path URI for the embeddable file
      */
-    public void setFontEmbedPath(String path) {
-        returnFont.setEmbedFileName(path);
+    public void setFontEmbedURI(URI path) {
+        returnFont.setEmbedURI(path);
     }
 
     /**
@@ -125,15 +136,6 @@ public class FontReader extends DefaultH
     }
 
     /**
-     * Sets the font resolver. Needed for URI resolution.
-     * @param resolver the font resolver
-     */
-    public void setResolver(FontResolver resolver) {
-        returnFont.setResolver(resolver);
-    }
-
-
-    /**
      * Get the generated font object
      * @return the font
      */
@@ -142,16 +144,6 @@ public class FontReader extends DefaultH
     }
 
     /**
-     * Construct a FontReader object from a path to a metric.xml file
-     * and read metric data
-     * @param source Source of the font metric file
-     * @throws FOPException if loading the font fails
-     */
-    public FontReader(InputSource source) throws FOPException {
-        createFont(source);
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override
@@ -161,45 +153,41 @@ public class FontReader extends DefaultH
     /**
      * {@inheritDoc}
      */
-    @Override
-    public void setDocumentLocator(Locator locator) {
-        // this.locator = locator; // not used at present
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void startElement(String uri, String localName, String qName,
-                             Attributes attributes) throws SAXException {
+    public void startElement(String uri, String localName, String qName, Attributes attributes)
+            throws SAXException {
         if (localName.equals("font-metrics")) {
             if ("TYPE0".equals(attributes.getValue("type"))) {
-                multiFont = new MultiByteFont();
+                multiFont = new MultiByteFont(resourceResolver);
                 returnFont = multiFont;
                 isCID = true;
                 TTFReader.checkMetricsVersion(attributes);
             } else if ("TRUETYPE".equals(attributes.getValue("type"))) {
-                singleFont = new SingleByteFont();
+                singleFont = new SingleByteFont(resourceResolver);
                 singleFont.setFontType(FontType.TRUETYPE);
                 returnFont = singleFont;
                 isCID = false;
                 TTFReader.checkMetricsVersion(attributes);
             } else {
-                singleFont = new SingleByteFont();
+                singleFont = new SingleByteFont(resourceResolver);
                 singleFont.setFontType(FontType.TYPE1);
                 returnFont = singleFont;
                 isCID = false;
             }
         } else if ("embed".equals(localName)) {
-            returnFont.setEmbedFileName(attributes.getValue("file"));
+            try {
+                returnFont.setEmbedURI(InternalResourceResolver.cleanURI(attributes.getValue("file")));
+            } catch (URISyntaxException e) {
+                throw new SAXException("URI syntax error in metrics file: " + e.getMessage(), e);
+            }
             returnFont.setEmbedResourceName(attributes.getValue("class"));
         } else if ("cid-widths".equals(localName)) {
-            cidWidthIndex = getInt(attributes.getValue("start-index"));
+            // This is unused
+            // cidWidthIndex = getInt(attributes.getValue("start-index"));
             cidWidths = new ArrayList<Integer>();
         } else if ("kerning".equals(localName)) {
             currentKerning = new HashMap<Integer, Integer>();
-            returnFont.putKerningEntry(new Integer(attributes.getValue("kpx1")),
-                                        currentKerning);
+            returnFont.putKerningEntry(getInt(attributes.getValue("kpx1")),
+                    currentKerning);
         } else if ("bfranges".equals(localName)) {
             bfranges = new ArrayList<CMapSegment>();
         } else if ("bf".equals(localName)) {
@@ -208,20 +196,19 @@ public class FontReader extends DefaultH
                                         getInt(attributes.getValue("gi")));
             bfranges.add(entry);
         } else if ("wx".equals(localName)) {
-            cidWidths.add(new Integer(attributes.getValue("w")));
-        } else if ("widths".equals(localName)) {
-            //singleFont.width = new int[256];
+            cidWidths.add(getInt(attributes.getValue("w")));
+            // } else if ("widths".equals(localName)) {
+            //    singleFont.width = new int[256];
         } else if ("char".equals(localName)) {
             try {
-                singleFont.setWidth(Integer.parseInt(attributes.getValue("idx")),
-                        Integer.parseInt(attributes.getValue("wdt")));
+                singleFont.setWidth(getInt(attributes.getValue("idx")),
+                        getInt(attributes.getValue("wdt")));
             } catch (NumberFormatException ne) {
-                throw new SAXException("Malformed width in metric file: "
-                                   + ne.getMessage(), ne);
+                throw new SAXException("Malformed width in metric file: " + ne.getMessage(), ne);
             }
         } else if ("pair".equals(localName)) {
-            currentKerning.put(new Integer(attributes.getValue("kpx2")),
-                               new Integer(attributes.getValue("kern")));
+            currentKerning.put(getInt(attributes.getValue("kpx2")),
+                    getInt(attributes.getValue("kern")));
         }
 
     }
@@ -319,5 +306,4 @@ public class FontReader extends DefaultH
     public void characters(char[] ch, int start, int length) {
         text.append(ch, start, length);
     }
-
 }

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontSetup.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontSetup.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontSetup.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontSetup.java Tue Jul  3 16:01:48 2012
@@ -22,9 +22,7 @@ package org.apache.fop.fonts;
 // FOP (base 14 fonts)
 import java.util.List;
 
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.base14.Courier;
 import org.apache.fop.fonts.base14.CourierBold;
 import org.apache.fop.fonts.base14.CourierBoldOblique;
@@ -71,11 +69,11 @@ public final class FontSetup {
      *
      * @param fontInfo the font info object to set up
      * @param embedFontInfoList a list of EmbedFontInfo objects
-     * @param resolver the font resolver
+     * @param resourceResolver the font resolver
      * @param base14Kerning true if base14 kerning applies
      */
-    public static void setup(FontInfo fontInfo, List<EmbedFontInfo> embedFontInfoList,
-                             FontResolver resolver, boolean base14Kerning) {
+    public static void setup(FontInfo fontInfo, List embedFontInfoList,
+            InternalResourceResolver resourceResolver, boolean base14Kerning) {
         fontInfo.addMetrics("F1", new Helvetica(base14Kerning));
         fontInfo.addMetrics("F2", new HelveticaOblique(base14Kerning));
         fontInfo.addMetrics("F3", new HelveticaBold(base14Kerning));
@@ -181,7 +179,7 @@ public final class FontSetup {
         final int startNum = 15;
 
         /* Add configured fonts */
-        addConfiguredFonts(fontInfo, embedFontInfoList, startNum, resolver, base14Kerning);
+        addConfiguredFonts(fontInfo, embedFontInfoList, startNum, resourceResolver, base14Kerning);
     }
 
     /**
@@ -189,21 +187,16 @@ public final class FontSetup {
      * @param fontInfo the font info to set up
      * @param embedFontInfoList a list of EmbedFontInfo objects
      * @param num starting index for internal font numbering
-     * @param resolver the font resolver
+     * @param resourceResolver the font resolver
      */
     private static void addConfiguredFonts(FontInfo fontInfo,
-            List<EmbedFontInfo> embedFontInfoList, int num, FontResolver resolver,
+            List<EmbedFontInfo> embedFontInfoList, int num,
+            InternalResourceResolver resourceResolver,
             boolean base14Kerning) {
         if (embedFontInfoList == null) {
             return; //No fonts to process
         }
-
-        if (resolver == null) {
-            //Ensure that we have minimal font resolution capabilities
-            //None of the built-in base14 fonts have advanced typographic data
-            boolean useAdvanced = false;
-            resolver = createMinimalFontResolver(useAdvanced);
-        }
+        assert resourceResolver != null;
 
         String internalName = null;
 
@@ -211,7 +204,7 @@ public final class FontSetup {
             internalName = "F" + num;
             num++;
 
-            LazyFont font = new LazyFont(embedFontInfo, resolver);
+            LazyFont font = new LazyFont(embedFontInfo, resourceResolver, false);
             fontInfo.addMetrics(internalName, font);
 
             List<FontTriplet> triplets = embedFontInfo.getFontTriplets();
@@ -221,32 +214,4 @@ public final class FontSetup {
             }
         }
     }
-
-    /**
-     * Minimum implemenation of FontResolver.
-     */
-    public static class MinimalFontResolver implements FontResolver {
-        private boolean useComplexScriptFeatures;
-        MinimalFontResolver(boolean useComplexScriptFeatures) {
-            this.useComplexScriptFeatures = useComplexScriptFeatures;
-        }
-        /** {@inheritDoc} */
-        public Source resolve(String href) {
-            //Minimal functionality here
-            return new StreamSource(href);
-        }
-        /** {@inheritDoc} */
-        public boolean isComplexScriptFeaturesEnabled() {
-            return useComplexScriptFeatures;
-        }
-    }
-
-    /**
-     * Create minimal font resolver.
-     * @param useComplexScriptFeatures true if complex script features enabled
-     * @return a new FontResolver to be used by the font subsystem
-     */
-    public static FontResolver createMinimalFontResolver(boolean useComplexScriptFeatures) {
-        return new MinimalFontResolver ( useComplexScriptFeatures );
-    }
 }

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontTriplet.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontTriplet.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontTriplet.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/FontTriplet.java Tue Jul  3 16:01:48 2012
@@ -27,6 +27,8 @@ import java.io.Serializable;
  */
 public class FontTriplet implements Comparable<FontTriplet>, Serializable {
 
+    public static final FontTriplet DEFAULT_FONT_TRIPLET = new FontTriplet("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
+
     /** serial version UID */
     private static final long serialVersionUID = 1168991106658033508L;
 
@@ -39,14 +41,6 @@ public class FontTriplet implements Comp
     private transient String key;
 
     /**
-     * Creates a new font triplet (for base14 use).
-     * @param name font name
-     */
-    public FontTriplet(String name) {
-        this.name = name;
-    }
-
-    /**
      * Creates a new font triplet.
      * @param name font name
      * @param style font style (normal, italic etc.)
@@ -64,7 +58,7 @@ public class FontTriplet implements Comp
      * @param priority priority of this triplet/font mapping
      */
     public FontTriplet(String name, String style, int weight, int priority) {
-        this(name);
+        this.name = name;
         this.style = style;
         this.weight = weight;
         this.priority = priority;
@@ -143,6 +137,5 @@ public class FontTriplet implements Comp
          */
         boolean matches(FontTriplet triplet);
     }
-
 }
 

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/LazyFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/LazyFont.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/LazyFont.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/LazyFont.java Tue Jul  3 16:01:48 2012
@@ -20,19 +20,17 @@
 package org.apache.fop.fonts;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
+import java.net.URI;
 import java.util.Map;
 import java.util.Set;
 
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
 import org.xml.sax.InputSource;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.complexscripts.fonts.Positionable;
 import org.apache.fop.complexscripts.fonts.Substitutable;
 
@@ -43,49 +41,50 @@ public class LazyFont extends Typeface i
 
     private static Log log = LogFactory.getLog(LazyFont.class);
 
-    private String metricsFileName;
-    private String fontEmbedPath;
-    private boolean useKerning;
-    private boolean useAdvanced;
-    private EncodingMode encodingMode = EncodingMode.AUTO;
-    private EmbeddingMode embeddingMode = EmbeddingMode.AUTO;
-    private boolean embedded = true;
-    private String subFontName;
+    private final URI metricsURI;
+    private final URI fontEmbedURI;
+    private final boolean useKerning;
+    private final boolean useAdvanced;
+    private final EncodingMode encodingMode;
+    private final EmbeddingMode embeddingMode;
+    private final String subFontName;
+    private final boolean embedded;
+    private final InternalResourceResolver resourceResolver;
 
     private boolean isMetricsLoaded;
     private Typeface realFont;
     private FontDescriptor realFontDescriptor;
 
-    private FontResolver resolver;
-
     /**
      * Main constructor
      * @param fontInfo  the font info to embed
-     * @param resolver the font resolver to handle font URIs
+     * @param resourceResolver the font resolver to handle font URIs
      */
-    public LazyFont(EmbedFontInfo fontInfo, FontResolver resolver) {
-
-        this.metricsFileName = fontInfo.getMetricsFile();
-        this.fontEmbedPath = fontInfo.getEmbedFile();
+    public LazyFont(EmbedFontInfo fontInfo, InternalResourceResolver resourceResolver,
+            boolean useComplexScripts) {
+        this.metricsURI = fontInfo.getMetricsURI();
+        this.fontEmbedURI = fontInfo.getEmbedURI();
         this.useKerning = fontInfo.getKerning();
-        if ( resolver != null ) {
-            this.useAdvanced = resolver.isComplexScriptFeaturesEnabled();
+        if (resourceResolver != null) {
+            this.useAdvanced = useComplexScripts;
         } else {
             this.useAdvanced = fontInfo.getAdvanced();
         }
-        this.encodingMode = fontInfo.getEncodingMode();
-        this.embeddingMode = fontInfo.getEmbeddingMode();
+        this.encodingMode = fontInfo.getEncodingMode() != null ? fontInfo.getEncodingMode()
+                : EncodingMode.AUTO;
+        this.embeddingMode = fontInfo.getEmbeddingMode() != null ? fontInfo.getEmbeddingMode()
+                : EmbeddingMode.AUTO;
         this.subFontName = fontInfo.getSubFontName();
         this.embedded = fontInfo.isEmbedded();
-        this.resolver = resolver;
+        this.resourceResolver = resourceResolver;
     }
 
     /** {@inheritDoc} */
     public String toString() {
         StringBuffer sbuf = new StringBuffer(super.toString());
         sbuf.append('{');
-        sbuf.append("metrics-url=" + metricsFileName);
-        sbuf.append(",embed-url=" + fontEmbedPath);
+        sbuf.append("metrics-url=" + metricsURI);
+        sbuf.append(",embed-url=" + fontEmbedURI);
         sbuf.append(",kerning=" + useKerning);
         sbuf.append(",advanced=" + useAdvanced);
         sbuf.append('}');
@@ -95,75 +94,38 @@ public class LazyFont extends Typeface i
     private void load(boolean fail) {
         if (!isMetricsLoaded) {
             try {
-                if (metricsFileName != null) {
+                if (metricsURI != null) {
                     /**@todo Possible thread problem here */
                     FontReader reader = null;
-                    if (resolver != null) {
-                        Source source = resolver.resolve(metricsFileName);
-                        if (source == null) {
-                            String err
-                                = "Cannot load font: failed to create Source from metrics file "
-                                    + metricsFileName;
-                            if (fail) {
-                                throw new RuntimeException(err);
-                            } else {
-                                log.error(err);
-                            }
-                            return;
-                        }
-                        InputStream in = null;
-                        if (source instanceof StreamSource) {
-                            in = ((StreamSource) source).getInputStream();
-                        }
-                        if (in == null && source.getSystemId() != null) {
-                            in = new java.net.URL(source.getSystemId()).openStream();
-                        }
-                        if (in == null) {
-                            String err = "Cannot load font: After URI resolution, the returned"
-                                + " Source object does not contain an InputStream"
-                                + " or a valid URL (system identifier) for metrics file: "
-                                + metricsFileName;
-                            if (fail) {
-                                throw new RuntimeException(err);
-                            } else {
-                                log.error(err);
-                            }
-                            return;
-                        }
-                        InputSource src = new InputSource(in);
-                        src.setSystemId(source.getSystemId());
-                        reader = new FontReader(src);
-                    } else {
-                        reader = new FontReader(new InputSource(
-                                    new URL(metricsFileName).openStream()));
-                    }
+                    InputStream in = resourceResolver.getResource(metricsURI);
+                    InputSource src = new InputSource(in);
+                    src.setSystemId(metricsURI.toASCIIString());
+                    reader = new FontReader(src, resourceResolver);
                     reader.setKerningEnabled(useKerning);
                     reader.setAdvancedEnabled(useAdvanced);
                     if (this.embedded) {
-                        reader.setFontEmbedPath(fontEmbedPath);
+                        reader.setFontEmbedURI(fontEmbedURI);
                     }
-                    reader.setResolver(resolver);
                     realFont = reader.getFont();
                 } else {
-                    if (fontEmbedPath == null) {
+                    if (fontEmbedURI == null) {
                         throw new RuntimeException("Cannot load font. No font URIs available.");
                     }
-                    realFont = FontLoader.loadFont(fontEmbedPath, subFontName,
-                            embedded, embeddingMode, encodingMode,
-                            useKerning, useAdvanced, resolver);
+                    realFont = FontLoader.loadFont(fontEmbedURI, subFontName, embedded,
+                            embeddingMode, encodingMode, useKerning, useAdvanced, resourceResolver);
                 }
                 if (realFont instanceof FontDescriptor) {
                     realFontDescriptor = (FontDescriptor) realFont;
                 }
             } catch (FOPException fopex) {
-                log.error("Failed to read font metrics file " + metricsFileName, fopex);
+                log.error("Failed to read font metrics file " + metricsURI, fopex);
                 if (fail) {
-                    throw new RuntimeException(fopex.getMessage());
+                    throw new RuntimeException(fopex);
                 }
             } catch (IOException ioex) {
-                log.error("Failed to read font metrics file " + metricsFileName, ioex);
+                log.error("Failed to read font metrics file " + metricsURI, ioex);
                 if (fail) {
-                    throw new RuntimeException(ioex.getMessage());
+                    throw new RuntimeException(ioex);
                 }
             }
             realFont.setEventListener(this.eventListener);

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/MultiByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/MultiByteFont.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/MultiByteFont.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/MultiByteFont.java Tue Jul  3 16:01:48 2012
@@ -26,6 +26,7 @@ import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.complexscripts.fonts.GlyphDefinitionTable;
 import org.apache.fop.complexscripts.fonts.GlyphPositioningTable;
 import org.apache.fop.complexscripts.fonts.GlyphSubstitutionTable;
@@ -68,7 +69,8 @@ public class MultiByteFont extends CIDFo
     /**
      * Default constructor
      */
-    public MultiByteFont() {
+    public MultiByteFont(InternalResourceResolver resourceResolver) {
+        super(resourceResolver);
         subset.setupFirstGlyph();
         setFontType(FontType.TYPE0);
     }
@@ -123,7 +125,7 @@ public class MultiByteFont extends CIDFo
 
     /** {@inheritDoc} */
     public boolean isEmbeddable() {
-        return !(getEmbedFileName() == null && getEmbedResourceName() == null);
+        return !(getEmbedFileURI() == null && getEmbedResourceName() == null);
     }
 
     public boolean isSubsetEmbedded() {
@@ -553,7 +555,7 @@ public class MultiByteFont extends CIDFo
             }
         }
         cb.flip();
-        return (CharSequence) cb;
+        return cb;
     }
 
 }

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/MutableFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/MutableFont.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/MutableFont.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/MutableFont.java Tue Jul  3 16:01:48 2012
@@ -19,6 +19,7 @@
 
 package org.apache.fop.fonts;
 
+import java.net.URI;
 import java.util.Map;
 import java.util.Set;
 
@@ -49,10 +50,10 @@ public interface MutableFont {
     void setFamilyNames(Set<String> names);
 
     /**
-     * Sets the path to the embeddable font file.
-     * @param path URI to the file
+     * Sets the URI to the embeddable font.
+     * @param path URI to the font
      */
-    void setEmbedFileName(String path);
+    void setEmbedURI(URI path);
 
     /**
      * Sets the resource name of the embeddable font file.

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/SingleByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/SingleByteFont.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/SingleByteFont.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/SingleByteFont.java Tue Jul  3 16:01:48 2012
@@ -31,6 +31,7 @@ import org.apache.commons.logging.LogFac
 
 import org.apache.xmlgraphics.fonts.Glyphs;
 
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.truetype.TTFFile.PostScriptVersion;
 
 /**
@@ -53,15 +54,16 @@ public class SingleByteFont extends Cust
     private PostScriptVersion ttPostScriptVersion;
 
     /**
-     * Main constructor.
+     * @param resourceResolver the URI resolver for controlling file access
      */
-    public SingleByteFont() {
+    public SingleByteFont(InternalResourceResolver resourceResolver) {
+        super(resourceResolver);
         setEncoding(CodePointMapping.WIN_ANSI_ENCODING);
     }
 
     /** {@inheritDoc} */
     public boolean isEmbeddable() {
-        return (!(getEmbedFileName() == null
+        return (!(getEmbedFileURI() == null
                 && getEmbedResourceName() == null));
     }
 

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/apps/TTFReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/apps/TTFReader.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/apps/TTFReader.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/apps/TTFReader.java Tue Jul  3 16:01:48 2012
@@ -19,7 +19,9 @@
 
 package org.apache.fop.fonts.apps;
 
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Map;
 import java.util.Set;
 
@@ -219,12 +221,17 @@ public class TTFReader extends AbstractF
     public TTFFile loadTTF(String fileName, String fontName, boolean useKerning, boolean useAdvanced) throws IOException {
         TTFFile ttfFile = new TTFFile(useKerning, useAdvanced);
         log.info("Reading " + fileName + "...");
-
-        FontFileReader reader = new FontFileReader(fileName);
-        boolean supported = ttfFile.readFont(reader, fontName);
-        if (!supported) {
-            return null;
+        InputStream stream = new FileInputStream(fileName);
+        try {
+            FontFileReader reader = new FontFileReader(stream);
+            boolean supported = ttfFile.readFont(reader, fontName);
+            if (!supported) {
+                return null;
+            }
+        } finally {
+            stream.close();
         }
+
         log.info("Font Family: " + ttfFile.getFamilyNames());
         if (ttfFile.isCFF()) {
             throw new UnsupportedOperationException(
@@ -465,7 +472,7 @@ public class TTFReader extends AbstractF
                 if (isCid || kpx2.intValue() < 256) {
                     el2 = doc.createElement("pair");
                     el2.setAttribute("kpx2", kpx2.toString());
-                    Integer val = (Integer)h2.get(kpx2);
+                    Integer val = h2.get(kpx2);
                     el2.setAttribute("kern", val.toString());
                     el.appendChild(el2);
                 }

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java Tue Jul  3 16:01:48 2012
@@ -20,7 +20,7 @@
 package org.apache.fop.fonts.autodetect;
 
 import java.io.InputStream;
-import java.net.URL;
+import java.net.URI;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
@@ -30,6 +30,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.CustomFont;
 import org.apache.fop.fonts.EmbedFontInfo;
 import org.apache.fop.fonts.EmbeddingMode;
@@ -38,7 +39,6 @@ import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontCache;
 import org.apache.fop.fonts.FontEventListener;
 import org.apache.fop.fonts.FontLoader;
-import org.apache.fop.fonts.FontResolver;
 import org.apache.fop.fonts.FontTriplet;
 import org.apache.fop.fonts.FontUtil;
 import org.apache.fop.fonts.MultiByteFont;
@@ -134,26 +134,25 @@ public class FontInfoFinder {
 
     /**
      * Attempts to determine FontInfo from a given custom font
-     * @param fontURL the font URL
+     * @param fontUri the font URI
      * @param customFont the custom font
      * @param fontCache font cache (may be null)
      * @return FontInfo from the given custom font
      */
-    private EmbedFontInfo getFontInfoFromCustomFont(
-            URL fontURL, CustomFont customFont, FontCache fontCache) {
+    private EmbedFontInfo getFontInfoFromCustomFont(URI fontUri, CustomFont customFont,
+            FontCache fontCache, InternalResourceResolver resourceResolver) {
         List<FontTriplet> fontTripletList = new java.util.ArrayList<FontTriplet>();
         generateTripletsFromFont(customFont, fontTripletList);
-        String embedUrl;
-        embedUrl = fontURL.toExternalForm();
         String subFontName = null;
         if (customFont instanceof MultiByteFont) {
-            subFontName = ((MultiByteFont)customFont).getTTCName();
+            subFontName = ((MultiByteFont) customFont).getTTCName();
         }
         EmbedFontInfo fontInfo = new EmbedFontInfo(null, customFont.isKerningEnabled(),
-                customFont.isAdvancedEnabled(), fontTripletList, embedUrl, subFontName);
+                customFont.isAdvancedEnabled(), fontTripletList, fontUri, subFontName,
+                EncodingMode.AUTO, EmbeddingMode.AUTO);
         fontInfo.setPostScriptName(customFont.getFontName());
         if (fontCache != null) {
-            fontCache.addFont(fontInfo);
+            fontCache.addFont(fontInfo, resourceResolver);
         }
         return fontInfo;
     }
@@ -161,32 +160,31 @@ public class FontInfoFinder {
     /**
      * Attempts to determine EmbedFontInfo from a given font file.
      *
-     * @param fontURL font URL. Assumed to be local.
-     * @param resolver font resolver used to resolve font
+     * @param fontURI the URI of the font resource
+     * @param resourceResolver font resolver used to resolve font
      * @param fontCache font cache (may be null)
      * @return an array of newly created embed font info. Generally, this array
      *         will have only one entry, unless the fontUrl is a TrueType Collection
      */
-    public EmbedFontInfo[] find(URL fontURL, FontResolver resolver, FontCache fontCache) {
-        String embedURL = null;
-        embedURL = fontURL.toExternalForm();
+    public EmbedFontInfo[] find(URI fontURI, InternalResourceResolver resourceResolver, FontCache fontCache) {
+        URI embedUri = resourceResolver.resolveFromBase(fontURI);
+        String embedStr = embedUri.toASCIIString();
         boolean useKerning = true;
-        boolean useAdvanced = ( resolver != null )
-            ? resolver.isComplexScriptFeaturesEnabled() : true;
+        boolean useAdvanced = true;
 
         long fileLastModified = -1;
         if (fontCache != null) {
-            fileLastModified = FontCache.getLastModified(fontURL);
+            fileLastModified = FontCache.getLastModified(fontURI);
             // firstly try and fetch it from cache before loading/parsing the font file
-            if (fontCache.containsFont(embedURL)) {
-                EmbedFontInfo[] fontInfos = fontCache.getFontInfos(embedURL, fileLastModified);
+            if (fontCache.containsFont(embedStr)) {
+                EmbedFontInfo[] fontInfos = fontCache.getFontInfos(embedStr, fileLastModified);
                 if (fontInfos != null) {
                     return fontInfos;
                 }
             // is this a previously failed parsed font?
-            } else if (fontCache.isFailedFont(embedURL, fileLastModified)) {
+            } else if (fontCache.isFailedFont(embedStr, fileLastModified)) {
                 if (log.isDebugEnabled()) {
-                    log.debug("Skipping font file that failed to load previously: " + embedURL);
+                    log.debug("Skipping font file that failed to load previously: " + embedUri);
                 }
                 return null;
             }
@@ -195,19 +193,19 @@ public class FontInfoFinder {
 
         // try to determine triplet information from font file
         CustomFont customFont = null;
-        if (fontURL.toExternalForm().toLowerCase().endsWith(".ttc")) {
+        if (fontURI.toASCIIString().toLowerCase().endsWith(".ttc")) {
             // Get a list of the TTC Font names
             List<String> ttcNames = null;
-            String fontFileURL = fontURL.toExternalForm().trim();
             InputStream in = null;
             try {
-                in = FontLoader.openFontUri(resolver, fontFileURL);
+                in = resourceResolver.getResource(fontURI);
                 TTFFile ttf = new TTFFile(false, false);
                 FontFileReader reader = new FontFileReader(in);
                 ttcNames = ttf.getTTCnames(reader);
             } catch (Exception e) {
                 if (this.eventListener != null) {
-                    this.eventListener.fontLoadingErrorAtAutoDetection(this, fontFileURL, e);
+                    this.eventListener.fontLoadingErrorAtAutoDetection(this,
+                            fontURI.toASCIIString(), e);
                 }
                 return null;
             } finally {
@@ -222,23 +220,25 @@ public class FontInfoFinder {
                     log.debug("Loading " + fontName);
                 }
                 try {
-                    TTFFontLoader ttfLoader = new TTFFontLoader(
-                            fontFileURL, fontName, true, EmbeddingMode.AUTO, EncodingMode.AUTO,
-                            useKerning, useAdvanced, resolver);
+                    TTFFontLoader ttfLoader = new TTFFontLoader(fontURI, fontName, true,
+                            EmbeddingMode.AUTO, EncodingMode.AUTO, useKerning, useAdvanced,
+                            resourceResolver);
                     customFont = ttfLoader.getFont();
                     if (this.eventListener != null) {
                         customFont.setEventListener(this.eventListener);
                     }
                 } catch (Exception e) {
                     if (fontCache != null) {
-                        fontCache.registerFailedFont(embedURL, fileLastModified);
+                        fontCache.registerFailedFont(embedUri.toASCIIString(), fileLastModified);
                     }
                     if (this.eventListener != null) {
-                        this.eventListener.fontLoadingErrorAtAutoDetection(this, embedURL, e);
+                        this.eventListener.fontLoadingErrorAtAutoDetection(this,
+                                embedUri.toASCIIString(), e);
                     }
                     continue;
                 }
-                EmbedFontInfo fi = getFontInfoFromCustomFont(fontURL, customFont, fontCache);
+                EmbedFontInfo fi = getFontInfoFromCustomFont(fontURI, customFont, fontCache,
+                        resourceResolver);
                 if (fi != null) {
                     embedFontInfoList.add(fi);
                 }
@@ -248,21 +248,22 @@ public class FontInfoFinder {
         } else {
             // The normal case
             try {
-                customFont = FontLoader.loadFont(fontURL, null, true, EmbeddingMode.AUTO,
-                        EncodingMode.AUTO, resolver);
+                customFont = FontLoader.loadFont(fontURI, null, true, EmbeddingMode.AUTO,
+                        EncodingMode.AUTO, useKerning, useAdvanced, resourceResolver);
                 if (this.eventListener != null) {
                     customFont.setEventListener(this.eventListener);
                 }
             } catch (Exception e) {
                 if (fontCache != null) {
-                    fontCache.registerFailedFont(embedURL, fileLastModified);
+                    fontCache.registerFailedFont(embedUri.toASCIIString(), fileLastModified);
                 }
                 if (this.eventListener != null) {
-                    this.eventListener.fontLoadingErrorAtAutoDetection(this, embedURL, e);
+                    this.eventListener.fontLoadingErrorAtAutoDetection(this,
+                            embedUri.toASCIIString(), e);
                 }
                 return null;
             }
-            EmbedFontInfo fi = getFontInfoFromCustomFont(fontURL, customFont, fontCache);
+            EmbedFontInfo fi = getFontInfoFromCustomFont(fontURI, customFont, fontCache, resourceResolver);
             if (fi != null) {
                 return new EmbedFontInfo[] {fi};
             } else {

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/FontFileReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/FontFileReader.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/FontFileReader.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/FontFileReader.java Tue Jul  3 16:01:48 2012
@@ -19,7 +19,6 @@
 
 package org.apache.fop.fonts.truetype;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -31,38 +30,9 @@ import org.apache.commons.io.IOUtils;
  */
 public class FontFileReader {
 
-    private int fsize;      // file size
+    private final int fsize; // file size
     private int current;    // current position in file
-    private byte[] file;
-
-    /**
-     * Initializes class and reads stream. Init does not close stream.
-     *
-     * @param in InputStream to read from new array with size + inc
-     * @throws IOException In case of an I/O problem
-     */
-    private void init(InputStream in) throws java.io.IOException {
-        this.file = IOUtils.toByteArray(in);
-        this.fsize = this.file.length;
-        this.current = 0;
-    }
-
-    /**
-     * Constructor
-     *
-     * @param fileName filename to read
-     * @throws IOException In case of an I/O problem
-     */
-    public FontFileReader(String fileName) throws IOException {
-        final File f = new File(fileName);
-        InputStream in = new java.io.FileInputStream(f);
-        try {
-            init(in);
-        } finally {
-            in.close();
-        }
-    }
-
+    private final byte[] file;
 
     /**
      * Constructor
@@ -71,7 +41,9 @@ public class FontFileReader {
      * @throws IOException In case of an I/O problem
      */
     public FontFileReader(InputStream in) throws IOException {
-        init(in);
+        this.file = IOUtils.toByteArray(in);
+        this.fsize = this.file.length;
+        this.current = 0;
     }
 
 
@@ -152,9 +124,9 @@ public class FontFileReader {
         final byte buf = read();
 
         if (buf < 0) {
-            return (int)(256 + buf);
+            return (256 + buf);
         } else {
-            return (int)buf;
+            return buf;
         }
     }
 
@@ -178,7 +150,7 @@ public class FontFileReader {
      */
     public final int readTTFUShort() throws IOException {
         final int ret = (readTTFUByte() << 8) + readTTFUByte();
-        return (int)ret;
+        return ret;
     }
 
     /**

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/TTFFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/TTFFile.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/TTFFile.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/TTFFile.java Tue Jul  3 16:01:48 2012
@@ -19,7 +19,9 @@
 
 package org.apache.fop.fonts.truetype;
 
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.Comparator;
@@ -33,6 +35,7 @@ import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -1672,7 +1675,7 @@ public class TTFFile {
 
                 for (Integer unicodeKey2 : ckpx.keySet()) {
                     Integer cidKey2 = unicodeToGlyph(unicodeKey2.intValue());
-                    Integer kern = (Integer)ckpx.get(unicodeKey2);
+                    Integer kern = ckpx.get(unicodeKey2);
 
                     Iterator uniMap = mtxTab[cidKey2.intValue()].getUnicodeIndex().listIterator();
                     while (uniMap.hasNext()) {
@@ -1838,6 +1841,8 @@ public class TTFFile {
      * @throws IOException In case of an I/O problem
      */
     public final List<String> getTTCnames(FontFileReader in) throws IOException {
+        this.fontFile = in;
+
         List<String> fontNames = new ArrayList<String>();
         String tag = in.readTTFString(4);
 
@@ -2011,12 +2016,14 @@ public class TTFFile {
      * @param args The command line arguments
      */
     public static void main(String[] args) {
+        InputStream stream = null;
         try {
             boolean useKerning = true;
             boolean useAdvanced = true;
             TTFFile ttfFile = new TTFFile(useKerning, useAdvanced);
 
-            FontFileReader reader = new FontFileReader(args[0]);
+            stream = new FileInputStream(args[0]);
+            FontFileReader reader = new FontFileReader(stream);
 
             String name = null;
             if (args.length >= 2) {
@@ -2029,6 +2036,8 @@ public class TTFFile {
         } catch (IOException ioe) {
             System.err.println("Problem reading font: " + ioe.toString());
             ioe.printStackTrace(System.err);
+        } finally {
+            IOUtils.closeQuietly(stream);
         }
     }
 }

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java Tue Jul  3 16:01:48 2012
@@ -21,17 +21,18 @@ package org.apache.fop.fonts.truetype;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
 import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.io.IOUtils;
 
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.CIDFontType;
 import org.apache.fop.fonts.CMapSegment;
 import org.apache.fop.fonts.EmbeddingMode;
 import org.apache.fop.fonts.EncodingMode;
 import org.apache.fop.fonts.FontLoader;
-import org.apache.fop.fonts.FontResolver;
 import org.apache.fop.fonts.FontType;
 import org.apache.fop.fonts.MultiByteFont;
 import org.apache.fop.fonts.NamedCharacter;
@@ -53,10 +54,10 @@ public class TTFFontLoader extends FontL
     /**
      * Default constructor
      * @param fontFileURI the URI representing the font file
-     * @param resolver the FontResolver for font URI resolution
+     * @param resourceResolver the resource resolver for font URI resolution
      */
-    public TTFFontLoader(String fontFileURI, FontResolver resolver) {
-        this(fontFileURI, null, true, EmbeddingMode.AUTO, EncodingMode.AUTO, true, true, resolver);
+    public TTFFontLoader(URI fontFileURI, InternalResourceResolver resourceResolver) {
+        this(fontFileURI, null, true, EmbeddingMode.AUTO, EncodingMode.AUTO, true, true, resourceResolver);
     }
 
     /**
@@ -71,9 +72,9 @@ public class TTFFontLoader extends FontL
      * @param useAdvanced true to enable loading advanced info if available, false to disable
      * @param resolver the FontResolver for font URI resolution
      */
-    public TTFFontLoader(String fontFileURI, String subFontName,
-                boolean embedded, EmbeddingMode embeddingMode, EncodingMode encodingMode,
-                boolean useKerning, boolean useAdvanced, FontResolver resolver) {
+    public TTFFontLoader(URI fontFileURI, String subFontName, boolean embedded,
+            EmbeddingMode embeddingMode, EncodingMode encodingMode, boolean useKerning,
+            boolean useAdvanced, InternalResourceResolver resolver) {
         super(fontFileURI, embedded, useKerning, useAdvanced, resolver);
         this.subFontName = subFontName;
         this.encodingMode = encodingMode;
@@ -98,7 +99,7 @@ public class TTFFontLoader extends FontL
      * @throws IOException if an I/O error occurs
      */
     private void read(String ttcFontName) throws IOException {
-        InputStream in = openFontUri(resolver, this.fontFileURI);
+        InputStream in = resourceResolver.getResource(this.fontFileURI);
         try {
             TTFFile ttf = new TTFFile(useKerning, useAdvanced);
             FontFileReader reader = new FontFileReader(in);
@@ -126,14 +127,13 @@ public class TTFFontLoader extends FontL
         }
 
         if (isCid) {
-            multiFont = new MultiByteFont();
+            multiFont = new MultiByteFont(resourceResolver);
             returnFont = multiFont;
             multiFont.setTTCName(ttcFontName);
         } else {
-            singleFont = new SingleByteFont();
+            singleFont = new SingleByteFont(resourceResolver);
             returnFont = singleFont;
         }
-        returnFont.setResolver(resolver);
 
         returnFont.setFontName(ttf.getPostScriptName());
         returnFont.setFullName(ttf.getFullName());
@@ -172,7 +172,7 @@ public class TTFFontLoader extends FontL
         }
         if (this.embedded) {
             if (ttf.isEmbeddable()) {
-                returnFont.setEmbedFileName(this.fontFileURI);
+                returnFont.setEmbedURI(this.fontFileURI);
             } else {
                 String msg = "The font " + this.fontFileURI + " is not embeddable due to a"
                         + " licensing restriction.";

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/PFBParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/PFBParser.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/PFBParser.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/PFBParser.java Tue Jul  3 16:01:48 2012
@@ -48,38 +48,6 @@ public class PFBParser {
 
     /**
      * Parses a PFB file into a PFBData object.
-     * @param url URL to load the PFB file from
-     * @return PFBData memory representation of the font
-     * @throws IOException In case of an I/O problem
-     */
-    public PFBData parsePFB(java.net.URL url) throws IOException {
-        InputStream in = url.openStream();
-        try {
-            return parsePFB(in);
-        } finally {
-            in.close();
-        }
-    }
-
-
-    /**
-     * Parses a PFB file into a PFBData object.
-     * @param pfbFile File to load the PFB file from
-     * @return PFBData memory representation of the font
-     * @throws IOException In case of an I/O problem
-     */
-    public PFBData parsePFB(java.io.File pfbFile) throws IOException {
-        InputStream in = new java.io.FileInputStream(pfbFile);
-        try {
-            return parsePFB(in);
-        } finally {
-            in.close();
-        }
-    }
-
-
-    /**
-     * Parses a PFB file into a PFBData object.
      * @param in InputStream to load the PFB file from
      * @return PFBData memory representation of the font
      * @throws IOException In case of an I/O problem
@@ -113,7 +81,6 @@ public class PFBParser {
     private void parsePCFormat(PFBData pfb, DataInputStream din) throws IOException {
         int segmentHead;
         int segmentType;
-        int bytesRead;
 
         //Read first segment
         segmentHead = din.readUnsignedByte();

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/PFMFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/PFMFile.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/PFMFile.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/PFMFile.java Tue Jul  3 16:01:48 2012
@@ -23,6 +23,7 @@ package org.apache.fop.fonts.type1;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.io.IOUtils;
@@ -40,7 +41,7 @@ public class PFMFile {
     private String windowsName;
     private String postscriptName;
     private short dfItalic;
-    private int dfWeight;
+    //private int dfWeight;
     private short dfCharSet;
     private short dfPitchAndFamily;
     private int dfAvgWidth;
@@ -61,7 +62,7 @@ public class PFMFile {
     // Extent table
     private int[] extentTable;
 
-    private Map kerningTab = new java.util.HashMap();
+    private Map<Integer, Map<Integer, Integer>> kerningTab = new HashMap<Integer, Map<Integer, Integer>>();
 
     /**
      * logging instance
@@ -119,7 +120,7 @@ public class PFMFile {
         inStream.skip(80);
         dfItalic = inStream.readByte();
         inStream.skip(2);
-        dfWeight = inStream.readShort();
+        inStream.readShort(); // dfWeight =
         dfCharSet = inStream.readByte();
         inStream.skip(4);
         dfPitchAndFamily = inStream.readByte();
@@ -192,10 +193,10 @@ public class PFMFile {
             log.trace(i + " kerning pairs");
         }
         while (i > 0) {
-            int g1 = (int)inStream.readByte();
+            int g1 = (int) inStream.readByte();
             i--;
 
-            int g2 = (int)inStream.readByte();
+            int g2 = (int) inStream.readByte();
 
             int adj = inStream.readShort();
             if (adj > 0x8000) {
@@ -209,12 +210,12 @@ public class PFMFile {
                 log.trace("glyphs: " + glyph1 + ", " + glyph2);
             }
 
-            Map adjTab = (Map)kerningTab.get(new Integer(g1));
+            Map<Integer, Integer> adjTab = kerningTab.get(Integer.valueOf(g1));
             if (adjTab == null) {
-                adjTab = new java.util.HashMap();
+                adjTab = new HashMap<Integer, Integer>();
             }
-            adjTab.put(new Integer(g2), new Integer(adj));
-            kerningTab.put(new Integer(g1), adjTab);
+            adjTab.put(Integer.valueOf(g2), Integer.valueOf(adj));
+            kerningTab.put(Integer.valueOf(g1), adjTab);
         }
     }
 
@@ -270,7 +271,7 @@ public class PFMFile {
      *
      * @return A Map containing the kerning table
      */
-    public Map getKerning() {
+    public Map<Integer, Map<Integer, Integer>> getKerning() {
         return kerningTab;
     }
 
@@ -453,9 +454,9 @@ public class PFMFile {
     public int getStemV() {
         // Just guessing....
         if (dfItalic != 0) {
-            return (int)Math.round(dfMinWidth * 0.25);
+            return (int) Math.round(dfMinWidth * 0.25);
         } else {
-            return (int)Math.round(dfMinWidth * 0.6);
+            return (int) Math.round(dfMinWidth * 0.6);
         }
     }
 

Modified: xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java?rev=1356804&r1=1356803&r2=1356804&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java (original)
+++ xmlgraphics/fop/branches/Temp_RoundedCorners/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java Tue Jul  3 16:01:48 2012
@@ -22,15 +22,19 @@ package org.apache.fop.fonts.type1;
 import java.awt.geom.RectangularShape;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.CodePointMapping;
 import org.apache.fop.fonts.FontLoader;
-import org.apache.fop.fonts.FontResolver;
 import org.apache.fop.fonts.FontType;
 import org.apache.fop.fonts.SingleByteEncoding;
 import org.apache.fop.fonts.SingleByteFont;
@@ -40,6 +44,8 @@ import org.apache.fop.fonts.SingleByteFo
  */
 public class Type1FontLoader extends FontLoader {
 
+    private static final Log log = LogFactory.getLog(Type1FontLoader.class);
+
     private SingleByteFont singleFont;
 
     /**
@@ -47,12 +53,12 @@ public class Type1FontLoader extends Fon
      * @param fontFileURI the URI to the PFB file of a Type 1 font
      * @param embedded indicates whether the font is embedded or referenced
      * @param useKerning indicates whether to load kerning information if available
-     * @param resolver the font resolver used to resolve URIs
+     * @param resourceResolver the font resolver used to resolve URIs
      * @throws IOException In case of an I/O error
      */
-    public Type1FontLoader(String fontFileURI, boolean embedded, boolean useKerning,
-            FontResolver resolver) throws IOException {
-        super(fontFileURI, embedded, useKerning, true, resolver);
+    public Type1FontLoader(URI fontFileURI, boolean embedded, boolean useKerning,
+            InternalResourceResolver resourceResolver) throws IOException {
+        super(fontFileURI, embedded, useKerning, true, resourceResolver);
     }
 
     private String getPFMURI(String pfbURI) {
@@ -71,17 +77,20 @@ public class Type1FontLoader extends Fon
         PFMFile pfm = null;
 
         InputStream afmIn = null;
+        String fontFileStr = fontFileURI.toASCIIString();
+        String partialAfmUri = fontFileStr.substring(0, fontFileStr.length() - 4);
         String afmUri = null;
-        for (int i = 0; i < AFM_EXTENSIONS.length; i++) {
+        for (String afmExtension : AFM_EXTENSIONS) {
             try {
-                afmUri = this.fontFileURI.substring(0, this.fontFileURI.length() - 4)
-                        + AFM_EXTENSIONS[i];
-                afmIn = openFontUri(resolver, afmUri);
+                afmUri = partialAfmUri + afmExtension;
+                afmIn = resourceResolver.getResource(afmUri);
                 if (afmIn != null) {
                     break;
                 }
             } catch (IOException ioe) {
                 // Ignore, AFM probably not available under the URI
+            } catch (URISyntaxException e) {
+                // Ignore, AFM probably not available under the URI
             }
         }
         if (afmIn != null) {
@@ -93,12 +102,14 @@ public class Type1FontLoader extends Fon
             }
         }
 
-        String pfmUri = getPFMURI(this.fontFileURI);
+        String pfmUri = getPFMURI(fontFileStr);
         InputStream pfmIn = null;
         try {
-            pfmIn = openFontUri(resolver, pfmUri);
+            pfmIn = resourceResolver.getResource(pfmUri);
         } catch (IOException ioe) {
             // Ignore, PFM probably not available under the URI
+        } catch (URISyntaxException e) {
+            // Ignore, PFM probably not available under the URI
         }
         if (pfmIn != null) {
             try {
@@ -126,11 +137,10 @@ public class Type1FontLoader extends Fon
         if (afm == null && pfm == null) {
             throw new IllegalArgumentException("Need at least an AFM or a PFM!");
         }
-        singleFont = new SingleByteFont();
+        singleFont = new SingleByteFont(resourceResolver);
         singleFont.setFontType(FontType.TYPE1);
-        singleFont.setResolver(this.resolver);
         if (this.embedded) {
-            singleFont.setEmbedFileName(this.fontFileURI);
+            singleFont.setEmbedURI(this.fontFileURI);
         }
         returnFont = singleFont;
 



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org