You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ac...@apache.org on 2010/08/15 18:15:56 UTC

svn commit: r985700 - in /xmlgraphics/fop/trunk: ./ src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/cli/ src/java/org/apache/fop/fonts/

Author: acumiskey
Date: Sun Aug 15 16:15:55 2010
New Revision: 985700

URL: http://svn.apache.org/viewvc?rev=985700&view=rev
Log:
Reinstated support for being able to specify a font cache filepath in the fop user configuration.
Added convenience support for the deletion of the Fop font cache file from the command line.

Modified:
    xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/configuration.xml
    xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/running.xml
    xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactoryConfigurator.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfoConfigurator.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/configuration.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/configuration.xml?rev=985700&r1=985699&r2=985700&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/configuration.xml (original)
+++ xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/configuration.xml Sun Aug 15 16:15:55 2010
@@ -176,8 +176,7 @@
       <tr>
         <td>cache-file</td>
         <td>String</td>
-        <td>This options specifies the file/directory path of the fop cache file.
-        This option can also be specified on the command-line using the -cache option.
+        <td>This option specifies the file/directory path of the fop cache file.
         This file is currently only used to cache font triplet information for future reference.</td>
         <td>${base}/conf/fop.cache</td>
       </tr>

Modified: xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/running.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/running.xml?rev=985700&r1=985699&r2=985700&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/running.xml (original)
+++ xmlgraphics/fop/trunk/src/documentation/content/xdocs/trunk/running.xml Sun Aug 15 16:15:55 2010
@@ -132,9 +132,11 @@ Fop [options] [-fo|-xml] infile [-xsl fi
   -pdfprofile prof  PDF file will be generated with the specified profile
                     (Examples for prof: PDF/A-1b or PDF/X-3:2003)
 
-  -conserve         Enable memory-conservation policy (trades memory-consumption for disk I/O)
+  -conserve         enable memory-conservation policy (trades memory-consumption for disk I/O)
                     (Note: currently only influences whether the area tree is serialized.)
 
+  -delete-cache     deletes the current font cache file
+
  [INPUT]
   infile            xsl:fo input file (the same as the next)
                     (use '-' for infile to pipe input from stdin)

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactoryConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactoryConfigurator.java?rev=985700&r1=985699&r2=985700&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactoryConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactoryConfigurator.java Sun Aug 15 16:15:55 2010
@@ -34,7 +34,6 @@ import org.apache.commons.logging.LogFac
 import org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry;
 import org.apache.xmlgraphics.image.loader.util.Penalty;
 
-import org.apache.fop.fonts.FontManager;
 import org.apache.fop.fonts.FontManagerConfigurator;
 import org.apache.fop.util.LogUtil;
 
@@ -198,9 +197,7 @@ public class FopFactoryConfigurator {
         }
 
         // configure font manager
-        FontManager fontManager = factory.getFontManager();
-        FontManagerConfigurator fontManagerConfigurator = new FontManagerConfigurator(cfg);
-        fontManagerConfigurator.configure(fontManager, strict);
+        new FontManagerConfigurator(cfg).configure(factory.getFontManager(), strict);
 
         // configure image loader framework
         configureImageLoading(cfg.getChild("image-loading", false), strict);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java?rev=985700&r1=985699&r2=985700&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/CommandLineOptions.java Sun Aug 15 16:15:55 2010
@@ -41,6 +41,7 @@ import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.fonts.FontManager;
 import org.apache.fop.pdf.PDFAMode;
 import org.apache.fop.pdf.PDFEncryptionManager;
 import org.apache.fop.pdf.PDFEncryptionParams;
@@ -284,6 +285,10 @@ public class CommandLineOptions {
                 factory.setStrictValidation(false);
             } else if (args[i].equals("-conserve")) {
                 conserveMemoryPolicy = true;
+            } else if (args[i].equals("-delete-cache")) {
+                parseDeleteCacheOption(args, i);
+            } else if (args[i].equals("-cache")) {
+                parseCacheOption(args, i);
             } else if (args[i].equals("-dpi")) {
                 i = i + parseResolution(args, i);
             } else if (args[i].equals("-q") || args[i].equals("--quiet")) {
@@ -385,6 +390,37 @@ public class CommandLineOptions {
         return true;
     }    // end parseOptions
 
+    private int parseCacheOption(String[] args, int i) throws FOPException {
+        if ((i + 1 == args.length)
+                || (isOption(args[i + 1]))) {
+            throw new FOPException("if you use '-cache', you must specify "
+              + "the name of the font cache file");
+        } else {
+            factory.getFontManager().setCacheFile(new File(args[i + 1]));
+            return 1;
+        }
+    }
+
+    private void parseDeleteCacheOption(String[] args, int i) throws FOPException {
+        FontManager fontManager = factory.getFontManager();
+        try {
+            setUserConfig();
+            File cacheFile = fontManager.getCacheFile();
+            if (fontManager.deleteCache()) {
+                System.out.println("Successfully deleted the font cache file '"
+                        + cacheFile + "'.");
+                System.exit(0);
+            } else {
+                System.err.println("Failed to delete the font cache file '"
+                        + cacheFile + "'.");
+                System.exit(1);
+            }
+        } catch (IOException e) {
+            System.err.println("Failed to delete the font cache file");
+            System.exit(1);
+        }
+    }
+
     private int parseConfigurationOption(String[] args, int i) throws FOPException {
         if ((i + 1 == args.length)
                 || (isOption(args[i + 1]))) {
@@ -1164,10 +1200,15 @@ public class CommandLineOptions {
             + "  -a                enables accessibility features (Tagged PDF etc., default off)\n"
             + "  -pdfprofile prof  PDF file will be generated with the specified profile\n"
             + "                    (Examples for prof: PDF/A-1b or PDF/X-3:2003)\n\n"
-            + "  -conserve         Enable memory-conservation policy (trades memory-consumption"
+            + "  -conserve         enable memory-conservation policy (trades memory-consumption"
             + " for disk I/O)\n"
             + "                    (Note: currently only influences whether the area tree is"
             + " serialized.)\n\n"
+
+            + "  -delete-cache     deletes the current font cache file\n"
+            + "  -cache            specifies a file/directory path location"
+            + " for the font cache file\n\n"
+
             + " [INPUT]  \n"
             + "  infile            xsl:fo input file (the same as the next) \n"
             + "                    (use '-' for infile to pipe input from stdin)\n"

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java?rev=985700&r1=985699&r2=985700&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontCache.java Sun Aug 15 16:15:55 2010
@@ -19,7 +19,9 @@
 
 package org.apache.fop.fonts;
 
+import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
@@ -45,8 +47,8 @@ import org.apache.fop.util.LogUtil;
 public final class FontCache implements Serializable {
 
     /**
-     * Serialization Version UID. Change this value if you want to make sure the user's cache
-     * file is purged after an update.
+     * Serialization Version UID. Change this value if you want to make sure the
+     * user's cache file is purged after an update.
      */
     private static final long serialVersionUID = 605232520271754719L;
 
@@ -59,19 +61,23 @@ public final class FontCache implements 
     /** font cache file path */
     private static final String DEFAULT_CACHE_FILENAME = "fop-fonts.cache";
 
-
     /** has this cache been changed since it was last read? */
     private transient boolean changed = false;
 
     /** change lock */
     private final boolean[] changeLock = new boolean[1];
 
-    /** master mapping of font url -> font info.  This needs to be
-     *  a list, since a TTC file may contain more than 1 font. */
-    private Map/*<String, CachedFontFile>*/ fontfileMap = null;
+    /**
+     * master mapping of font url -> font info. This needs to be a list, since a
+     * TTC file may contain more than 1 font.
+     */
+    private Map/* <String, CachedFontFile> */fontfileMap = null;
 
-    /** mapping of font url -> file modified date (for all fonts that have failed to load) */
-    private Map failedFontMap/*<String, Long>*/ = null;
+    /**
+     * mapping of font url -> file modified date (for all fonts that have failed
+     * to load)
+     */
+    private Map failedFontMap/* <String, Long> */= null;
 
     /**
      * Default constructor
@@ -100,7 +106,9 @@ public final class FontCache implements 
 
     /**
      * Returns the default font cache file.
-     * @param forWriting true if the user directory should be created
+     * 
+     * @param forWriting
+     *            true if the user directory should be created
      * @return the default font cache file
      */
     public static File getDefaultCacheFile(boolean forWriting) {
@@ -125,8 +133,9 @@ public final class FontCache implements 
 
     /**
      * Reads the default font cache file and returns its contents.
-     * @return the font cache deserialized from the file (or null if no cache file exists or if
-     *         it could not be read)
+     * 
+     * @return the font cache deserialized from the file (or null if no cache
+     *         file exists or if it could not be read)
      */
     public static FontCache load() {
         return loadFrom(getDefaultCacheFile(false));
@@ -134,36 +143,41 @@ public final class FontCache implements 
 
     /**
      * Reads a font cache file and returns its contents.
-     * @param cacheFile the cache file
-     * @return the font cache deserialized from the file (or null if no cache file exists or if
-     *         it could not be read)
+     * 
+     * @param cacheFile
+     *            the cache file
+     * @return the font cache deserialized from the file (or null if no cache
+     *         file exists or if it could not be read)
      */
     public static FontCache loadFrom(File cacheFile) {
         if (cacheFile.exists()) {
             try {
                 if (log.isTraceEnabled()) {
-                    log.trace("Loading font cache from " + cacheFile.getCanonicalPath());
+                    log.trace("Loading font cache from "
+                            + cacheFile.getCanonicalPath());
                 }
-                InputStream in = new java.io.FileInputStream(cacheFile);
-                in = new java.io.BufferedInputStream(in);
+                InputStream in = new BufferedInputStream(new FileInputStream(cacheFile));
                 ObjectInputStream oin = new ObjectInputStream(in);
                 try {
-                    return (FontCache)oin.readObject();
+                    return (FontCache) oin.readObject();
                 } finally {
                     IOUtils.closeQuietly(oin);
                 }
             } catch (ClassNotFoundException e) {
-                //We don't really care about the exception since it's just a cache file
+                // We don't really care about the exception since it's just a
+                // cache file
                 log.warn("Could not read font cache. Discarding font cache file. Reason: "
                         + e.getMessage());
             } catch (IOException ioe) {
-                //We don't really care about the exception since it's just a cache file
-                log.warn("I/O exception while reading font cache (" + ioe.getMessage()
-                        + "). Discarding font cache file.");
+                // We don't really care about the exception since it's just a
+                // cache file
+                log.warn("I/O exception while reading font cache ("
+                        + ioe.getMessage() + "). Discarding font cache file.");
                 try {
                     cacheFile.delete();
                 } catch (SecurityException ex) {
-                    log.warn("Failed to delete font cache file: " + cacheFile.getAbsolutePath());
+                    log.warn("Failed to delete font cache file: "
+                            + cacheFile.getAbsolutePath());
                 }
             }
         }
@@ -172,7 +186,9 @@ public final class FontCache implements 
 
     /**
      * Writes the font cache to disk.
-     * @throws FOPException fop exception
+     * 
+     * @throws FOPException
+     *             fop exception
      */
     public void save() throws FOPException {
         saveTo(getDefaultCacheFile(true));
@@ -180,16 +196,17 @@ public final class FontCache implements 
 
     /**
      * Writes the font cache to disk.
-     * @param cacheFile the file to write to
-     * @throws FOPException fop exception
+     * 
+     * @param cacheFile
+     *            the file to write to
+     * @throws FOPException
+     *             fop exception
      */
     public void saveTo(File cacheFile) throws FOPException {
         synchronized (changeLock) {
             if (changed) {
                 try {
-                    if (log.isTraceEnabled()) {
-                        log.trace("Writing font cache to " + cacheFile.getCanonicalPath());
-                    }
+                    log.trace("Writing font cache to " + cacheFile.getCanonicalPath());
                     OutputStream out = new java.io.FileOutputStream(cacheFile);
                     out = new java.io.BufferedOutputStream(out);
                     ObjectOutputStream oout = new ObjectOutputStream(out);
@@ -209,7 +226,9 @@ public final class FontCache implements 
 
     /**
      * creates a key given a font info for the font mapping
-     * @param fontInfo font info
+     * 
+     * @param fontInfo
+     *            font info
      * @return font cache key
      */
     protected static String getCacheKey(EmbedFontInfo fontInfo) {
@@ -223,6 +242,7 @@ public final class FontCache implements 
 
     /**
      * cache has been updated since it was read
+     * 
      * @return if this cache has changed
      */
     public boolean hasChanged() {
@@ -231,28 +251,33 @@ public final class FontCache implements 
 
     /**
      * is this font in the cache?
-     * @param embedUrl font info
+     * 
+     * @param embedUrl
+     *            font info
      * @return boolean
      */
     public boolean containsFont(String embedUrl) {
-        return (embedUrl != null
-                && getFontFileMap().containsKey(embedUrl));
+        return (embedUrl != null && getFontFileMap().containsKey(embedUrl));
     }
 
     /**
      * is this font info in the cache?
-     * @param fontInfo font info
+     * 
+     * @param fontInfo
+     *            font info
      * @return font
      */
     public boolean containsFont(EmbedFontInfo fontInfo) {
-        return (fontInfo != null
-                && getFontFileMap().containsKey(getCacheKey(fontInfo)));
+        return (fontInfo != null && getFontFileMap().containsKey(
+                getCacheKey(fontInfo)));
     }
 
     /**
-     * Tries to identify a File instance from an array of URLs. If there's no file URL in the
-     * array, the method returns null.
-     * @param urls array of possible font urls
+     * Tries to identify a File instance from an array of URLs. If there's no
+     * file URL in the array, the method returns null.
+     * 
+     * @param urls
+     *            array of possible font urls
      * @return file font file
      */
     public static File getFileFromUrls(String[] urls) {
@@ -279,31 +304,35 @@ public final class FontCache implements 
         return null;
     }
 
-    private Map/*<String, CachedFontFile>*/ getFontFileMap() {
+    private Map/* <String, CachedFontFile> */getFontFileMap() {
         if (fontfileMap == null) {
-            fontfileMap = new java.util.HashMap/*<String, CachedFontFile>*/();
+            fontfileMap = new java.util.HashMap/* <String, CachedFontFile> */();
         }
         return fontfileMap;
     }
 
     /**
      * Adds a font info to cache
-     * @param fontInfo font info
+     * 
+     * @param fontInfo
+     *            font info
      */
     public void addFont(EmbedFontInfo fontInfo) {
         String cacheKey = getCacheKey(fontInfo);
         synchronized (changeLock) {
             CachedFontFile cachedFontFile;
             if (containsFont(cacheKey)) {
-                cachedFontFile = (CachedFontFile)getFontFileMap().get(cacheKey);
+                cachedFontFile = (CachedFontFile) getFontFileMap()
+                        .get(cacheKey);
                 if (!cachedFontFile.containsFont(fontInfo)) {
                     cachedFontFile.put(fontInfo);
                 }
             } else {
                 // try and determine modified date
-                File fontFile = getFileFromUrls(new String[]
-                                     {fontInfo.getEmbedFile(), fontInfo.getMetricsFile()});
-                long lastModified = (fontFile != null ? fontFile.lastModified() : -1);
+                File fontFile = getFileFromUrls(new String[] {
+                        fontInfo.getEmbedFile(), fontInfo.getMetricsFile() });
+                long lastModified = (fontFile != null ? fontFile.lastModified()
+                        : -1);
                 cachedFontFile = new CachedFontFile(lastModified);
                 if (log.isTraceEnabled()) {
                     log.trace("Font added to cache: " + cacheKey);
@@ -317,19 +346,27 @@ public final class FontCache implements 
 
     /**
      * Returns a font from the cache.
-     * @param embedUrl font info
+     * 
+     * @param embedUrl
+     *            font info
      * @return CachedFontFile object
      */
     public CachedFontFile getFontFile(String embedUrl) {
-        return containsFont(embedUrl) ? (CachedFontFile) getFontFileMap().get(embedUrl) : null;
+        return containsFont(embedUrl) ? (CachedFontFile) getFontFileMap().get(
+                embedUrl) : null;
     }
 
     /**
-     * Returns the EmbedFontInfo instances belonging to a font file. If the font file was
-     * modified since it was cached the entry is removed and null is returned.
-     * @param embedUrl the font URL
-     * @param lastModified the last modified date/time of the font file
-     * @return the EmbedFontInfo instances or null if there's no cached entry or if it is outdated
+     * Returns the EmbedFontInfo instances belonging to a font file. If the font
+     * file was modified since it was cached the entry is removed and null is
+     * returned.
+     * 
+     * @param embedUrl
+     *            the font URL
+     * @param lastModified
+     *            the last modified date/time of the font file
+     * @return the EmbedFontInfo instances or null if there's no cached entry or
+     *         if it is outdated
      */
     public EmbedFontInfo[] getFontInfos(String embedUrl, long lastModified) {
         CachedFontFile cff = getFontFile(embedUrl);
@@ -343,7 +380,9 @@ public final class FontCache implements 
 
     /**
      * removes font from cache
-     * @param embedUrl embed url
+     * 
+     * @param embedUrl
+     *            embed url
      */
     public void removeFont(String embedUrl) {
         synchronized (changeLock) {
@@ -359,14 +398,18 @@ public final class FontCache implements 
 
     /**
      * has this font previously failed to load?
-     * @param embedUrl embed url
-     * @param lastModified last modified
+     * 
+     * @param embedUrl
+     *            embed url
+     * @param lastModified
+     *            last modified
      * @return whether this is a failed font
      */
     public boolean isFailedFont(String embedUrl, long lastModified) {
         synchronized (changeLock) {
             if (getFailedFontMap().containsKey(embedUrl)) {
-                long failedLastModified = ((Long)getFailedFontMap().get(embedUrl)).longValue();
+                long failedLastModified = ((Long) getFailedFontMap().get(
+                        embedUrl)).longValue();
                 if (lastModified != failedLastModified) {
                     // this font has been changed so lets remove it
                     // from failed font map for now
@@ -382,8 +425,11 @@ public final class FontCache implements 
 
     /**
      * Registers a failed font with the cache
-     * @param embedUrl embed url
-     * @param lastModified time last modified
+     * 
+     * @param embedUrl
+     *            embed url
+     * @param lastModified
+     *            time last modified
      */
     public void registerFailedFont(String embedUrl, long lastModified) {
         synchronized (changeLock) {
@@ -394,9 +440,9 @@ public final class FontCache implements 
         }
     }
 
-    private Map/*<String, Long>*/ getFailedFontMap() {
+    private Map/* <String, Long> */getFailedFontMap() {
         if (failedFontMap == null) {
-            failedFontMap = new java.util.HashMap/*<String, Long>*/();
+            failedFontMap = new java.util.HashMap/* <String, Long> */();
         }
         return failedFontMap;
     }
@@ -417,7 +463,9 @@ public final class FontCache implements 
 
     /**
      * Retrieve the last modified date/time of a URL.
-     * @param url the URL
+     * 
+     * @param url
+     *            the URL
      * @return the last modified date/time
      */
     public static long getLastModified(URL url) {
@@ -426,7 +474,8 @@ public final class FontCache implements 
             try {
                 return conn.getLastModified();
             } finally {
-                //An InputStream is created even if it's not accessed, but we need to close it.
+                // An InputStream is created even if it's not accessed, but we
+                // need to close it.
                 IOUtils.closeQuietly(conn.getInputStream());
             }
         } catch (IOException e) {
@@ -442,15 +491,15 @@ public final class FontCache implements 
         /** file modify date (if available) */
         private long lastModified = -1;
 
-        private Map/*<String, EmbedFontInfo>*/ filefontsMap = null;
+        private Map/* <String, EmbedFontInfo> */filefontsMap = null;
 
         public CachedFontFile(long lastModified) {
             setLastModified(lastModified);
         }
 
-        private Map/*<String, EmbedFontInfo>*/ getFileFontsMap() {
+        private Map/* <String, EmbedFontInfo> */getFileFontsMap() {
             if (filefontsMap == null) {
-                filefontsMap = new java.util.HashMap/*<String, EmbedFontInfo>*/();
+                filefontsMap = new java.util.HashMap/* <String, EmbedFontInfo> */();
             }
             return filefontsMap;
         }
@@ -465,12 +514,13 @@ public final class FontCache implements 
         }
 
         public EmbedFontInfo[] getEmbedFontInfos() {
-            return (EmbedFontInfo[])getFileFontsMap().values().toArray(
+            return (EmbedFontInfo[]) getFileFontsMap().values().toArray(
                     new EmbedFontInfo[getFileFontsMap().size()]);
         }
 
         /**
          * Gets the modified timestamp for font file (not always available)
+         * 
          * @return modified timestamp
          */
         public long lastModified() {
@@ -478,17 +528,18 @@ public final class FontCache implements 
         }
 
         /**
-         * Gets the modified timestamp for font file
-         * (used for the purposes of font info caching)
-         * @param lastModified modified font file timestamp
+         * Gets the modified timestamp for font file (used for the purposes of
+         * font info caching)
+         * 
+         * @param lastModified
+         *            modified font file timestamp
          */
         public void setLastModified(long lastModified) {
             this.lastModified = lastModified;
         }
 
         /**
-         * @return string representation of this object
-         * {@inheritDoc}
+         * @return string representation of this object {@inheritDoc}
          */
         public String toString() {
             return super.toString() + ", lastModified=" + lastModified;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfoConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfoConfigurator.java?rev=985700&r1=985699&r2=985700&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfoConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfoConfigurator.java Sun Aug 15 16:15:55 2010
@@ -75,8 +75,8 @@ public class FontInfoConfigurator {
      * @throws FOPException if an exception occurs while processing the configuration
      */
     public void configure(List/*<EmbedFontInfo>*/ fontInfoList) throws FOPException {
-        Configuration fonts = cfg.getChild("fonts", false);
-        if (fonts != null) {
+        Configuration fontsCfg = cfg.getChild("fonts", false);
+        if (fontsCfg != null) {
             long start = 0;
             if (log.isDebugEnabled()) {
                 log.debug("Starting font configuration...");
@@ -86,24 +86,23 @@ public class FontInfoConfigurator {
             FontAdder fontAdder = new FontAdder(fontManager, fontResolver, listener);
 
             // native o/s search (autodetect) configuration
-            boolean autodetectFonts = (fonts.getChild("auto-detect", false) != null);
+            boolean autodetectFonts = (fontsCfg.getChild("auto-detect", false) != null);
             if (autodetectFonts) {
                 FontDetector fontDetector = new FontDetector(fontManager, fontAdder, strict);
                 fontDetector.detect(fontInfoList);
             }
 
-            // Add configured directories to FontInfo
-            addDirectories(fonts, fontAdder, fontInfoList);
+            // Add configured directories to FontInfo list
+            addDirectories(fontsCfg, fontAdder, fontInfoList);
 
-            // Add configured fonts to FontInfo
-            FontCache fontCache = fontManager.getFontCache();
-            addFonts(fonts, fontCache, fontInfoList);
+            // Add fonts from configuration to FontInfo list
+            addFonts(fontsCfg, fontManager.getFontCache(), fontInfoList);
 
             // Update referenced fonts (fonts which are not to be embedded)
             fontManager.updateReferencedFonts(fontInfoList);
 
             // Renderer-specific referenced fonts
-            Configuration referencedFontsCfg = fonts.getChild("referenced-fonts", false);
+            Configuration referencedFontsCfg = fontsCfg.getChild("referenced-fonts", false);
             if (referencedFontsCfg != null) {
                 FontTriplet.Matcher matcher = FontManagerConfigurator.createFontsMatcher(
                         referencedFontsCfg, strict);
@@ -111,9 +110,7 @@ public class FontInfoConfigurator {
             }
 
             // Update font cache if it has changed
-            if (fontCache != null && fontCache.hasChanged()) {
-                fontCache.save();
-            }
+            fontManager.saveCache();
 
             if (log.isDebugEnabled()) {
                 log.debug("Finished font configuration in "

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManager.java?rev=985700&r1=985699&r2=985700&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManager.java Sun Aug 15 16:15:55 2010
@@ -19,6 +19,7 @@
 
 package org.apache.fop.fonts;
 
+import java.io.File;
 import java.net.MalformedURLException;
 import java.util.Iterator;
 import java.util.List;
@@ -26,12 +27,12 @@ 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.fonts.FontTriplet.Matcher;
 import org.apache.fop.fonts.substitute.FontSubstitutions;
 
 // TODO: Refactor fonts package so major font activities (autodetection etc)
-// are all centrally managed and delegated from this class, also remove dependency on FopFactory
-// and start using POJO config/properties type classes
+// are all centrally managed and delegated from this class
 
 /**
  * The manager of fonts. The class holds a reference to the font cache and information about
@@ -56,11 +57,16 @@ 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
      */
     public FontManager() {
-        setUseCache(DEFAULT_USE_CACHE);
     }
 
     /**
@@ -113,16 +119,31 @@ public class FontManager {
     }
 
     /**
+     * Sets the font cache file
+     * @param cacheFile the font cache file
+     */
+    public void setCacheFile(File cacheFile) {
+        this.cacheFile = cacheFile;
+    }
+
+    /**
+     * Returns the font cache file
+     * @return the font cache file
+     */
+    public File getCacheFile() {
+        if (cacheFile != null) {
+            return this.cacheFile;
+        }
+        return FontCache.getDefaultCacheFile(false);
+    }
+
+    /**
      * Whether or not to cache results of font triplet detection/auto-config
      * @param useCache use cache or not
      */
     public void setUseCache(boolean useCache) {
-        if (useCache) {
-            this.fontCache = FontCache.load();
-            if (this.fontCache == null) {
-                this.fontCache = new FontCache();
-            }
-        } else {
+        this.useCache = useCache;
+        if (!useCache) {
             this.fontCache = null;
         }
     }
@@ -132,7 +153,7 @@ public class FontManager {
      * @return true if this font manager uses the cache
      */
     public boolean useCache() {
-        return (this.fontCache != null);
+        return useCache;
     }
 
     /**
@@ -140,7 +161,53 @@ public class FontManager {
      * @return the font cache
      */
     public FontCache getFontCache() {
-        return this.fontCache;
+        if (fontCache == null) {
+            if (useCache) {
+                if (cacheFile != null) {
+                    fontCache = FontCache.loadFrom(cacheFile);
+                } else {
+                    fontCache = FontCache.load();
+                }
+                if (fontCache == null) {
+                    fontCache = new FontCache();
+                }
+            }
+        }
+        return fontCache;
+    }
+    
+    /**
+     * Saves the FontCache as necessary
+     * 
+     * @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();
+                }
+            }
+        }
+    }
+
+    /**
+     * Deletes the current FontCache file
+     * @return Returns true if the font cache file was successfully deleted.
+     */
+    public boolean deleteCache() {
+        boolean deleted = false;
+        if (useCache) {
+            if (cacheFile != null) {
+                deleted = cacheFile.delete();
+                cacheFile = null;
+            } else {
+                deleted = FontCache.getDefaultCacheFile(true).delete();
+            }
+        }
+        return deleted;
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java?rev=985700&r1=985699&r2=985700&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontManagerConfigurator.java Sun Aug 15 16:15:55 2010
@@ -19,6 +19,7 @@
 
 package org.apache.fop.fonts;
 
+import java.io.File;
 import java.net.MalformedURLException;
 import java.util.List;
 import java.util.regex.Pattern;
@@ -58,20 +59,20 @@ public class FontManagerConfigurator {
      * @throws FOPException if an exception occurs while processing the configuration
      */
     public void configure(FontManager fontManager, boolean strict) throws FOPException {
-
         // caching (fonts)
         if (cfg.getChild("use-cache", false) != null) {
             try {
-                fontManager.setUseCache(
-                        cfg.getChild("use-cache").getValueAsBoolean());
+                fontManager.setUseCache(cfg.getChild("use-cache").getValueAsBoolean());
+                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) {
             try {
-                fontManager.setFontBaseURL(
-                        cfg.getChild("font-base").getValue(null));
+                fontManager.setFontBaseURL(cfg.getChild("font-base").getValue(null));
             } catch (MalformedURLException mfue) {
                 LogUtil.handleException(log, mfue, true);
             }
@@ -80,13 +81,12 @@ 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) {
-                FontSubstitutionsConfigurator fontSubstitutionsConfigurator
-                        = new FontSubstitutionsConfigurator(substitutionsCfg);
                 FontSubstitutions substitutions = new FontSubstitutions();
-                fontSubstitutionsConfigurator.configure(substitutions);
+                new FontSubstitutionsConfigurator(substitutionsCfg).configure(substitutions);
                 fontManager.setFontSubstitutions(substitutions);
             }
 

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=985700&r1=985699&r2=985700&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Sun Aug 15 16:15:55 2010
@@ -58,6 +58,12 @@
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Fonts" dev="AC" type="fix">
+        Reinstated support for being able to specify a font cache filepath in the fop user configuration.
+      </action>
+      <action context="Fonts" dev="AC" type="add">
+        Added convenience support for the deletion of the Fop font cache file from the command line.
+      </action>
       <action context="Renderers" dev="JM" type="add" fixes-bug="44460" due-to="Andrejus Chaliapinas">
         Added support for PDF File Attachments (Embedded Files).
       </action>



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


Re: svn commit: r985700 - in /xmlgraphics/fop/trunk: ./ src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/cli/ src/java/org/apache/fop/fonts/

Posted by Adrian Cumiskey <ad...@gmail.com>.
Hi Simon,

Yes now you mention it I can imagine such a use case.  I'll look at changing
the option to "flush-cache" and continue processing.

Adrian.

On 2010-08-16 7:16 PM, "Simon Pepping" <sp...@leverkruid.eu> wrote:

It just occurred to me that a user might want to delete the cache and
process his next files.

And I noticed that only an unknown option and 'mime list' exit, and
now delete-cache.

Simon


On Mon, Aug 16, 2010 at 05:40:37PM +0800, Adrian Cumiskey wrote:
> Hi Simon,
>
> The intent is tha...
--

Simon Pepping
home page: http://www.leverkruid.eu

Re: svn commit: r985700 - in /xmlgraphics/fop/trunk: ./ src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/cli/ src/java/org/apache/fop/fonts/

Posted by Simon Pepping <sp...@leverkruid.eu>.
It just occurred to me that a user might want to delete the cache and
process his next files.

And I noticed that only an unknown option and 'mime list' exit, and
now delete-cache.

Simon

On Mon, Aug 16, 2010 at 05:40:37PM +0800, Adrian Cumiskey wrote:
> Hi Simon,
> 
> The intent is that the user just wishes to remove the cache file and not
> carry out multiple activities at the same time.  So is it desirable to
> continue execution?
> 
> If we do continue executing, there is a small complication in that the user
> configuration is set prior to the deletion to ensure that the correct cache
> file is being deleted.  This would mean that we would need to record that
> the user configuration had already been set so as to not set it again for a
> second time. I'll revisit this again asap.

-- 
Simon Pepping
home page: http://www.leverkruid.eu

Re: svn commit: r985700 - in /xmlgraphics/fop/trunk: ./ src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/cli/ src/java/org/apache/fop/fonts/

Posted by Adrian Cumiskey <ad...@gmail.com>.
Hi Simon,

The intent is that the user just wishes to remove the cache file and not
carry out multiple activities at the same time.  So is it desirable to
continue execution?

If we do continue executing, there is a small complication in that the user
configuration is set prior to the deletion to ensure that the correct cache
file is being deleted.  This would mean that we would need to record that
the user configuration had already been set so as to not set it again for a
second time. I'll revisit this again asap.

Adrian.

On 2010-08-16 2:25 PM, "Simon Pepping" <sp...@leverkruid.eu> wrote:

On Sun, Aug 15, 2010 at 04:15:56PM -0000, acumiskey@apache.org wrote:
...

> + private void parseDeleteCacheOption(String[] args, int i) throws
FOPException {
> + Fo...
Why does FOP exit after the use of this option?

--
Simon Pepping
home page: http://www.leverkruid.eu

Re: svn commit: r985700 - in /xmlgraphics/fop/trunk: ./ src/documentation/content/xdocs/trunk/ src/java/org/apache/fop/apps/ src/java/org/apache/fop/cli/ src/java/org/apache/fop/fonts/

Posted by Simon Pepping <sp...@leverkruid.eu>.
On Sun, Aug 15, 2010 at 04:15:56PM -0000, acumiskey@apache.org wrote:
...
> +    private void parseDeleteCacheOption(String[] args, int i) throws FOPException {
> +        FontManager fontManager = factory.getFontManager();
> +        try {
> +            setUserConfig();
> +            File cacheFile = fontManager.getCacheFile();
> +            if (fontManager.deleteCache()) {
> +                System.out.println("Successfully deleted the font cache file '"
> +                        + cacheFile + "'.");
> +                System.exit(0);
> +            } else {
> +                System.err.println("Failed to delete the font cache file '"
> +                        + cacheFile + "'.");
> +                System.exit(1);
> +            }
> +        } catch (IOException e) {
> +            System.err.println("Failed to delete the font cache file");
> +            System.exit(1);

Why does FOP exit after the use of this option?

-- 
Simon Pepping
home page: http://www.leverkruid.eu