xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From me...@apache.org
Subject svn commit: r1344594 [4/15] - in /xmlgraphics/fop/branches/Temp_URI_Unification: ./ examples/embedding/java/embedding/ examples/embedding/java/embedding/atxml/ examples/embedding/java/embedding/events/ examples/embedding/java/embedding/intermediate/ sr...
Date Thu, 31 May 2012 08:33:50 GMT
Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/DefaultFontConfig.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/DefaultFontConfig.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/DefaultFontConfig.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/DefaultFontConfig.java Thu May 31 08:33:36 2012
@@ -0,0 +1,335 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.events.EventProducer;
+import org.apache.fop.util.LogUtil;
+
+/**
+ * The font configuration data for the more generic fonts such as TTF and Type1, that are used by
+ * most the renderers.
+ */
+public final class DefaultFontConfig implements FontConfig {
+
+    protected static Log log = LogFactory.getLog(DefaultFontConfig.class);
+
+    private final List<Directory> directories = new ArrayList<Directory>();
+
+    private final List<Font> fonts = new ArrayList<Font>();
+
+    private final List<String> referencedFontFamilies = new ArrayList<String>();
+
+    private final boolean autoDetectFonts;
+
+    private DefaultFontConfig(boolean autoDetectFonts) {
+        this.autoDetectFonts = autoDetectFonts;
+    }
+
+    /**
+     * Parses the morge generic font information.
+     */
+    public static final class DefaultFontConfigParser implements FontConfig.FontConfigParser {
+        /**
+         * Parses the font configuration and return the configuration object.
+         *
+         * @param cfg the configuration data
+         * @param strict whether or not to enforce strict validation
+         * @return the font configuration object
+         * @throws FOPException if an error occurs when creating the configuration object
+         */
+        public DefaultFontConfig parse(Configuration cfg, boolean strict) throws FOPException {
+            return new ParserHelper(cfg, strict).instance;
+        }
+
+        /** {@inheritDoc} */
+        public FontConfig parse(Configuration cfg, FontManager fontManager, boolean strict,
+                EventProducer eventProducer) throws FOPException {
+            return parse(cfg, strict);
+        }
+    }
+
+    private  static final class ParserHelper {
+
+        private  boolean strict;
+
+        private  Configuration fontInfoCfg;
+
+        private  DefaultFontConfig instance;
+
+        private ParserHelper(Configuration cfg, boolean strict) throws FOPException {
+            if (cfg == null || cfg.getChild("fonts", false) == null) {
+                instance = null;
+            } else {
+                this.strict = strict;
+                this.fontInfoCfg = cfg.getChild("fonts", false);
+                instance = new DefaultFontConfig(cfg.getChild("auto-detect", false) != null);
+                parse();
+            }
+        }
+
+        private void parse() throws FOPException {
+            parseFonts();
+            parseReferencedFonts();
+            parseDirectories();
+        }
+
+        private void parseFonts() throws FOPException {
+            for (Configuration fontCfg : fontInfoCfg.getChildren("font")) {
+                String embed = fontCfg.getAttribute("embed-url", null);
+                if (embed == null) {
+                    LogUtil.handleError(log, "Font configuration without embed-url attribute",
+                            strict);
+                    continue;
+                }
+                Font font = new Font(fontCfg.getAttribute("metrics-url", null), embed,
+                        fontCfg.getAttribute("sub-font", null), fontCfg.getAttributeAsBoolean(
+                                "kerning", true), fontCfg.getAttributeAsBoolean("advanced", true),
+                                fontCfg.getAttribute("encoding-mode", EncodingMode.AUTO.getName()));
+                instance.fonts.add(font);
+                boolean hasTriplets = false;
+                for (Configuration tripletCfg : fontCfg.getChildren("font-triplet")) {
+                    FontTriplet fontTriplet = getFontTriplet(tripletCfg, strict);
+                    font.tripletList.add(fontTriplet);
+                    hasTriplets = true;
+                }
+                // no font triplet info
+                if (!hasTriplets) {
+                    LogUtil.handleError(log, "font without font-triplet", strict);
+                }
+            }
+        }
+
+        private void parseReferencedFonts() throws FOPException {
+            Configuration referencedFontsCfg = fontInfoCfg.getChild("referenced-fonts", false);
+            if (referencedFontsCfg != null) {
+                for (Configuration match : referencedFontsCfg.getChildren("match")) {
+                    try {
+                        instance.referencedFontFamilies.add(match.getAttribute("font-family"));
+                    } catch (ConfigurationException ce) {
+                        LogUtil.handleException(log, ce, strict);
+                        continue;
+                    }
+                }
+            }
+        }
+
+        private void parseDirectories() throws FOPException {
+            for (Configuration directoriesCfg : fontInfoCfg.getChildren("directory")) {
+                boolean recursive = directoriesCfg.getAttributeAsBoolean("recursive", false);
+                String directory;
+                try {
+                    directory = directoriesCfg.getValue();
+                } catch (ConfigurationException e) {
+                    LogUtil.handleException(log, e, strict);
+                    continue;
+                }
+                if (directory == null) {
+                    LogUtil.handleException(log,
+                            new FOPException("directory defined without value"), strict);
+                    continue;
+                }
+                instance.directories.add(new Directory(directory, recursive));
+            }
+        }
+
+        /**
+         * Creates a new FontTriplet given a triple Configuration
+         *
+         * @param tripletCfg a triplet configuration
+         * @return a font triplet font key
+         * @throws FOPException thrown if a FOP exception occurs
+         */
+        private FontTriplet getFontTriplet(Configuration tripletCfg, boolean strict)
+                throws FOPException {
+            try {
+                String name = tripletCfg.getAttribute("name");
+                if (name == null) {
+                    LogUtil.handleError(log, "font-triplet without name", strict);
+                    return null;
+                }
+                String weightStr = tripletCfg.getAttribute("weight");
+                if (weightStr == null) {
+                    LogUtil.handleError(log, "font-triplet without weight", strict);
+                    return null;
+                }
+                int weight = FontUtil.parseCSS2FontWeight(FontUtil.stripWhiteSpace(weightStr));
+                String style = tripletCfg.getAttribute("style");
+                if (style == null) {
+                    LogUtil.handleError(log, "font-triplet without style", strict);
+                    return null;
+                } else {
+                    style = FontUtil.stripWhiteSpace(style);
+                }
+                return FontInfo.createFontKey(name, style, weight);
+            } catch (ConfigurationException e) {
+                LogUtil.handleException(log, e, strict);
+            }
+            return null;
+        }
+
+    }
+
+    /**
+     * Returns the list of fonts that were parsed.
+     * @return a list of fonts
+     */
+    public List<Font> getFonts() {
+        return Collections.unmodifiableList(fonts);
+    }
+
+    /**
+     * Returns a list of directories that were parsed.
+     * @return a list of directories
+     */
+    public List<Directory> getDirectories() {
+        return Collections.unmodifiableList(directories);
+    }
+
+    /**
+     * Returns a list of referenced font families.
+     * @return the referenced font families
+     */
+    public List<String> getReferencedFontFamily() {
+        return Collections.unmodifiableList(referencedFontFamilies);
+    }
+
+    /**
+     * Whether or not to enable auto-detecting of fonts in the system.
+     * @return true to enable auto-detect
+     */
+    public boolean isAutoDetectFonts() {
+        return autoDetectFonts;
+    }
+
+    /**
+     * The directory to find fonts within.
+     */
+    public static final class Directory {
+
+        private final String directory;
+
+        private final boolean recursive;
+
+        private Directory(String directory, boolean recurse) {
+            this.directory = directory;
+            this.recursive = recurse;
+        }
+
+        /**
+         * Returns a String representing the directory to find fonts within.
+         * @return the directory
+         */
+        public String getDirectory() {
+            return directory;
+        }
+
+        /**
+         * Returns whether or not to recurse through the directory when finding fonts.
+         * @return true to recurse through the directory and sub-directories
+         */
+        public boolean isRecursive() {
+            return recursive;
+        }
+    }
+
+    /**
+     * Represents a font object within the FOP conf.
+     */
+    public static final class Font {
+
+        private final String metrics;
+
+        private final String embedUri;
+
+        private final String subFont;
+
+        private final boolean kerning;
+
+        private final boolean advanced;
+
+        private final String encodingMode;
+
+        public String getEncodingMode() {
+            return encodingMode;
+        }
+
+        private final List<FontTriplet> tripletList = new ArrayList<FontTriplet>();
+
+        public List<FontTriplet> getTripletList() {
+            return Collections.unmodifiableList(tripletList);
+        }
+
+        private Font(String metrics, String embed, String subFont, boolean kerning,
+                boolean advanced, String encodingMode) {
+            this.metrics = metrics;
+            this.embedUri = embed;
+            this.subFont = subFont;
+            this.kerning = kerning;
+            this.advanced = advanced;
+            this.encodingMode = encodingMode;
+        }
+
+        /**
+         * Whether or not to allow kerning of glyphs.
+         * @return true to allow glyph kerning
+         */
+        public boolean isKerning() {
+            return kerning;
+        }
+        
+        public boolean isAdvanced() {
+            return advanced;
+        }
+
+        /**
+         * Gets the String representing the metrics file.
+         * @return the metrics file
+         */
+        public String getMetrics() {
+            return metrics;
+        }
+
+        /**
+         * Gets the URI of the font to embed.
+         * @return the font URI
+         */
+        public String getEmbedURI() {
+            return embedUri;
+        }
+
+        /**
+         * Gets the sub font within, for example, a TTC.
+         * @return the sub font name
+         */
+        public String getSubFont() {
+            return subFont;
+        }
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/DefaultFontConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/DefaultFontConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/DefaultFontConfigurator.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/DefaultFontConfigurator.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/DefaultFontConfigurator.java Thu May 31 08:33:36 2012
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.io.URIResolverWrapper;
+import org.apache.fop.fonts.DefaultFontConfig.Directory;
+import org.apache.fop.fonts.autodetect.FontFileFinder;
+import org.apache.fop.fonts.autodetect.FontInfoFinder;
+import org.apache.fop.util.LogUtil;
+
+/**
+ * The default configurator for fonts. This configurator can configure the more generic fonts used
+ * by the renderers i.e. TTF, Type1 etc...
+ */
+public class DefaultFontConfigurator implements FontConfigurator<EmbedFontInfo> {
+    /** logger instance */
+    protected static Log log = LogFactory.getLog(DefaultFontConfigurator.class);
+
+    private final FontManager fontManager;
+    private final URIResolverWrapper uriResolver;
+    private final FontEventListener listener;
+    private final boolean strict;
+
+    /**
+     * Main constructor
+     * @param fontInfoConfig the configuration object
+     * @param fontManager the font manager
+     * @param listener the font event listener
+     * @param strict true if an Exception should be thrown if an error is found.
+     */
+    public DefaultFontConfigurator(FontManager fontManager, FontEventListener listener, boolean strict) {
+        this.fontManager = fontManager;
+        this.uriResolver = fontManager.getURIResolver();
+        this.listener = listener;
+        this.strict = strict;
+    }
+
+    /**
+     * Initializes font info settings from the user configuration
+     * @throws FOPException if an exception occurs while processing the configuration
+     */
+    public List<EmbedFontInfo> configure(FontConfig fontInfoConfig)
+            throws FOPException {
+        List<EmbedFontInfo> fontInfoList = new ArrayList<EmbedFontInfo>();
+        DefaultFontConfig adobeFontInfoConfig = (DefaultFontConfig) fontInfoConfig;
+        if (adobeFontInfoConfig != null) {
+            long start = 0;
+            if (log.isDebugEnabled()) {
+                log.debug("Starting font configuration...");
+                start = System.currentTimeMillis();
+            }
+            FontAdder fontAdder = new FontAdder(fontManager, uriResolver, listener);
+            // native o/s search (autodetect) configuration
+            fontManager.autoDetectFonts(adobeFontInfoConfig.isAutoDetectFonts(), fontAdder, strict,
+                    listener, fontInfoList);
+            // Add configured directories to FontInfo list
+            addDirectories(adobeFontInfoConfig, fontAdder, fontInfoList);
+            // Add configured fonts to FontInfo
+            FontCache fontCache = fontManager.getFontCache();
+            try {
+                addFonts(adobeFontInfoConfig, fontCache, fontInfoList);
+            } catch (URISyntaxException use) {
+                LogUtil.handleException(log, use, strict);
+            }
+            // Update referenced fonts (fonts which are not to be embedded)
+            fontManager.updateReferencedFonts(fontInfoList);
+            // Renderer-specific referenced fonts
+            List<String> referencedFonts = adobeFontInfoConfig.getReferencedFontFamily();
+            if (referencedFonts.size() > 0) {
+                FontTriplet.Matcher matcher = FontManagerConfigurator.createFontsMatcher(
+                        referencedFonts, strict);
+                fontManager.updateReferencedFonts(fontInfoList, matcher);
+            }
+            // Update font cache if it has changed
+            fontManager.saveCache();
+            if (log.isDebugEnabled()) {
+                log.debug("Finished font configuration in "
+                        + (System.currentTimeMillis() - start) + "ms");
+            }
+        }
+        return Collections.unmodifiableList(fontInfoList);
+    }
+
+    private void addDirectories(DefaultFontConfig fontInfoConfig, FontAdder fontAdder,
+            List<EmbedFontInfo> fontInfoList) throws FOPException {
+        // directory (multiple font) configuration
+        List<Directory> directories = fontInfoConfig.getDirectories();
+        for (Directory directory : directories) {
+            // add fonts found in directory
+            FontFileFinder fontFileFinder = new FontFileFinder(directory.isRecursive() ? -1 : 1, listener);
+            List<URL> fontURLList;
+            try {
+                fontURLList = fontFileFinder.find(directory.getDirectory());
+                fontAdder.add(fontURLList, fontInfoList);
+            } catch (IOException e) {
+                LogUtil.handleException(log, e, strict);
+            } catch (URISyntaxException use) {
+                LogUtil.handleException(log, use, strict);
+            }
+        }
+    }
+
+    private void addFonts(DefaultFontConfig fontInfoConfig, FontCache fontCache,
+            List<EmbedFontInfo> fontInfoList) throws FOPException, URISyntaxException {
+        // font file (singular) configuration
+        List<DefaultFontConfig.Font> fonts = fontInfoConfig.getFonts();
+        for (DefaultFontConfig.Font font : fonts) {
+            EmbedFontInfo embedFontInfo = getFontInfo(font, fontCache);
+            if (embedFontInfo != null) {
+                fontInfoList.add(embedFontInfo);
+            }
+        }
+    }
+
+    private EmbedFontInfo getFontInfo(DefaultFontConfig.Font font, FontCache fontCache)
+            throws FOPException, URISyntaxException {
+        String embed = font.getEmbedURI();
+        String metrics = font.getMetrics();
+        String subFont = font.getSubFont();
+        URI metricsUri = metrics == null ? null : URIResolverWrapper.cleanURI(metrics);
+        URI embedUri = URIResolverWrapper.cleanURI(embed);
+
+        List<FontTriplet> tripletList = font.getTripletList();
+
+        // no font triplet info
+        if (tripletList.size() == 0) {
+            //TODO: could be problematic!!
+            URI fontUri = uriResolver.getBaseURI().resolve(embedUri);
+            if (fontUri != null) {
+                FontInfoFinder finder = new FontInfoFinder();
+                finder.setEventListener(listener);
+                EmbedFontInfo[] infos = finder.find(fontUri, uriResolver, fontCache);
+                return infos[0]; //When subFont is set, only one font is returned
+            } else {
+                return null;
+            }
+        }
+        EncodingMode encodingMode = EncodingMode.getEncodingMode(font.getEncodingMode());
+        EmbedFontInfo embedFontInfo = new EmbedFontInfo(metricsUri, font.isKerning(),
+                font.isAdvanced(), tripletList, embedUri, subFont, encodingMode);
+        if (fontCache != null) {
+            if (!fontCache.containsFont(embedFontInfo)) {
+                fontCache.addFont(embedFontInfo, uriResolver);
+            }
+        }
+
+        if (log.isDebugEnabled()) {
+            URI embedFile = embedFontInfo.getEmbedURI();
+            log.debug("Adding font " + (embedFile != null ? embedFile + ", " : "")
+                    + "metrics URI " + embedFontInfo.getMetricsURI());
+            for (int j = 0; j < tripletList.size(); ++j) {
+                FontTriplet triplet = tripletList.get(j);
+                log.debug("  Font triplet "
+                        + triplet.getName() + ", "
+                        + triplet.getStyle() + ", "
+                        + triplet.getWeight());
+            }
+        }
+        return embedFontInfo;
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/DefaultFontConfigurator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/EmbedFontInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/EmbedFontInfo.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/EmbedFontInfo.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/EmbedFontInfo.java Thu May 31 08:33:36 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;
 
 /**
@@ -31,60 +32,74 @@ 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 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) {
+        this.metricsURI = metricsURI;
+        this.embedURI = embedURI;
         this.kerning = kerning;
         this.advanced = advanced;
         this.fontTriplets = fontTriplets;
         this.subFontName = subFontName;
+        this.encodingMode = EncodingMode.AUTO;
+    }
+
+    public EmbedFontInfo(URI metricsURI, boolean kerning, boolean advanced,
+            List<FontTriplet> fontTriplets, URI embedURI, String subFontName,
+            EncodingMode encodingMode) {
+        this.metricsURI = metricsURI;
+        this.embedURI = embedURI;
+        this.kerning = kerning;
+        this.advanced = advanced;
+        this.fontTriplets = fontTriplets;
+        this.subFontName = subFontName;
+        this.encodingMode = encodingMode;
     }
 
     /**
-     * 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;
     }
 
     /**
@@ -141,7 +156,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;
@@ -164,17 +179,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;
-    }
-
     private void readObject(java.io.ObjectInputStream in)
                 throws IOException, ClassNotFoundException {
         in.defaultReadObject();
@@ -183,7 +187,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/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontAdder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontAdder.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontAdder.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontAdder.java Thu May 31 08:33:36 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.URIResolverWrapper;
 import org.apache.fop.fonts.autodetect.FontInfoFinder;
 
 /**
@@ -29,7 +31,7 @@ import org.apache.fop.fonts.autodetect.F
  */
 public class FontAdder {
     private final FontEventListener listener;
-    private final FontResolver resolver;
+    private final URIResolverWrapper resolver;
     private final FontManager manager;
 
     /**
@@ -38,7 +40,7 @@ public class FontAdder {
      * @param resolver a font resolver
      * @param listener a font event handler
      */
-    public FontAdder(FontManager manager, FontResolver resolver, FontEventListener listener) {
+    public FontAdder(FontManager manager, URIResolverWrapper resolver, FontEventListener listener) {
         this.manager = manager;
         this.resolver = resolver;
         this.listener = listener;
@@ -48,14 +50,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(), resolver, cache);
             if (embedFontInfos == null) {
                 continue;
             }

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCache.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCache.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCache.java Thu May 31 08:33:36 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.URIResolverWrapper;
 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, URIResolverWrapper resolver) {
         String cacheKey = getCacheKey(fontInfo);
         synchronized (changeLock) {
             CachedFontFile cachedFontFile;
@@ -329,10 +331,10 @@ 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);
+                // TODO: This could be problematic?!!?!?!
+                URI fontUri = resolver.getBaseURI().resolve(fontInfo.getEmbedURI());
+                File fontFile = new File(fontUri);
+                long lastModified = (fontFile != null ? fontFile.lastModified() : -1);
                 cachedFontFile = new CachedFontFile(lastModified);
                 if (log.isTraceEnabled()) {
                     log.trace("Font added to cache: " + cacheKey);
@@ -467,8 +469,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();

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCacheManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCacheManager.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCacheManager.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCacheManager.java Thu May 31 08:33:36 2012
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts;
+
+import java.io.File;
+
+import org.apache.fop.apps.FOPException;
+
+
+/**
+ * Fop cache (currently only used for font info caching)
+ */
+public interface FontCacheManager {
+
+    /**
+     * Loads the font cache into memory from the given file.
+     * @param file the serialized font cache
+     * @return the de-serialized font cache
+     */
+    FontCache load(File file);
+
+    /**
+     * Serializes the font cache to file.
+     * @param file the file to serialize the font cache to
+     * @throws FOPException if an error occurs serializing the font cache
+     */
+    void save(File file) throws FOPException;
+
+    /**
+     * Deletes the font cache from the file-system.
+     * @param file delete the serialized font cache
+     * @throws FOPException if an error occurs deleting the font cache
+     */
+    void delete(File file) throws FOPException;
+
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCacheManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCacheManagerFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCacheManagerFactory.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCacheManagerFactory.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCacheManagerFactory.java Thu May 31 08:33:36 2012
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts;
+
+import java.io.File;
+
+import org.apache.fop.apps.FOPException;
+
+/**
+ * A factory that provides the font caching manager mechanism.
+ *
+ */
+public final class FontCacheManagerFactory {
+
+    private FontCacheManagerFactory() {
+    }
+
+    /**
+     * Create the default font caching mechanism.
+     * @return the font cache manager
+     */
+    public static FontCacheManager createDefault() {
+        return new FontCacheManagerImpl();
+    }
+
+    /**
+     * Create a disabled font caching mechanism which by definition does nothing to cache fonts.
+     * @return a completely restricted font cache manager
+     */
+    public static FontCacheManager createDisabled() {
+        return new DisabledFontCacheManager();
+    }
+
+    private static final class FontCacheManagerImpl implements FontCacheManager {
+
+        private FontCache fontCache;
+
+        public FontCache load(File cacheFile) {
+            if (fontCache == null) {
+                fontCache = FontCache.loadFrom(cacheFile);
+                if (fontCache == null) {
+                    fontCache = new FontCache();
+                }
+            }
+            return fontCache;
+        }
+
+        public void save(File cacheFile) throws FOPException {
+            if (fontCache != null && fontCache.hasChanged()) {
+                fontCache.saveTo(cacheFile);
+            }
+        }
+
+        public void delete(File cacheFile) throws FOPException {
+            if (!cacheFile.delete()) {
+                throw new FOPException("Failed to flush the font cache file '" + cacheFile + "'.");
+            }
+        }
+    }
+
+    private static final class DisabledFontCacheManager implements FontCacheManager {
+
+        public FontCache load(File cacheFile) {
+            return null;
+        }
+
+        public void save(File cacheFile) throws FOPException {
+            // nop
+        }
+
+        public void delete(File cacheFile) throws FOPException {
+            throw new FOPException("Font Cache disabled");
+        }
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontCacheManagerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontConfig.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontConfig.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontConfig.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontConfig.java Thu May 31 08:33:36 2012
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts;
+
+import org.apache.avalon.framework.configuration.Configuration;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.events.EventProducer;
+
+/**
+ * An interface for font configuration information.
+ */
+public interface FontConfig {
+
+    /**
+     * An interface for parsing font configuration information.
+     */
+    public interface FontConfigParser {
+
+        /**
+         * Parse the font configuration and return an object containing all the necessary data.
+         *
+         * @param cfg the configuration object
+         * @param fontManager the font manager
+         * @param strict whether or not to enforce strict validation
+         * @param eventProducer the event producer for handling font events
+         * @return the configuration object
+         * @throws FOPException if an error occurs creating the font configuration object
+         */
+        FontConfig parse(Configuration cfg, FontManager fontManager, boolean strict,
+                EventProducer eventProducer) throws FOPException;
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontConfigurator.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontConfigurator.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontConfigurator.java Thu May 31 08:33:36 2012
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts;
+
+import java.util.List;
+
+import org.apache.fop.apps.FOPException;
+
+/**
+ * An abstract FontInfo configurator
+ */
+// TODO: Make T extends some interface to make the font info type explicit
+public interface FontConfigurator<T> {
+
+    /**
+     * Initializes font info settings from the user configuration
+     * @return a font info list
+     * @throws FOPException if an exception occurs while processing the configuration
+     */
+    List<T> configure(FontConfig fontInfoConfig) throws FOPException;
+
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontConfigurator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontDetector.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontDetector.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontDetector.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontDetector.java Thu May 31 08:33:36 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;
 }

Added: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontDetectorFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontDetectorFactory.java?rev=1344594&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontDetectorFactory.java (added)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontDetectorFactory.java Thu May 31 08:33:36 2012
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.fonts;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+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;
+
+/**
+ * A factory that provides the font detecting machanism.
+ */
+public final class FontDetectorFactory {
+    private FontDetectorFactory() {
+    }
+
+    /**
+     * Creates the default font detector
+     * @return the default font detector
+     */
+    public static FontDetector createDefault() {
+        return new DefaultFontDetector();
+    }
+
+    /**
+     * Creates a disabled font detector which, by definition, does nothing to detect fonts.
+     * @return the completely restricted font detector
+     */
+    public static FontDetector createDisabled() {
+        return new DisabledFontDetector();
+    }
+
+
+    private static class DisabledFontDetector implements FontDetector {
+        public void detect(FontManager fontManager, FontAdder fontAdder, boolean strict,
+                FontEventListener eventListener, List<EmbedFontInfo> fontInfoList)
+                throws FOPException {
+            // nop
+        }
+    }
+
+    /**
+     * Detector of operating system and classpath fonts
+     */
+    private static class DefaultFontDetector implements FontDetector {
+        private static Log log = LogFactory.getLog(DefaultFontDetector.class);
+
+        private static final String[] FONT_MIMETYPES = {
+            "application/x-font", "application/x-font-truetype"
+        };
+
+        /**
+         * 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(FontManager fontManager, FontAdder fontAdder, boolean strict,
+                FontEventListener eventListener, List<EmbedFontInfo> fontInfoList)
+                throws FOPException {
+            try {
+                // search in font base if it is defined and
+                // is a directory but don't recurse
+                FontFileFinder fontFileFinder = new FontFileFinder(eventListener);
+                URI fontBaseURI = fontManager.getURIResolver().getBaseURI();
+                if (fontBaseURI != null) {
+                    File fontBase = FileUtils.toFile(fontBaseURI.toURL());
+                    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
+                    }
+                }
+
+                // native o/s font directory finding
+                List<URL> systemFontList;
+                systemFontList = fontFileFinder.find();
+                fontAdder.add(systemFontList, fontInfoList);
+
+                // classpath font finding
+                ClasspathResource resource = ClasspathResource.getInstance();
+                for (String mimeTypes : FONT_MIMETYPES) {
+                    fontAdder.add(resource.listResourcesOfMimeType(mimeTypes), fontInfoList);
+                }
+            } catch (IOException e) {
+                LogUtil.handleException(log, e, strict);
+            } catch (URISyntaxException use) {
+                LogUtil.handleException(log, use, strict);
+            }
+        }
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontDetectorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontLoader.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontLoader.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontLoader.java Thu May 31 08:33:36 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.URIResolverWrapper;
 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;
+    protected final URI fontFileURI;
     /** the FontResolver to use for font URI resolution */
-    protected FontResolver resolver;
+    protected final URIResolverWrapper resolver;
     /** the loaded font */
     protected CustomFont returnFont;
 
@@ -67,8 +62,8 @@ public abstract class FontLoader {
      * available
      * @param resolver 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, URIResolverWrapper resolver) {
         this.fontFileURI = fontFileURI;
         this.embedded = embedded;
         this.useKerning = useKerning;
@@ -76,42 +71,8 @@ public abstract class FontLoader {
         this.resolver = resolver;
     }
 
-    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 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, EncodingMode encodingMode, FontResolver resolver) throws IOException {
-        return loadFont(fontFile.toURI().toURL(), subFontName,
-                embedded, 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 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, EncodingMode encodingMode,
-            FontResolver resolver) throws IOException {
-        return loadFont(fontUrl.toExternalForm(), subFontName,
-                embedded, encodingMode, true, true,
-                resolver);
+    private static boolean isType1(URI fontURI) {
+        return fontURI.toASCIIString().toLowerCase().endsWith(".pfb");
     }
 
     /**
@@ -127,10 +88,9 @@ public abstract class FontLoader {
      * @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, EncodingMode encodingMode, boolean useKerning,
-            boolean useAdvanced, FontResolver resolver) throws IOException {
-        fontFileURI = fontFileURI.trim();
+            boolean useAdvanced, URIResolverWrapper resolver) throws IOException {
         boolean type1 = isType1(fontFileURI);
         FontLoader loader;
         if (type1) {
@@ -147,41 +107,6 @@ public abstract class FontLoader {
     }
 
     /**
-     * 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_URI_Unification/src/java/org/apache/fop/fonts/FontManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontManager.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontManager.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontManager.java Thu May 31 08:33:36 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.URIResolverWrapper;
 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;
+    private URIResolverWrapper uriResolver;
+
+    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 uriResolver the URI resolver
+     * @param fontDetector the font detector
+     * @param fontCacheManager the font cache manager
      */
-    public FontManager() {
+    public FontManager(URIResolverWrapper uriResolver, FontDetector fontDetector,
+            FontCacheManager fontCacheManager) {
+        this.uriResolver = uriResolver;
+        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 URI resolver
+     * @param uriResolver font base URI
      */
-    public void setFontBaseURL(String fontBase) throws MalformedURLException {
-        this.fontBase = fontBase;
+    public void setFontURIResolver(URIResolverWrapper uriResolver) {
+        this.uriResolver = uriResolver;
     }
 
-    /**
-     * Returns the font base URL.
-     * @return the font base URL (or null if none was set)
-     */
-    public String getFontBaseURL() {
-        return this.fontBase;
+    public URIResolverWrapper getURIResolver() {
+        return this.uriResolver;
     }
 
     /** @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,11 @@ public class FontManager {
             }
         }
     }
+
+    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_URI_Unification/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontManagerConfigurator.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontManagerConfigurator.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontManagerConfigurator.java Thu May 31 08:33:36 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,8 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.io.ResourceResolver;
+import org.apache.fop.apps.io.URIResolverWrapper;
 import org.apache.fop.fonts.substitute.FontSubstitutions;
 import org.apache.fop.fonts.substitute.FontSubstitutionsConfigurator;
 import org.apache.fop.util.LogUtil;
@@ -45,24 +47,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 uriResolver;
 
     /**
      * 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 resolver the URI resolver
      */
-    public FontManagerConfigurator(Configuration cfg, URI baseURI) {
+    public FontManagerConfigurator(Configuration cfg, URI defaultBaseUri,
+            ResourceResolver resolver) {
         this.cfg = cfg;
-        this.baseURI = baseURI;
+        this.defaultBaseUri = defaultBaseUri;
+        this.uriResolver = resolver;
     }
 
     /**
@@ -75,28 +74,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);
+                // TODO: Find some way to deal with this!!
+                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 = URIResolverWrapper.getBaseURI(cfg.getChild("font-base").getValue(
+                        null));
+                fontManager.setFontURIResolver(new URIResolverWrapper(
+                        defaultBaseUri.resolve(fontBase), uriResolver));
+            } catch (URISyntaxException use) {
+                LogUtil.handleException(log, use, true);
             }
+        } else {
+            fontManager.setFontURIResolver(new URIResolverWrapper(defaultBaseUri, uriResolver));
         }
 
         // [GA] permit configuration control over base14 kerning; without this,
@@ -114,7 +114,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 +121,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 +128,6 @@ public class FontManagerConfigurator {
                         referencedFontsCfg, strict);
                 fontManager.setReferencedFontsMatcher(matcher);
             }
-
         }
     }
 
@@ -159,6 +156,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_URI_Unification/src/java/org/apache/fop/fonts/FontReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontReader.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontReader.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontReader.java Thu May 31 08:33:36 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.URIResolverWrapper;
 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 URIResolverWrapper resolver;
     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<BFEntry> bfranges = null;
+    private List<BFEntry> 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, URIResolverWrapper resolver) throws FOPException {
+        this.resolver = resolver;
+        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}
      */
     public void startDocument() {
@@ -160,65 +152,62 @@ public class FontReader extends DefaultH
     /**
      * {@inheritDoc}
      */
-    public void setDocumentLocator(Locator locator) {
-        // this.locator = locator; // not used at present
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    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(resolver);
                 returnFont = multiFont;
                 isCID = true;
                 TTFReader.checkMetricsVersion(attributes);
             } else if ("TRUETYPE".equals(attributes.getValue("type"))) {
-                singleFont = new SingleByteFont();
+                singleFont = new SingleByteFont(resolver);
                 singleFont.setFontType(FontType.TRUETYPE);
                 returnFont = singleFont;
                 isCID = false;
                 TTFReader.checkMetricsVersion(attributes);
             } else {
-                singleFont = new SingleByteFont();
+                singleFont = new SingleByteFont(resolver);
                 singleFont.setFontType(FontType.TYPE1);
                 returnFont = singleFont;
                 isCID = false;
             }
         } else if ("embed".equals(localName)) {
-            returnFont.setEmbedFileName(attributes.getValue("file"));
+            try {
+                returnFont.setEmbedURI(URIResolverWrapper.cleanURI(attributes.getValue("file")));
+            } catch (URISyntaxException e) {
+                // TODO: dunno what to do here?!?!
+            }
             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<BFEntry>();
         } else if ("bf".equals(localName)) {
             BFEntry entry = new BFEntry(getInt(attributes.getValue("us")),
-                                        getInt(attributes.getValue("ue")),
-                                        getInt(attributes.getValue("gi")));
+                    getInt(attributes.getValue("ue")),
+                    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")));
         }
 
     }
@@ -314,5 +303,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_URI_Unification/src/java/org/apache/fop/fonts/FontSetup.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontSetup.java?rev=1344594&r1=1344593&r2=1344594&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontSetup.java (original)
+++ xmlgraphics/fop/branches/Temp_URI_Unification/src/java/org/apache/fop/fonts/FontSetup.java Thu May 31 08:33:36 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.URIResolverWrapper;
 import org.apache.fop.fonts.base14.Courier;
 import org.apache.fop.fonts.base14.CourierBold;
 import org.apache.fop.fonts.base14.CourierBoldOblique;
@@ -74,8 +72,8 @@ public final class FontSetup {
      * @param resolver 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,
+            URIResolverWrapper resolver, boolean base14Kerning) {
         fontInfo.addMetrics("F1", new Helvetica(base14Kerning));
         fontInfo.addMetrics("F2", new HelveticaOblique(base14Kerning));
         fontInfo.addMetrics("F3", new HelveticaBold(base14Kerning));
@@ -192,18 +190,12 @@ public final class FontSetup {
      * @param resolver the font resolver
      */
     private static void addConfiguredFonts(FontInfo fontInfo,
-            List<EmbedFontInfo> embedFontInfoList, int num, FontResolver resolver,
+            List<EmbedFontInfo> embedFontInfoList, int num, URIResolverWrapper resolver,
             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 resolver != null;
 
         String internalName = null;
 
@@ -211,7 +203,7 @@ public final class FontSetup {
             internalName = "F" + num;
             num++;
 
-            LazyFont font = new LazyFont(embedFontInfo, resolver);
+            LazyFont font = new LazyFont(embedFontInfo, resolver, false);
             fontInfo.addMetrics(internalName, font);
 
             List<FontTriplet> triplets = embedFontInfo.getFontTriplets();
@@ -221,32 +213,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 );
-    }
 }



---------------------------------------------------------------------
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