xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gad...@apache.org
Subject svn commit: r1400689 [4/13] - in /xmlgraphics/fop/branches/fop-1_1: ./ examples/embedding/java/embedding/ examples/embedding/java/embedding/atxml/ examples/embedding/java/embedding/events/ examples/embedding/java/embedding/intermediate/ src/documentati...
Date Sun, 21 Oct 2012 18:06:04 GMT
Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/EmbedFontInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/EmbedFontInfo.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/EmbedFontInfo.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/EmbedFontInfo.java Sun Oct 21 18:05:50 2012
@@ -21,6 +21,7 @@ package org.apache.fop.fonts;
 
 import java.io.IOException;
 import java.io.Serializable;
+import java.net.URI;
 import java.util.List;
 
 /**
@@ -33,62 +34,66 @@ public class EmbedFontInfo implements Se
     /** Serialization Version UID */
     private static final long serialVersionUID = 8755432068669997369L;
 
-    /** filename of the metrics file */
-    protected String metricsFile;
-    /** filename of the main font file */
-    protected String embedFile;
+    protected final URI metricsURI;
+    protected final URI embedURI;
     /** false, to disable kerning */
-    protected boolean kerning;
+    protected final boolean kerning;
     /** false, to disable advanced typographic features */
-    protected boolean advanced;
+    protected final boolean advanced;
     /** the requested encoding mode for the font */
-    protected EncodingMode encodingMode = EncodingMode.AUTO;
+    private final EncodingMode encodingMode;
     /** the requested embedding mode for this font */
-    protected EmbeddingMode embeddingMode = EmbeddingMode.AUTO;
+    private final EmbeddingMode embeddingMode;
 
     /** the PostScript name of the font */
-    protected String postScriptName = null;
+    protected String postScriptName;
     /** the sub-fontname of the font (used for TrueType Collections, null otherwise) */
-    protected String subFontName = null;
+    protected String subFontName;
 
     /** the list of associated font triplets */
-    private List<FontTriplet> fontTriplets = null;
+    private List<FontTriplet> fontTriplets;
 
     private transient boolean embedded = true;
 
     /**
      * Main constructor
-     * @param metricsFile path to the xml file containing font metrics
-     * @param kerning true if kerning should be enabled
+     * @param metricsURI the URI of the XML resource containing font metrics
+     * @param kerning True if kerning should be enabled
      * @param advanced true if advanced typography features should be enabled
-     * @param fontTriplets list of font triplets to associate with this font
-     * @param embedFile path to the embeddable font file (may be null)
+     * @param fontTriplets List of font triplets to associate with this font
+     * @param embedURI Path to the embeddable font file (may be null)
      * @param subFontName the sub-fontname used for TrueType Collections (null otherwise)
+     * @param encodingMode the encoding mode to use for this font
      */
-    public EmbedFontInfo(String metricsFile, boolean kerning, boolean advanced,
-                    List<FontTriplet> fontTriplets, String embedFile, String subFontName) {
-        this.metricsFile = metricsFile;
-        this.embedFile = embedFile;
+    public EmbedFontInfo(URI metricsURI, boolean kerning, boolean advanced,
+            List<FontTriplet> fontTriplets, URI embedURI, String subFontName,
+            EncodingMode encodingMode, EmbeddingMode embeddingMode) {
+        this.metricsURI = metricsURI;
+        this.embedURI = embedURI;
         this.kerning = kerning;
         this.advanced = advanced;
         this.fontTriplets = fontTriplets;
         this.subFontName = subFontName;
+        this.encodingMode = encodingMode;
+        this.embeddingMode = embeddingMode;
     }
 
     /**
-     * Returns the path to the metrics file
+     * Returns the URI of the metrics XML resource
+     *
      * @return the metrics file path
      */
-    public String getMetricsFile() {
-        return metricsFile;
+    public URI getMetricsURI() {
+        return metricsURI;
     }
 
     /**
-     * Returns the path to the embeddable font file
-     * @return the font file path
+     * Returns the URI to the embeddable font resource
+     *
+     * @return the font resource URI
      */
-    public String getEmbedFile() {
-        return embedFile;
+    public URI getEmbedURI() {
+        return embedURI;
     }
 
     /**
@@ -145,7 +150,7 @@ public class EmbedFontInfo implements Se
      * @return true if the font is embedded, false if it is referenced.
      */
     public boolean isEmbedded() {
-        if (metricsFile != null && embedFile == null) {
+        if (embedURI == null) {
             return false;
         } else {
             return this.embedded;
@@ -176,28 +181,6 @@ public class EmbedFontInfo implements Se
         return this.encodingMode;
     }
 
-    /**
-     * Sets the requested encoding mode for this font.
-     * @param mode the new encoding mode
-     */
-    public void setEncodingMode(EncodingMode mode) {
-        if (mode == null) {
-            throw new NullPointerException("mode must not be null");
-        }
-        this.encodingMode = mode;
-    }
-
-    /**
-     * Sets the embedding mode for this font, currently not supported for Type 1 fonts.
-     * @param embeddingMode the new embedding mode.
-     */
-    public void setEmbeddingMode(EmbeddingMode embeddingMode) {
-        if (embeddingMode == null) {
-            throw new NullPointerException("embeddingMode must not be null");
-        }
-        this.embeddingMode = embeddingMode;
-    }
-
     private void readObject(java.io.ObjectInputStream in)
                 throws IOException, ClassNotFoundException {
         in.defaultReadObject();
@@ -206,7 +189,7 @@ public class EmbedFontInfo implements Se
 
     /** {@inheritDoc} */
     public String toString() {
-        return "metrics-url=" + metricsFile + ", embed-url=" + embedFile
+        return "metrics-uri=" + metricsURI + ", embed-uri=" + embedURI
             + ", kerning=" + kerning
             + ", advanced=" + advanced
             + ", enc-mode=" + encodingMode

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontAdder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontAdder.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontAdder.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontAdder.java Sun Oct 21 18:05:50 2012
@@ -19,9 +19,11 @@
 
 package org.apache.fop.fonts;
 
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.List;
 
+import org.apache.fop.apps.io.InternalResourceResolver;
 import org.apache.fop.fonts.autodetect.FontInfoFinder;
 
 /**
@@ -29,18 +31,19 @@ import org.apache.fop.fonts.autodetect.F
  */
 public class FontAdder {
     private final FontEventListener listener;
-    private final FontResolver resolver;
+    private final InternalResourceResolver resourceResolver;
     private final FontManager manager;
 
     /**
      * Main constructor
      * @param manager a font manager
-     * @param resolver a font resolver
+     * @param resourceResolver a font resolver
      * @param listener a font event handler
      */
-    public FontAdder(FontManager manager, FontResolver resolver, FontEventListener listener) {
+    public FontAdder(FontManager manager, InternalResourceResolver resourceResolver,
+            FontEventListener listener) {
         this.manager = manager;
-        this.resolver = resolver;
+        this.resourceResolver = resourceResolver;
         this.listener = listener;
     }
 
@@ -48,14 +51,16 @@ public class FontAdder {
      * Iterates over font url list adding to font info list
      * @param fontURLList font file list
      * @param fontInfoList a configured font info list
+     * @throws URISyntaxException if a URI syntax error is found
      */
-    public void add(List<URL> fontURLList, List<EmbedFontInfo> fontInfoList) {
+    public void add(List<URL> fontURLList, List<EmbedFontInfo> fontInfoList)
+            throws URISyntaxException {
         FontCache cache = manager.getFontCache();
         FontInfoFinder finder = new FontInfoFinder();
         finder.setEventListener(listener);
 
         for (URL fontURL : fontURLList) {
-            EmbedFontInfo[] embedFontInfos = finder.find(fontURL, resolver, cache);
+            EmbedFontInfo[] embedFontInfos = finder.find(fontURL.toURI(), resourceResolver, cache);
             if (embedFontInfos == null) {
                 continue;
             }

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontCache.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontCache.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontCache.java Sun Oct 21 18:05:50 2012
@@ -29,6 +29,7 @@ import java.io.ObjectOutputStream;
 import java.io.OutputStream;
 import java.io.Serializable;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.HashMap;
@@ -40,6 +41,7 @@ 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.util.LogUtil;
 
 /**
@@ -234,9 +236,9 @@ public final class FontCache implements 
      */
     protected static String getCacheKey(EmbedFontInfo fontInfo) {
         if (fontInfo != null) {
-            String embedFile = fontInfo.getEmbedFile();
-            String metricsFile = fontInfo.getMetricsFile();
-            return (embedFile != null) ? embedFile : metricsFile;
+            URI embedFile = fontInfo.getEmbedURI();
+            URI metricsFile = fontInfo.getMetricsURI();
+            return (embedFile != null) ? embedFile.toASCIIString() : metricsFile.toASCIIString();
         }
         return null;
     }
@@ -318,7 +320,7 @@ public final class FontCache implements 
      * @param fontInfo
      *            font info
      */
-    public void addFont(EmbedFontInfo fontInfo) {
+    public void addFont(EmbedFontInfo fontInfo, InternalResourceResolver resourceResolver) {
         String cacheKey = getCacheKey(fontInfo);
         synchronized (changeLock) {
             CachedFontFile cachedFontFile;
@@ -329,10 +331,9 @@ public final class FontCache implements 
                 }
             } else {
                 // try and determine modified date
-                File fontFile = getFileFromUrls(new String[] {
-                        fontInfo.getEmbedFile(), fontInfo.getMetricsFile() });
-                long lastModified = (fontFile != null ? fontFile.lastModified()
-                        : -1);
+                URI fontUri = resourceResolver.resolveFromBase(fontInfo.getEmbedURI());
+                File fontFile = new File(fontUri);
+                long lastModified = fontFile.lastModified();
                 cachedFontFile = new CachedFontFile(lastModified);
                 if (log.isTraceEnabled()) {
                     log.trace("Font added to cache: " + cacheKey);
@@ -467,8 +468,9 @@ public final class FontCache implements 
      *            the URL
      * @return the last modified date/time
      */
-    public static long getLastModified(URL url) {
+    public static long getLastModified(URI uri) {
         try {
+            URL url = uri.toURL();
             URLConnection conn = url.openConnection();
             try {
                 return conn.getLastModified();

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontDetector.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontDetector.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontDetector.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontDetector.java Sun Oct 21 18:05:50 2012
@@ -17,90 +17,18 @@
 
 /* $Id$ */
 
+
 package org.apache.fop.fonts;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
 import java.util.List;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.xmlgraphics.util.ClasspathResource;
-
 import org.apache.fop.apps.FOPException;
-import org.apache.fop.fonts.autodetect.FontFileFinder;
-import org.apache.fop.util.LogUtil;
 
 /**
- * Detector of operating system and classpath fonts
+ * An interface for the font detecting mechanism.
  */
-public class FontDetector {
-    private static Log log = LogFactory.getLog(FontDetector.class);
 
-    private static final String[] FONT_MIMETYPES = {
-        "application/x-font", "application/x-font-truetype"
-    };
-
-    private final FontManager fontManager;
-    private final FontAdder fontAdder;
-    private final boolean strict;
-    private final FontEventListener eventListener;
-
-    /**
-     * Main constructor
-     * @param manager the font manager
-     * @param adder the font adder
-     * @param strict true if an Exception should be thrown if an error is found.
-     * @param listener for throwing font related events
-     */
-    public FontDetector(FontManager manager, FontAdder adder, boolean strict,
-            FontEventListener listener) {
-        this.fontManager = manager;
-        this.fontAdder = adder;
-        this.strict = strict;
-        this.eventListener = listener;
-    }
-
-    /**
-     * Detect installed fonts on the system
-     * @param fontInfoList a list of fontinfo to populate
-     * @throws FOPException thrown if a problem occurred during detection
-     */
-    public void detect(List<EmbedFontInfo> fontInfoList) throws FOPException {
-        // search in font base if it is defined and
-        // is a directory but don't recurse
-        FontFileFinder fontFileFinder = new FontFileFinder(eventListener);
-        String fontBaseURL = fontManager.getFontBaseURL();
-        if (fontBaseURL != null) {
-            try {
-                File fontBase = FileUtils.toFile(new URL(fontBaseURL));
-                if (fontBase != null) {
-                    List<URL> fontURLList = fontFileFinder.find(fontBase.getAbsolutePath());
-                    fontAdder.add(fontURLList, fontInfoList);
-
-                    //Can only use the font base URL if it's a file URL
-                }
-            } catch (IOException e) {
-                LogUtil.handleException(log, e, strict);
-            }
-        }
-
-        // native o/s font directory finding
-        List<URL> systemFontList;
-        try {
-            systemFontList = fontFileFinder.find();
-            fontAdder.add(systemFontList, fontInfoList);
-        } catch (IOException e) {
-            LogUtil.handleException(log, e, strict);
-        }
-
-        // classpath font finding
-        ClasspathResource resource = ClasspathResource.getInstance();
-        for (int i = 0; i < FONT_MIMETYPES.length; i++) {
-            fontAdder.add(resource.listResourcesOfMimeType(FONT_MIMETYPES[i]), fontInfoList);
-        }
-    }
+public interface FontDetector {
+    void detect(FontManager fontManager, FontAdder fontAdder, boolean strict,
+            FontEventListener eventListener, List<EmbedFontInfo> fontInfoList) throws FOPException;
 }

Modified: xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontLoader.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontLoader.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontLoader.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/FontManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontManager.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontManager.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontManager.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontManagerConfigurator.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontManagerConfigurator.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontManagerConfigurator.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/FontReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontReader.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontReader.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontReader.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/FontSetup.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontSetup.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontSetup.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontSetup.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/FontTriplet.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontTriplet.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontTriplet.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/FontTriplet.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/LazyFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/LazyFont.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/LazyFont.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/LazyFont.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/MultiByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/MultiByteFont.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/MultiByteFont.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/MultiByteFont.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/MutableFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/MutableFont.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/MutableFont.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/MutableFont.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/SingleByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/SingleByteFont.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/SingleByteFont.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/SingleByteFont.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/apps/TTFReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/apps/TTFReader.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/apps/TTFReader.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/apps/TTFReader.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/truetype/FontFileReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/FontFileReader.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/FontFileReader.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/FontFileReader.java Sun Oct 21 18:05:50 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/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFFile.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFFile.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFFile.java Sun Oct 21 18:05:50 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;
 
@@ -2013,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) {
@@ -2031,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/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java?rev=1400689&r1=1400688&r2=1400689&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java (original)
+++ xmlgraphics/fop/branches/fop-1_1/src/java/org/apache/fop/fonts/truetype/TTFFontLoader.java Sun Oct 21 18:05:50 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.";



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


Mime
View raw message