From: Adrian Cumiskey Date: Sun, 15 Aug 2010 16:15:55 +0000 (+0000) Subject: Reinstated support for being able to specify a font cache filepath in the fop user... X-Git-Tag: fop-1_1rc1old~470 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ff3a0b1f92bef5b6384c286a5944d2d5df96fe41;p=xmlgraphics-fop.git 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. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@985700 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/trunk/configuration.xml b/src/documentation/content/xdocs/trunk/configuration.xml index eaa788990..0f4100bf7 100644 --- a/src/documentation/content/xdocs/trunk/configuration.xml +++ b/src/documentation/content/xdocs/trunk/configuration.xml @@ -176,8 +176,7 @@ cache-file String - 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. + 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. ${base}/conf/fop.cache diff --git a/src/documentation/content/xdocs/trunk/running.xml b/src/documentation/content/xdocs/trunk/running.xml index 757e7aaa4..7e98a867c 100644 --- a/src/documentation/content/xdocs/trunk/running.xml +++ b/src/documentation/content/xdocs/trunk/running.xml @@ -132,9 +132,11 @@ Fop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl -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) diff --git a/src/java/org/apache/fop/apps/FopFactoryConfigurator.java b/src/java/org/apache/fop/apps/FopFactoryConfigurator.java index 736ae05d8..e46530177 100644 --- a/src/java/org/apache/fop/apps/FopFactoryConfigurator.java +++ b/src/java/org/apache/fop/apps/FopFactoryConfigurator.java @@ -34,7 +34,6 @@ import org.apache.commons.logging.LogFactory; 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); diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index fb3b54c9c..9a661650b 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -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" diff --git a/src/java/org/apache/fop/fonts/FontCache.java b/src/java/org/apache/fop/fonts/FontCache.java index 9d5eff010..0b71e6294 100644 --- a/src/java/org/apache/fop/fonts/FontCache.java +++ b/src/java/org/apache/fop/fonts/FontCache.java @@ -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 Serializable { /** 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/**/ 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/* */fontfileMap = null; - /** mapping of font url -> file modified date (for all fonts that have failed to load) */ - private Map failedFontMap/**/ = null; + /** + * mapping of font url -> file modified date (for all fonts that have failed + * to load) + */ + private Map failedFontMap/* */= null; /** * Default constructor @@ -100,7 +106,9 @@ public final class FontCache implements Serializable { /** * 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 Serializable { /** * 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 Serializable { /** * 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 Serializable { /** * 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 Serializable { /** * 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 Serializable { /** * 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 Serializable { /** * 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 Serializable { /** * 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 Serializable { return null; } - private Map/**/ getFontFileMap() { + private Map/* */getFontFileMap() { if (fontfileMap == null) { - fontfileMap = new java.util.HashMap/**/(); + fontfileMap = new java.util.HashMap/* */(); } 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 Serializable { /** * 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 Serializable { /** * 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 Serializable { /** * 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 Serializable { /** * 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 Serializable { } } - private Map/**/ getFailedFontMap() { + private Map/* */getFailedFontMap() { if (failedFontMap == null) { - failedFontMap = new java.util.HashMap/**/(); + failedFontMap = new java.util.HashMap/* */(); } return failedFontMap; } @@ -417,7 +463,9 @@ public final class FontCache implements Serializable { /** * 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 Serializable { 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 Serializable { /** file modify date (if available) */ private long lastModified = -1; - private Map/**/ filefontsMap = null; + private Map/* */filefontsMap = null; public CachedFontFile(long lastModified) { setLastModified(lastModified); } - private Map/**/ getFileFontsMap() { + private Map/* */getFileFontsMap() { if (filefontsMap == null) { - filefontsMap = new java.util.HashMap/**/(); + filefontsMap = new java.util.HashMap/* */(); } return filefontsMap; } @@ -465,12 +514,13 @@ public final class FontCache implements Serializable { } 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 Serializable { } /** - * 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; diff --git a/src/java/org/apache/fop/fonts/FontInfoConfigurator.java b/src/java/org/apache/fop/fonts/FontInfoConfigurator.java index e0d52ad43..f8399b110 100644 --- a/src/java/org/apache/fop/fonts/FontInfoConfigurator.java +++ b/src/java/org/apache/fop/fonts/FontInfoConfigurator.java @@ -75,8 +75,8 @@ public class FontInfoConfigurator { * @throws FOPException if an exception occurs while processing the configuration */ public void configure(List/**/ 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 " diff --git a/src/java/org/apache/fop/fonts/FontManager.java b/src/java/org/apache/fop/fonts/FontManager.java index cfce0fd69..f989d2e3a 100644 --- a/src/java/org/apache/fop/fonts/FontManager.java +++ b/src/java/org/apache/fop/fonts/FontManager.java @@ -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); } /** @@ -112,17 +118,32 @@ public class FontManager { return fontSubstitutions; } + /** + * 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; } /** diff --git a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java index 68dd869f5..ecbbf8ec6 100644 --- a/src/java/org/apache/fop/fonts/FontManagerConfigurator.java +++ b/src/java/org/apache/fop/fonts/FontManagerConfigurator.java @@ -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); } diff --git a/status.xml b/status.xml index 146a65ad0..61bf1fc50 100644 --- a/status.xml +++ b/status.xml @@ -58,6 +58,12 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + 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. + Added support for PDF File Attachments (Embedded Files).