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 me...@apache.org on 2012/07/03 11:47:25 UTC
svn commit: r1356646 [3/12] - in /xmlgraphics/fop/trunk: ./
examples/embedding/java/embedding/ examples/embedding/java/embedding/atxml/
examples/embedding/java/embedding/events/
examples/embedding/java/embedding/intermediate/ src/java/org/apache/fop/af...
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FopFactory.java Tue Jul 3 09:46:41 2012
@@ -21,19 +21,13 @@ package org.apache.fop.apps;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
-import java.net.MalformedURLException;
import java.net.URI;
-import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.URIResolver;
-
import org.xml.sax.SAXException;
import org.apache.avalon.framework.configuration.Configuration;
@@ -44,13 +38,15 @@ import org.apache.xmlgraphics.image.load
import org.apache.xmlgraphics.image.loader.ImageManager;
import org.apache.xmlgraphics.util.UnitConv;
+import org.apache.fop.apps.io.InternalResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.ElementMappingRegistry;
-import org.apache.fop.fonts.FontCache;
import org.apache.fop.fonts.FontManager;
-import org.apache.fop.hyphenation.HyphenationTreeResolver;
import org.apache.fop.layoutmgr.LayoutManagerMaker;
import org.apache.fop.render.ImageHandlerRegistry;
+import org.apache.fop.render.RendererConfig;
+import org.apache.fop.render.RendererConfig.RendererConfigParser;
import org.apache.fop.render.RendererFactory;
import org.apache.fop.render.XMLHandlerRegistry;
import org.apache.fop.util.ColorSpaceCache;
@@ -59,57 +55,49 @@ import org.apache.fop.util.ContentHandle
/**
* Factory class which instantiates new Fop and FOUserAgent instances. This
* class also holds environmental information and configuration used by FOP.
- * Information that may potentially be different for each rendering run can be
+ * Information that may potentially be different for each renderingq run can be
* found and managed in the FOUserAgent.
*/
-public class FopFactory implements ImageContext {
+public final class FopFactory implements ImageContext {
/** logger instance */
private static Log log = LogFactory.getLog(FopFactory.class);
/** Factory for Renderers and FOEventHandlers */
- private RendererFactory rendererFactory;
+ private final RendererFactory rendererFactory;
/** Registry for XML handlers */
- private XMLHandlerRegistry xmlHandlers;
+ private final XMLHandlerRegistry xmlHandlers;
/** Registry for image handlers */
- private ImageHandlerRegistry imageHandlers;
+ private final ImageHandlerRegistry imageHandlers;
/** The registry for ElementMapping instances */
- private ElementMappingRegistry elementMappingRegistry;
+ private final ElementMappingRegistry elementMappingRegistry;
/** The registry for ContentHandlerFactory instance */
- private ContentHandlerFactoryRegistry contentHandlerFactoryRegistry
- = new ContentHandlerFactoryRegistry();
-
- /** The resolver for user-supplied hyphenation patterns */
- private HyphenationTreeResolver hyphResolver = null;
+ private final ContentHandlerFactoryRegistry contentHandlerFactoryRegistry
+ = new ContentHandlerFactoryRegistry();
- private ColorSpaceCache colorSpaceCache = null;
+ private final ColorSpaceCache colorSpaceCache;
- /** Image manager for loading and caching image objects */
- private ImageManager imageManager;
+ private final FopFactoryConfig config;
- /** Font manager for font substitution, autodetection and caching **/
- private FontManager fontManager;
+ private final InternalResourceResolver resolver;
- /** Configuration layer used to configure fop */
- private FopFactoryConfigurator config = null;
+ private final Map<String, RendererConfig> rendererConfig;
- /**
- * The base URL for all URL resolutions, especially for
- * external-graphics.
- */
- private String base = null;
-
- /**
- * Controls if accessibility is turned on or off
- */
- private boolean accessibility = false;
-
- /** The base URL for all hyphen URL resolutions. */
- private String hyphenBase = null;
+ private FopFactory(FopFactoryConfig config) {
+ this.config = config;
+ this.resolver = ResourceResolverFactory.createInternalResourceResolver(config.getBaseURI(),
+ config.getResourceResolver());
+ this.elementMappingRegistry = new ElementMappingRegistry(this);
+ this.colorSpaceCache = new ColorSpaceCache(resolver);
+ this.rendererFactory = new RendererFactory(config.preferRenderer());
+ this.xmlHandlers = new XMLHandlerRegistry();
+ this.imageHandlers = new ImageHandlerRegistry();
+ rendererConfig = new HashMap<String, RendererConfig>();
+ }
/**
* Map of configured names of hyphenation pattern file names: ll_CC => name
@@ -121,73 +109,52 @@ public class FopFactory implements Image
* input XSL violates that FO's content model. This is the default
* behavior for FOP. However, this flag, if set, provides the user the
* ability for FOP to halt on all content model violations if desired.
+ * Returns a new FopFactory instance that is configured using the {@link FopFactoryConfig} object.
+ *
+ * @param config the fop configuration
+ * @return the requested FopFactory instance.
*/
- private boolean strictFOValidation = FopFactoryConfigurator.DEFAULT_STRICT_FO_VALIDATION;
+ public static FopFactory newInstance(FopFactoryConfig config) {
+ return new FopFactory(config);
+ }
/**
- * FOP will validate the contents of the user configuration strictly
- * (e.g. base-urls and font urls/paths).
+ * Returns a new FopFactory instance that is configured using the {@link FopFactoryConfig} object that
+ * is created when the fopConf is parsed.
+ *
+ * @param fopConf the fop conf configuration file to parse
+ * @return the requested FopFactory instance.
+ * @throws IOException
+ * @throws SAXException
*/
- private boolean strictUserConfigValidation
- = FopFactoryConfigurator.DEFAULT_STRICT_USERCONFIG_VALIDATION;
-
- /** Source resolution in dpi */
- private float sourceResolution = FopFactoryConfigurator.DEFAULT_SOURCE_RESOLUTION;
-
- /** Target resolution in dpi */
- private float targetResolution = FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
-
- /** Page height */
- private String pageHeight = FopFactoryConfigurator.DEFAULT_PAGE_HEIGHT;
-
- /** Page width */
- private String pageWidth = FopFactoryConfigurator.DEFAULT_PAGE_WIDTH;
-
- /** Complex scripts support enabled */
- private boolean useComplexScriptFeatures
- = FopFactoryConfigurator.DEFAULT_COMPLEX_SCRIPT_FEATURES;
-
- /** @see #setBreakIndentInheritanceOnReferenceAreaBoundary(boolean) */
- private boolean breakIndentInheritanceOnReferenceAreaBoundary
- = FopFactoryConfigurator.DEFAULT_BREAK_INDENT_INHERITANCE;
-
- /** Optional overriding LayoutManagerMaker */
- private LayoutManagerMaker lmMakerOverride = null;
-
- private Set<String> ignoredNamespaces;
-
- private FOURIResolver foURIResolver;
+ public static FopFactory newInstance(File fopConf) throws SAXException, IOException {
+ return new FopConfParser(fopConf).getFopFactoryBuilder().build();
+ }
/**
- * Main constructor.
+ * Returns a new FopFactory instance that is configured only by the default configuration
+ * parameters.
+ *
+ * @param baseURI the base URI to resolve resource URIs against
+ * @return the requested FopFactory instance.
*/
- protected FopFactory() {
- this.config = new FopFactoryConfigurator(this);
- this.elementMappingRegistry = new ElementMappingRegistry(this);
- this.foURIResolver = new FOURIResolver(validateUserConfigStrictly());
- this.fontManager = new FontManager() {
-
- /** {@inheritDoc} */
- @Override
- public void setFontBaseURL(String fontBase) throws MalformedURLException {
- super.setFontBaseURL(getFOURIResolver().checkBaseURL(fontBase));
- }
-
- };
- this.colorSpaceCache = new ColorSpaceCache(foURIResolver);
- this.imageManager = new ImageManager(this);
- this.rendererFactory = new RendererFactory();
- this.xmlHandlers = new XMLHandlerRegistry();
- this.imageHandlers = new ImageHandlerRegistry();
- this.ignoredNamespaces = new java.util.HashSet<String>();
+ public static FopFactory newInstance(URI baseURI) {
+ return new FopFactoryBuilder(baseURI).build();
}
/**
- * Returns a new FopFactory instance.
+ * Returns a new FopFactory instance that is configured using the {@link FopFactoryConfig} object that
+ * is created when the fopConf is parsed.
+ *
+ * @param baseURI the base URI to resolve resource URIs against
+ * @param confStream the fop conf configuration stream to parse
* @return the requested FopFactory instance.
+ * @throws SAXException
+ * @throws IOException
*/
- public static FopFactory newInstance() {
- return new FopFactory();
+ public static FopFactory newInstance(URI baseURI, InputStream confStream) throws SAXException,
+ IOException {
+ return new FopConfParser(confStream, baseURI).getFopFactoryBuilder().build();
}
/**
@@ -198,34 +165,12 @@ public class FopFactory implements Image
* @throws FOPException
*/
public FOUserAgent newFOUserAgent() {
- FOUserAgent userAgent = new FOUserAgent(this);
+ FOUserAgent userAgent = new FOUserAgent(this, resolver);
return userAgent;
}
- /**
- * Sets accessibility support.
- *
- * @param value <code>true</code> to enable accessibility, <code>false</code> otherwise
- */
- void setAccessibility(boolean value) {
- this.accessibility = value;
- }
-
- boolean isAccessibilityEnabled() {
- return accessibility;
- }
-
- /**
- * Sets complex script support.
- * @param value <code>true</code> to enable complex script features,
- * <code>false</code> otherwise
- */
- void setComplexScriptFeaturesEnabled(boolean value) {
- this.useComplexScriptFeatures = value;
- }
-
boolean isComplexScriptFeaturesEnabled() {
- return useComplexScriptFeatures;
+ return config.isComplexScriptFeaturesEnabled();
}
/**
@@ -239,7 +184,7 @@ public class FopFactory implements Image
* @throws FOPException when the constructor fails
*/
public Fop newFop(String outputFormat) throws FOPException {
- return newFop(outputFormat, newFOUserAgent());
+ return newFOUserAgent().newFop(outputFormat);
}
/**
@@ -256,7 +201,7 @@ public class FopFactory implements Image
* @throws FOPException when the constructor fails
*/
public Fop newFop(String outputFormat, FOUserAgent userAgent) throws FOPException {
- return newFop(outputFormat, userAgent, null);
+ return userAgent.newFop(outputFormat, null);
}
/**
@@ -271,7 +216,7 @@ public class FopFactory implements Image
* @throws FOPException when the constructor fails
*/
public Fop newFop(String outputFormat, OutputStream stream) throws FOPException {
- return newFop(outputFormat, newFOUserAgent(), stream);
+ return newFOUserAgent().newFop(outputFormat, stream);
}
/**
@@ -290,11 +235,8 @@ public class FopFactory implements Image
* @throws FOPException when the constructor fails
*/
public Fop newFop(String outputFormat, FOUserAgent userAgent, OutputStream stream)
- throws FOPException {
- if (userAgent == null) {
- throw new NullPointerException("The userAgent parameter must not be null!");
- }
- return new Fop(outputFormat, userAgent, stream);
+ throws FOPException {
+ return userAgent.newFop(outputFormat, stream);
}
/**
@@ -343,11 +285,28 @@ public class FopFactory implements Image
}
/**
- * Returns the image manager.
- * @return the image manager
- */
- public ImageManager getImageManager() {
- return this.imageManager;
+ * Returns the renderer configuration object for a specific renderer given the parser and
+ * configuration to read. The renderer config is cached such that the {@link Configuration} is
+ * only parsed once per renderer, per FopFactory instance.
+ *
+ * @param userAgent the user agent
+ * @param cfg the configuration to be parsed
+ * @param configCreator the parser that creates the config object
+ * @return the config object
+ * @throws FOPException when an error occurs while creating the configuration object
+ */
+ public RendererConfig getRendererConfig(FOUserAgent userAgent, Configuration cfg,
+ RendererConfigParser configCreator) throws FOPException {
+ RendererConfig config = rendererConfig.get(configCreator.getMimeType());
+ if (config == null) {
+ try {
+ config = configCreator.build(userAgent, cfg);
+ rendererConfig.put(configCreator.getMimeType(), config);
+ } catch (Exception e) {
+ throw new FOPException(e);
+ }
+ }
+ return config;
}
/**
@@ -359,143 +318,32 @@ public class FopFactory implements Image
}
/**
- * Sets an explicit LayoutManagerMaker instance which overrides the one
- * defined by the AreaTreeHandler.
- * @param lmMaker the LayoutManagerMaker instance
- */
- public void setLayoutManagerMakerOverride(LayoutManagerMaker lmMaker) {
- this.lmMakerOverride = lmMaker;
- }
-
- /**
- * Returns the overriding LayoutManagerMaker instance, if any.
- * @return the overriding LayoutManagerMaker or null
- */
- public LayoutManagerMaker getLayoutManagerMakerOverride() {
- return this.lmMakerOverride;
- }
-
- /**
- * Sets the base URL.
- * @param base the base URL
- * @throws MalformedURLException if there's a problem with a file URL
- */
- public void setBaseURL(String base) throws MalformedURLException {
- this.base = foURIResolver.checkBaseURL(base);
- }
-
- /**
- * Returns the base URL.
- * @return the base URL
- */
- public String getBaseURL() {
- return this.base;
- }
-
- /**
- * Sets the font base URL.
- * @param fontBase font base URL
- * @throws MalformedURLException if there's a problem with a file URL
- * @deprecated use getFontManager().setFontBaseURL(fontBase) instead
- */
- @Deprecated
- public void setFontBaseURL(String fontBase) throws MalformedURLException {
- getFontManager().setFontBaseURL(fontBase);
- }
-
- /**
- * @return the font base URL
- * @deprecated use getFontManager().setFontBaseURL(fontBase) instead
- */
- @Deprecated
- public String getFontBaseURL() {
- return getFontManager().getFontBaseURL();
- }
-
- /** @return the hyphen base URL */
- public String getHyphenBaseURL() {
- return this.hyphenBase;
- }
-
- /**
- * Sets the hyphen base URL.
- * @param hyphenBase hythen base URL
- * @throws MalformedURLException if there's a problem with a file URL
- * */
- public void setHyphenBaseURL(final String hyphenBase) throws MalformedURLException {
- if (hyphenBase != null) {
- setHyphenationTreeResolver(
- new HyphenationTreeResolver() {
- public Source resolve(String href) {
- return resolveURI(href, hyphenBase);
- }
- });
- }
- this.hyphenBase = foURIResolver.checkBaseURL(hyphenBase);
- }
-
- /**
- * @return the hyphPatNames
- */
- public Map getHyphPatNames() {
- return hyphPatNames;
- }
-
- /**
- * @param hyphPatNames the hyphPatNames to set
- */
- public void setHyphPatNames(Map hyphPatNames) {
- if (hyphPatNames == null) {
- hyphPatNames = new HashMap();
- }
- this.hyphPatNames = hyphPatNames;
- }
-
- /**
- * Sets the URI Resolver. It is used for resolving factory-level URIs like hyphenation
- * patterns and as backup for URI resolution performed during a rendering run.
- * @param uriResolver the new URI resolver
+ * Returns whether accessibility is enabled.
+ * @return true if accessibility is enabled
*/
- public void setURIResolver(URIResolver uriResolver) {
- foURIResolver.setCustomURIResolver(uriResolver);
+ boolean isAccessibilityEnabled() {
+ return config.isAccessibilityEnabled();
}
/**
- * Returns the URI Resolver.
- * @return the URI Resolver
+ * Returns the image manager.
+ * @return the image manager
*/
- public URIResolver getURIResolver() {
- return foURIResolver;
+ public ImageManager getImageManager() {
+ return config.getImageManager();
}
/**
- * Returns the FO URI Resolver.
- * @return the FO URI Resolver
+ * Returns the overriding LayoutManagerMaker instance, if any.
+ * @return the overriding LayoutManagerMaker or null
*/
- public FOURIResolver getFOURIResolver() {
- return foURIResolver;
+ public LayoutManagerMaker getLayoutManagerMakerOverride() {
+ return config.getLayoutManagerMakerOverride();
}
- /** @return the HyphenationTreeResolver for resolving user-supplied hyphenation patterns. */
- public HyphenationTreeResolver getHyphenationTreeResolver() {
- return this.hyphResolver;
- }
- /**
- * Sets the HyphenationTreeResolver to be used for resolving user-supplied hyphenation files.
- * @param hyphResolver the HyphenationTreeResolver instance
- */
- public void setHyphenationTreeResolver(HyphenationTreeResolver hyphResolver) {
- this.hyphResolver = hyphResolver;
- }
-
- /**
- * Activates strict XSL content model validation for FOP
- * Default is false (FOP will continue processing where it can)
- * @param validateStrictly true to turn on strict validation
- */
- public void setStrictValidation(boolean validateStrictly) {
- this.strictFOValidation = validateStrictly;
+ public Map<String, String> getHyphPatNames() {
+ return config.getHyphPatNames();
}
/**
@@ -503,7 +351,7 @@ public class FopFactory implements Image
* @return true of strict validation turned on, false otherwise
*/
public boolean validateStrictly() {
- return strictFOValidation;
+ return config.validateStrictly();
}
/**
@@ -511,48 +359,12 @@ public class FopFactory implements Image
* boundaries (for more info, see the javadoc for the relative member variable)
*/
public boolean isBreakIndentInheritanceOnReferenceAreaBoundary() {
- return breakIndentInheritanceOnReferenceAreaBoundary;
- }
-
- /**
- * Controls whether to enable a feature that breaks indent inheritance when crossing
- * reference area boundaries.
- * <p>
- * This flag controls whether FOP will enable special code that breaks property
- * inheritance for start-indent and end-indent when the evaluation of the inherited
- * value would cross a reference area. This is described under
- * http://wiki.apache.org/xmlgraphics-fop/IndentInheritance as is intended to
- * improve interoperability with commercial FO implementations and to produce
- * results that are more in line with the expectation of unexperienced FO users.
- * Note: Enabling this features violates the XSL specification!
- * @param value true to enable the feature
- */
- public void setBreakIndentInheritanceOnReferenceAreaBoundary(boolean value) {
- this.breakIndentInheritanceOnReferenceAreaBoundary = value;
+ return config.isBreakIndentInheritanceOnReferenceAreaBoundary();
}
- /**
- * @return true if kerning on base 14 fonts is enabled
- * @deprecated use getFontManager().isBase14KerningEnabled() instead
- */
- @Deprecated
- public boolean isBase14KerningEnabled() {
- return getFontManager().isBase14KerningEnabled();
- }
-
- /**
- * Controls whether kerning is activated on base 14 fonts.
- * @param value true if kerning should be activated
- * @deprecated use getFontManager().setBase14KerningEnabled(boolean) instead
- */
- @Deprecated
- public void setBase14KerningEnabled(boolean value) {
- getFontManager().setBase14KerningEnabled(value);
- }
-
- /** @return the resolution for resolution-dependant input */
+ /** @return the resolution for resolution-dependent input */
public float getSourceResolution() {
- return this.sourceResolution;
+ return config.getSourceResolution();
}
/**
@@ -565,22 +377,9 @@ public class FopFactory implements Image
return UnitConv.IN2MM / getSourceResolution();
}
- /**
- * Sets the source resolution in dpi. This value is used to interpret the pixel size
- * of source documents like SVG images and bitmap images without resolution information.
- * @param dpi resolution in dpi
- */
- public void setSourceResolution(float dpi) {
- this.sourceResolution = dpi;
- if (log.isDebugEnabled()) {
- log.debug("source-resolution set to: " + sourceResolution
- + "dpi (px2mm=" + getSourcePixelUnitToMillimeter() + ")");
- }
- }
-
/** @return the resolution for resolution-dependant output */
public float getTargetResolution() {
- return this.targetResolution;
+ return config.getTargetResolution();
}
/**
@@ -590,25 +389,7 @@ public class FopFactory implements Image
* @see #getTargetResolution()
*/
public float getTargetPixelUnitToMillimeter() {
- return UnitConv.IN2MM / this.targetResolution;
- }
-
- /**
- * Sets the source resolution in dpi. This value is used to interpret the pixel size
- * of source documents like SVG images and bitmap images without resolution information.
- * @param dpi resolution in dpi
- */
- public void setTargetResolution(float dpi) {
- this.targetResolution = dpi;
- }
-
- /**
- * Sets the source resolution in dpi. This value is used to interpret the pixel size
- * of source documents like SVG images and bitmap images without resolution information.
- * @param dpi resolution in dpi
- */
- public void setSourceResolution(int dpi) {
- setSourceResolution((float)dpi);
+ return 25.4f / getTargetResolution();
}
/**
@@ -618,20 +399,7 @@ public class FopFactory implements Image
* @return the page-height, as a String
*/
public String getPageHeight() {
- return this.pageHeight;
- }
-
- /**
- * Sets the page-height to use as fallback, in case
- * page-height="auto"
- *
- * @param pageHeight page-height as a String
- */
- public void setPageHeight(String pageHeight) {
- this.pageHeight = pageHeight;
- if (log.isDebugEnabled()) {
- log.debug("Default page-height set to: " + pageHeight);
- }
+ return config.getPageHeight();
}
/**
@@ -641,40 +409,7 @@ public class FopFactory implements Image
* @return the page-width, as a String
*/
public String getPageWidth() {
- return this.pageWidth;
- }
-
- /**
- * Sets the page-width to use as fallback, in case
- * page-width="auto"
- *
- * @param pageWidth page-width as a String
- */
- public void setPageWidth(String pageWidth) {
- this.pageWidth = pageWidth;
- if (log.isDebugEnabled()) {
- log.debug("Default page-width set to: " + pageWidth);
- }
- }
-
- /**
- * Adds a namespace to the set of ignored namespaces.
- * If FOP encounters a namespace which it cannot handle, it issues a warning except if this
- * namespace is in the ignored set.
- * @param namespaceURI the namespace URI
- */
- public void ignoreNamespace(String namespaceURI) {
- this.ignoredNamespaces.add(namespaceURI);
- }
-
- /**
- * Adds a collection of namespaces to the set of ignored namespaces.
- * If FOP encounters a namespace which it cannot handle, it issues a warning except if this
- * namespace is in the ignored set.
- * @param namespaceURIs the namespace URIs
- */
- public void ignoreNamespaces(Collection<String> namespaceURIs) {
- this.ignoredNamespaces.addAll(namespaceURIs);
+ return config.getPageWidth();
}
/**
@@ -683,55 +418,17 @@ public class FopFactory implements Image
* @return true if the namespace is ignored by FOP
*/
public boolean isNamespaceIgnored(String namespaceURI) {
- return this.ignoredNamespaces.contains(namespaceURI);
+ return config.isNamespaceIgnored(namespaceURI);
}
/** @return the set of namespaces that are ignored by FOP */
public Set<String> getIgnoredNamespace() {
- return Collections.unmodifiableSet(this.ignoredNamespaces);
+ return config.getIgnoredNamespaces();
}
//------------------------------------------- Configuration stuff
/**
- * Set the user configuration.
- * @param userConfigFile the configuration file
- * @throws IOException if an I/O error occurs
- * @throws SAXException if a parsing error occurs
- */
- public void setUserConfig(File userConfigFile) throws SAXException, IOException {
- config.setUserConfig(userConfigFile);
- }
-
- /**
- * Set the user configuration from an URI.
- * @param uri the URI to the configuration file
- * @throws IOException if an I/O error occurs
- * @throws SAXException if a parsing error occurs
- */
- public void setUserConfig(String uri) throws SAXException, IOException {
- config.setUserConfig(uri);
- }
-
- /**
- * Set the user configuration.
- * @param userConfig configuration
- * @throws FOPException if a configuration problem occurs
- */
- public void setUserConfig(Configuration userConfig) throws FOPException {
- config.setUserConfig(userConfig);
- }
-
- /**
- * Set the base URI for the user configuration
- * Useful for programmatic configurations
- * @param baseURI the base URI
- */
- public void setUserConfigBaseURI(URI baseURI) {
- config.setBaseURI(baseURI);
- }
-
- /**
* Get the user configuration.
* @return the user configuration
*/
@@ -741,79 +438,20 @@ public class FopFactory implements Image
/**
* Is the user configuration to be validated?
- * @param strictUserConfigValidation strict user config validation
- */
- public void setStrictUserConfigValidation(boolean strictUserConfigValidation) {
- this.strictUserConfigValidation = strictUserConfigValidation;
- this.foURIResolver.setThrowExceptions(strictUserConfigValidation);
- }
-
- /**
- * Is the user configuration to be validated?
* @return if the user configuration should be validated
*/
public boolean validateUserConfigStrictly() {
- return this.strictUserConfigValidation;
+ return config.validateUserConfigStrictly();
}
//------------------------------------------- Font related stuff
/**
- * Whether or not to cache results of font triplet detection/auto-config
- * @param useCache use cache or not
- * @deprecated use getFontManager().setUseCache(boolean) instead
- */
- @Deprecated
- public void setUseCache(boolean useCache) {
- getFontManager().setUseCache(useCache);
- }
-
- /**
- * Cache results of font triplet detection/auto-config?
- * @return whether this factory is uses the cache
- * @deprecated use getFontManager().useCache() instead
- */
- @Deprecated
- public boolean useCache() {
- return getFontManager().useCache();
- }
-
- /**
- * Returns the font cache instance used by this factory.
- * @return the font cache
- * @deprecated use getFontManager().getFontCache() instead
- */
- @Deprecated
- public FontCache getFontCache() {
- return getFontManager().getFontCache();
- }
-
- /**
* Returns the font manager.
* @return the font manager
*/
public FontManager getFontManager() {
- return this.fontManager;
- }
-
- /**
- * Attempts to resolve the given URI.
- * Will use the configured resolver and if not successful fall back
- * to the default resolver.
- * @param href URI to access
- * @param baseUri the base URI to resolve against
- * @return A {@link javax.xml.transform.Source} object, or null if the URI
- * cannot be resolved.
- * @see org.apache.fop.apps.FOURIResolver
- */
- public Source resolveURI(String href, String baseUri) {
- Source source = null;
- try {
- source = foURIResolver.resolve(href, baseUri);
- } catch (TransformerException e) {
- log.error("Attempt to resolve URI '" + href + "' failed: ", e);
- }
- return source;
+ return config.getFontManager();
}
/**
@@ -825,5 +463,4 @@ public class FopFactory implements Image
public ColorSpaceCache getColorSpaceCache() {
return this.colorSpaceCache;
}
-
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/MimeConstants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/MimeConstants.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/MimeConstants.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/MimeConstants.java Tue Jul 3 09:46:41 2012
@@ -32,4 +32,6 @@ public interface MimeConstants extends o
String MIME_FOP_AREA_TREE = "application/X-fop-areatree";
/** Apache FOP's intermediate format XML */
String MIME_FOP_IF = "application/X-fop-intermediate-format";
+ /** Bitmap images */
+ String MIME_BITMAP = "image/x-bitmap";
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeHandler.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeHandler.java Tue Jul 3 09:46:41 2012
@@ -104,7 +104,7 @@ public class AreaTreeHandler extends FOE
setupModel(userAgent, outputFormat, stream);
- this.lmMaker = userAgent.getFactory().getLayoutManagerMakerOverride();
+ this.lmMaker = userAgent.getLayoutManagerMakerOverride();
if (lmMaker == null) {
lmMaker = new LayoutManagerMapping();
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/AreaTreeParser.java Tue Jul 3 09:46:41 2012
@@ -132,7 +132,7 @@ public class AreaTreeParser {
*/
public ContentHandler getContentHandler(AreaTreeModel treeModel, FOUserAgent userAgent) {
ElementMappingRegistry elementMappingRegistry
- = userAgent.getFactory().getElementMappingRegistry();
+ = userAgent.getElementMappingRegistry();
return new Handler(treeModel, userAgent, elementMappingRegistry);
}
@@ -292,7 +292,7 @@ public class AreaTreeParser {
}
} else {
ContentHandlerFactoryRegistry registry
- = userAgent.getFactory().getContentHandlerFactoryRegistry();
+ = userAgent.getContentHandlerFactoryRegistry();
ContentHandlerFactory factory = registry.getFactory(uri);
if (factory != null) {
delegate = factory.createContentHandler();
@@ -1102,7 +1102,7 @@ public class AreaTreeParser {
bkg.setURL(uri);
try {
- ImageManager manager = userAgent.getFactory().getImageManager();
+ ImageManager manager = userAgent.getImageManager();
ImageSessionContext sessionContext
= userAgent.getImageSessionContext();
ImageInfo info = manager.getImageInfo(uri, sessionContext);
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/CachedRenderPagesModel.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/CachedRenderPagesModel.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/CachedRenderPagesModel.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/CachedRenderPagesModel.java Tue Jul 3 09:46:41 2012
@@ -21,13 +21,12 @@ package org.apache.fop.area;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
+import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -36,9 +35,9 @@ import org.xml.sax.SAXException;
import org.apache.commons.io.IOUtils;
-import org.apache.fop.ResourceEventProducer;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.io.TempResourceURIGenerator;
import org.apache.fop.fonts.FontInfo;
/**
@@ -49,10 +48,12 @@ import org.apache.fop.fonts.FontInfo;
*/
public class CachedRenderPagesModel extends RenderPagesModel {
- private Map<PageViewport, String> pageMap = new HashMap<PageViewport, String>();
+ private Map<PageViewport, URI> pageMap = new HashMap<PageViewport, URI>();
/** Base directory to save temporary file in, typically points to the user's temp dir. */
- protected File baseDir;
+ private final URI tempBaseURI;
+ private static final TempResourceURIGenerator TEMP_URI_GENERATOR
+ = new TempResourceURIGenerator("cached-pages");
/**
* Main Constructor
@@ -65,8 +66,7 @@ public class CachedRenderPagesModel exte
public CachedRenderPagesModel (FOUserAgent userAgent, String outputFormat,
FontInfo fontInfo, OutputStream stream) throws FOPException {
super(userAgent, outputFormat, fontInfo, stream);
- //TODO: Avoid System.getProperty()?
- this.baseDir = new File(System.getProperty("java.io.tmpdir"));
+ tempBaseURI = TEMP_URI_GENERATOR.generate();
}
/** {@inheritDoc} */
@@ -78,27 +78,19 @@ public class CachedRenderPagesModel exte
if (pageViewport != newpage) {
try {
// load page from cache
- String name = pageMap.get(pageViewport);
- File tempFile = new File(baseDir, name);
- log.debug("Loading page from: " + tempFile);
- ObjectInputStream in = new ObjectInputStream(
- new BufferedInputStream(
- new FileInputStream(tempFile)));
+ URI tempURI = pageMap.get(pageViewport);
+ log.debug("Loading page from: " + tempURI);
+ InputStream inStream = renderer.getUserAgent().getResourceResolver().getResource(tempURI);
+ ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(inStream));
try {
pageViewport.loadPage(in);
} finally {
+ IOUtils.closeQuietly(inStream);
IOUtils.closeQuietly(in);
}
- if (!tempFile.delete()) {
- ResourceEventProducer eventProducer
- = ResourceEventProducer.Provider.get(
- renderer.getUserAgent().getEventBroadcaster());
- eventProducer.cannotDeleteTempFile(this, tempFile);
- }
pageMap.remove(pageViewport);
} catch (Exception e) {
- AreaEventProducer eventProducer
- = AreaEventProducer.Provider.get(
+ AreaEventProducer eventProducer = AreaEventProducer.Provider.get(
renderer.getUserAgent().getEventBroadcaster());
eventProducer.pageLoadError(this, pageViewport.getPageNumberString(), e);
}
@@ -131,18 +123,17 @@ public class CachedRenderPagesModel exte
// save page to cache
ObjectOutputStream tempstream;
String fname = "fop-page-" + page.getPageIndex() + ".ser";
- File tempFile = new File(baseDir, fname);
- tempFile.deleteOnExit();
- tempstream = new ObjectOutputStream(new BufferedOutputStream(
- new FileOutputStream(tempFile)));
+ URI tempURI = tempBaseURI.resolve(fname);
+ OutputStream outStream = renderer.getUserAgent().getResourceResolver().getOutputStream(tempURI);
+ tempstream = new ObjectOutputStream(new BufferedOutputStream(outStream));
try {
page.savePage(tempstream);
} finally {
IOUtils.closeQuietly(tempstream);
}
- pageMap.put(page, fname);
+ pageMap.put(page, tempURI);
if (log.isDebugEnabled()) {
- log.debug("Page saved to temporary file: " + tempFile);
+ log.debug("Page saved to temporary file: " + tempURI);
}
} catch (IOException ioe) {
AreaEventProducer eventProducer
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=1356646&r1=1356645&r2=1356646&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 Tue Jul 3 09:46:41 2012
@@ -39,9 +39,10 @@ import org.apache.fop.Version;
import org.apache.fop.accessibility.Accessibility;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopConfParser;
import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.FopFactoryBuilder;
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;
@@ -51,7 +52,7 @@ import org.apache.fop.render.awt.AWTRend
import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFSerializer;
-import org.apache.fop.render.pdf.PDFConfigurationConstants;
+import org.apache.fop.render.pdf.PDFEncryptionOption;
import org.apache.fop.render.print.PagesMode;
import org.apache.fop.render.print.PrintRenderer;
import org.apache.fop.render.xml.XMLRenderer;
@@ -116,12 +117,14 @@ public class CommandLineOptions {
private Map renderingOptions = new java.util.HashMap();
/* target resolution (for the user agent) */
private int targetResolution = 0;
+
+ private boolean strictValidation = true;
/* control memory-conservation policy */
private boolean conserveMemoryPolicy = false;
/* true if a complex script features are enabled */
private boolean useComplexScriptFeatures = true;
- private FopFactory factory = FopFactory.newInstance();
+ private FopFactory factory;
private FOUserAgent foUserAgent;
private InputHandler inputHandler;
@@ -183,9 +186,10 @@ public class CommandLineOptions {
addXSLTParameter("fop-output-format", getOutputFormat());
addXSLTParameter("fop-version", Version.getVersion());
foUserAgent.setConserveMemoryPolicy(conserveMemoryPolicy);
- if (!useComplexScriptFeatures) {
- foUserAgent.setComplexScriptFeaturesEnabled(false);
- }
+ // TODO: Handle this!!
+ //if (!useComplexScriptFeatures) {
+ // foUserAgent.setComplexScriptFeaturesEnabled(false);
+ //}
} else {
return false;
}
@@ -225,9 +229,7 @@ public class CommandLineOptions {
} else if (MimeConstants.MIME_FOP_IF.equals(outputmode)
&& mimicRenderer != null) {
// render from FO to Intermediate Format
- IFSerializer serializer = new IFSerializer();
- serializer.setContext(new IFContext(foUserAgent));
-
+ IFSerializer serializer = new IFSerializer(new IFContext(foUserAgent));
IFDocumentHandler targetHandler
= foUserAgent.getRendererFactory().createDocumentHandler(
foUserAgent, mimicRenderer);
@@ -288,7 +290,7 @@ public class CommandLineOptions {
} else if (args[i].equals("-d")) {
setLogOption("debug", "debug");
} else if (args[i].equals("-r")) {
- factory.setStrictValidation(false);
+ strictValidation = false;
} else if (args[i].equals("-conserve")) {
conserveMemoryPolicy = true;
} else if (args[i].equals("-flush")) {
@@ -819,15 +821,14 @@ public class CommandLineOptions {
}
private PDFEncryptionParams getPDFEncryptionParams() throws FOPException {
- PDFEncryptionParams params = (PDFEncryptionParams)renderingOptions.get(
- PDFConfigurationConstants.ENCRYPTION_PARAMS);
+ PDFEncryptionParams params = (PDFEncryptionParams) renderingOptions.get(PDFEncryptionOption.ENCRYPTION_PARAMS);
if (params == null) {
if (!PDFEncryptionManager.checkAvailableAlgorithms()) {
throw new FOPException("PDF encryption requested but it is not available."
+ " Please make sure MD5 and RC4 algorithms are available.");
}
params = new PDFEncryptionParams();
- renderingOptions.put(PDFConfigurationConstants.ENCRYPTION_PARAMS, params);
+ renderingOptions.put(PDFEncryptionOption.ENCRYPTION_PARAMS, params);
}
return params;
}
@@ -860,7 +861,7 @@ public class CommandLineOptions {
throw new FOPException("You must specify a PDF profile");
} else {
String profile = args[i + 1];
- PDFAMode pdfAMode = PDFAMode.valueOf(profile);
+ PDFAMode pdfAMode = PDFAMode.getValueOf(profile);
if (pdfAMode != null && pdfAMode != PDFAMode.DISABLED) {
if (renderingOptions.get("pdf-a-mode") != null) {
throw new FOPException("PDF/A mode already set");
@@ -868,7 +869,7 @@ public class CommandLineOptions {
renderingOptions.put("pdf-a-mode", pdfAMode.getName());
return 1;
} else {
- PDFXMode pdfXMode = PDFXMode.valueOf(profile);
+ PDFXMode pdfXMode = PDFXMode.getValueOf(profile);
if (pdfXMode != null && pdfXMode != PDFXMode.DISABLED) {
if (renderingOptions.get("pdf-x-mode") != null) {
throw new FOPException("PDF/X mode already set");
@@ -1027,14 +1028,18 @@ public class CommandLineOptions {
* @throws IOException
*/
private void setUserConfig() throws FOPException, IOException {
+ FopFactoryBuilder fopFactoryBuilder;
if (userConfigFile == null) {
- return;
- }
- try {
- factory.setUserConfig(userConfigFile);
- } catch (SAXException e) {
- throw new FOPException(e);
+ fopFactoryBuilder = new FopFactoryBuilder(new File(".").toURI());
+ } else {
+ try {
+ fopFactoryBuilder = new FopConfParser(userConfigFile).getFopFactoryBuilder();
+ } catch (SAXException e) {
+ throw new FOPException(e);
+ }
+ fopFactoryBuilder.setStrictFOValidation(strictValidation);
}
+ factory = fopFactoryBuilder.build();
}
/**
@@ -1390,13 +1395,7 @@ public class CommandLineOptions {
}
private void flushCache() throws FOPException {
- FontManager fontManager = factory.getFontManager();
- File cacheFile = fontManager.getCacheFile();
- if (!fontManager.deleteCache()) {
- System.err.println("Failed to flush the font cache file '"
- + cacheFile + "'.");
- System.exit(1);
- }
+ factory.getFontManager().deleteCache();
}
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/IFInputHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/IFInputHandler.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/IFInputHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/IFInputHandler.java Tue Jul 3 09:46:41 2012
@@ -62,7 +62,7 @@ public class IFInputHandler extends Inpu
public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out)
throws FOPException {
IFDocumentHandler documentHandler
- = userAgent.getFactory().getRendererFactory().createDocumentHandler(
+ = userAgent.getRendererFactory().createDocumentHandler(
userAgent, outputFormat);
try {
documentHandler.setResult(new StreamResult(out));
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/cli/InputHandler.java Tue Jul 3 09:46:41 2012
@@ -51,7 +51,6 @@ import org.apache.fop.ResourceEventProdu
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
-import org.apache.fop.apps.FopFactory;
import org.apache.fop.render.awt.viewer.Renderable;
/**
@@ -103,25 +102,11 @@ public class InputHandler implements Err
public void renderTo(FOUserAgent userAgent, String outputFormat, OutputStream out)
throws FOPException {
- FopFactory factory = userAgent.getFactory();
Fop fop;
if (out != null) {
- fop = factory.newFop(outputFormat, userAgent, out);
+ fop = userAgent.newFop(outputFormat, out);
} else {
- fop = factory.newFop(outputFormat, userAgent);
- }
-
- // if base URL was not explicitly set in FOUserAgent, obtain here
- if (fop.getUserAgent().getBaseURL() == null && sourcefile != null) {
- String baseURL = null;
-
- try {
- baseURL = new File(sourcefile.getAbsolutePath())
- .getParentFile().toURI().toURL().toExternalForm();
- } catch (Exception e) {
- baseURL = "";
- }
- fop.getUserAgent().setBaseURL(baseURL);
+ fop = userAgent.newFop(outputFormat);
}
// Resulting SAX events (the generated FO) must be piped through to FOP
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOTreeBuilder.java Tue Jul 3 09:46:41 2012
@@ -99,7 +99,7 @@ public class FOTreeBuilder extends Defau
throws FOPException {
this.userAgent = foUserAgent;
- this.elementMappingRegistry = userAgent.getFactory().getElementMappingRegistry();
+ this.elementMappingRegistry = userAgent.getElementMappingRegistry();
//This creates either an AreaTreeHandler and ultimately a Renderer, or
//one of the RTF-, MIF- etc. Handlers.
foEventHandler = foUserAgent.getRendererFactory().createFOEventHandler(
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/PropertyList.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/PropertyList.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/PropertyList.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/PropertyList.java Tue Jul 3 09:46:41 2012
@@ -27,7 +27,7 @@ import org.apache.commons.logging.LogFac
import org.apache.xmlgraphics.util.QName;
-import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.fo.properties.CommonAbsolutePosition;
import org.apache.fop.fo.properties.CommonAural;
@@ -308,7 +308,7 @@ public abstract class PropertyList {
String attributeNS;
String attributeName;
String attributeValue;
- FopFactory factory = getFObj().getUserAgent().getFactory();
+ FOUserAgent userAgent = getFObj().getUserAgent();
for (int i = 0; i < attributes.getLength(); i++) {
/* convert all attributes with the same namespace as the fo element
* the "xml:lang" and "xml:base" properties are special cases */
@@ -319,8 +319,8 @@ public abstract class PropertyList {
|| "xml:lang".equals(attributeName)
|| "xml:base".equals(attributeName)) {
convertAttributeToProperty(attributes, attributeName, attributeValue);
- } else if (!factory.isNamespaceIgnored(attributeNS)) {
- ElementMapping mapping = factory.getElementMappingRegistry().getElementMapping(
+ } else if (!userAgent.isNamespaceIgnored(attributeNS)) {
+ ElementMapping mapping = userAgent.getElementMappingRegistry().getElementMapping(
attributeNS);
QName attr = new QName(attributeNS, attributeName);
if (mapping != null) {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java Tue Jul 3 09:46:41 2012
@@ -23,7 +23,7 @@ package org.apache.fop.fo.extensions.svg
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
-import java.net.URL;
+import java.net.URI;
import org.w3c.dom.Element;
@@ -71,12 +71,10 @@ public class SVGElement extends SVGObj {
/* if width and height are zero, get the bounds of the content. */
try {
- URL baseURL = new URL(getUserAgent().getBaseURL() == null
- ? new java.io.File("").toURI().toURL().toExternalForm()
- : getUserAgent().getBaseURL());
- if (baseURL != null) {
+ URI baseUri = getUserAgent().getResourceResolver().getBaseURI();
+ if (baseUri != null) {
SVGOMDocument svgdoc = (SVGOMDocument)doc;
- svgdoc.setURLObject(baseURL);
+ svgdoc.setURLObject(baseUri.toURL());
//The following line should not be called to leave FOP compatible to Batik 1.6.
//svgdoc.setDocumentURI(baseURL.toString());
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/ExternalGraphic.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/ExternalGraphic.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/ExternalGraphic.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/ExternalGraphic.java Tue Jul 3 09:46:41 2012
@@ -75,7 +75,7 @@ public class ExternalGraphic extends Abs
//Additional processing: obtain the image's intrinsic size and baseline information
url = URISpecification.getURL(src);
FOUserAgent userAgent = getUserAgent();
- ImageManager manager = userAgent.getFactory().getImageManager();
+ ImageManager manager = userAgent.getImageManager();
ImageInfo info = null;
try {
info = manager.getImageInfo(url, userAgent.getImageSessionContext());
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonBorderPaddingBackground.java Tue Jul 3 09:46:41 2012
@@ -374,7 +374,7 @@ public class CommonBorderPaddingBackgrou
String uri = URISpecification.getURL(newInstance.backgroundImage);
FObj fobj = pList.getFObj();
FOUserAgent userAgent = pList.getFObj().getUserAgent();
- ImageManager manager = userAgent.getFactory().getImageManager();
+ ImageManager manager = userAgent.getImageManager();
ImageSessionContext sessionContext = userAgent.getImageSessionContext();
ImageInfo info;
try {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CIDFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CIDFont.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CIDFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CIDFont.java Tue Jul 3 09:46:41 2012
@@ -19,6 +19,8 @@
package org.apache.fop.fonts;
+import org.apache.fop.apps.io.InternalResourceResolver;
+
//Java
/**
@@ -29,6 +31,13 @@ public abstract class CIDFont extends Cu
/** Contains the character widths for all characters in the font */
protected int[] width = null;
+ /**
+ * @param resourceResolver the URI resolver for controlling file access
+ */
+ public CIDFont(InternalResourceResolver resourceResolver) {
+ super(resourceResolver);
+ }
+
// ---- Required ----
/**
* Returns the type of the CID font.
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CustomFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CustomFont.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CustomFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CustomFont.java Tue Jul 3 09:46:41 2012
@@ -20,13 +20,15 @@
package org.apache.fop.fonts;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import javax.xml.transform.Source;
+import org.apache.fop.apps.io.InternalResourceResolver;
/**
@@ -35,27 +37,27 @@ import javax.xml.transform.Source;
public abstract class CustomFont extends Typeface
implements FontDescriptor, MutableFont {
- private String fontName = null;
- private String fullName = null;
- private Set<String> familyNames = null;
- private String fontSubName = null;
- private String embedFileName = null;
- private String embedResourceName = null;
- private FontResolver resolver = null;
+ private String fontName;
+ private String fullName;
+ private Set<String> familyNames;
+ private String fontSubName;
+ private URI embedFileURI;
+ private String embedResourceName;
+ private final InternalResourceResolver resourceResolver;
private EmbeddingMode embeddingMode = EmbeddingMode.AUTO;
- private int capHeight = 0;
- private int xHeight = 0;
- private int ascender = 0;
- private int descender = 0;
+ private int capHeight;
+ private int xHeight;
+ private int ascender;
+ private int descender;
private int[] fontBBox = {0, 0, 0, 0};
private int flags = 4;
- private int weight = 0; //0 means unknown weight
- private int stemV = 0;
- private int italicAngle = 0;
- private int missingWidth = 0;
+ private int weight; //0 means unknown weight
+ private int stemV;
+ private int italicAngle;
+ private int missingWidth;
private FontType fontType = FontType.TYPE1;
- private int firstChar = 0;
+ private int firstChar;
private int lastChar = 255;
private Map<Integer, Map<Integer, Integer>> kerning;
@@ -63,6 +65,12 @@ public abstract class CustomFont extends
private boolean useKerning = true;
private boolean useAdvanced = true;
+ /**
+ * @param resourceResolver the URI resource resolver for controlling file access
+ */
+ public CustomFont(InternalResourceResolver resourceResolver) {
+ this.resourceResolver = resourceResolver;
+ }
/** the character map, mapping Unicode ranges to glyph indices. */
protected CMapSegment[] cmap;
@@ -107,15 +115,16 @@ public abstract class CustomFont extends
}
/**
- * Returns an URI representing an embeddable font file. The URI will often
- * be a filename or an URL.
+ * Returns an URI representing an embeddable font file.
+ *
* @return URI to an embeddable font file or null if not available.
*/
- public String getEmbedFileName() {
- return embedFileName;
+ public URI getEmbedFileURI() {
+ return embedFileURI;
}
/**
+
* Returns the embedding mode for this font.
* @return embedding mode
*/
@@ -124,20 +133,13 @@ public abstract class CustomFont extends
}
/**
- * Returns a Source representing an embeddable font file.
- * @return Source for an embeddable font file
+ * Returns an {@link InputStream} representing an embeddable font file.
+ *
+ * @return {@link InputStream} for an embeddable font file
* @throws IOException if embedFileName is not null but Source is not found
*/
- public Source getEmbedFileSource() throws IOException {
- Source result = null;
- if (resolver != null && embedFileName != null) {
- result = resolver.resolve(embedFileName);
- if (result == null) {
- throw new IOException("Unable to resolve Source '"
- + embedFileName + "' for embedded font");
- }
- }
- return result;
+ public InputStream getInputStream() throws IOException {
+ return resourceResolver.getResource(embedFileURI);
}
/**
@@ -335,8 +337,8 @@ public abstract class CustomFont extends
/**
* {@inheritDoc}
*/
- public void setEmbedFileName(String path) {
- this.embedFileName = path;
+ public void setEmbedURI(URI path) {
+ this.embedFileURI = path;
}
/**
@@ -463,14 +465,6 @@ public abstract class CustomFont extends
this.useAdvanced = enabled;
}
- /**
- * Sets the font resolver. Needed for URI resolution.
- * @param resolver the font resolver
- */
- public void setResolver(FontResolver resolver) {
- this.resolver = resolver;
- }
-
/** {@inheritDoc} */
public void putKerningEntry(Integer key, Map<Integer, Integer> value) {
if (kerning == null) {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CustomFontCollection.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CustomFontCollection.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CustomFontCollection.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/CustomFontCollection.java Tue Jul 3 09:46:41 2012
@@ -21,13 +21,16 @@ package org.apache.fop.fonts;
import java.util.List;
+import org.apache.fop.apps.io.InternalResourceResolver;
+
/**
* Sets up a set of custom (embedded) fonts
*/
public class CustomFontCollection implements FontCollection {
- private FontResolver fontResolver;
private final List<EmbedFontInfo> embedFontInfoList;
+ private final InternalResourceResolver uriResolver;
+ private final boolean useComplexScripts;
/**
* Main constructor.
@@ -35,14 +38,11 @@ public class CustomFontCollection implem
* @param customFonts the list of custom fonts
* @param useComplexScriptFeatures true if complex script features enabled
*/
- public CustomFontCollection(FontResolver fontResolver,
- List<EmbedFontInfo> customFonts, boolean useComplexScriptFeatures) {
- this.fontResolver = fontResolver;
- if (this.fontResolver == null) {
- //Ensure that we have minimal font resolution capabilities
- this.fontResolver = FontManager.createMinimalFontResolver(useComplexScriptFeatures);
- }
+ public CustomFontCollection(InternalResourceResolver fontResolver,
+ List<EmbedFontInfo> customFonts, boolean useComplexScriptFeatures) {
+ this.uriResolver = fontResolver;
this.embedFontInfoList = customFonts;
+ this.useComplexScripts = useComplexScriptFeatures;
}
/** {@inheritDoc} */
@@ -52,22 +52,14 @@ public class CustomFontCollection implem
}
String internalName = null;
- //FontReader reader = null;
for (int i = 0; i < embedFontInfoList.size(); i++) {
EmbedFontInfo embedFontInfo = embedFontInfoList.get(i);
- //String metricsFile = configFontInfo.getMetricsFile();
internalName = "F" + num;
num++;
- /*
- reader = new FontReader(metricsFile);
- reader.useKerning(configFontInfo.getKerning());
- reader.setFontEmbedPath(configFontInfo.getEmbedFile());
- fontInfo.addMetrics(internalName, reader.getFont());
- */
- LazyFont font = new LazyFont(embedFontInfo, this.fontResolver);
+ LazyFont font = new LazyFont(embedFontInfo, this.uriResolver, useComplexScripts);
fontInfo.addMetrics(internalName, font);
List<FontTriplet> triplets = embedFontInfo.getFontTriplets();
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EmbedFontInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EmbedFontInfo.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EmbedFontInfo.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/EmbedFontInfo.java Tue Jul 3 09:46:41 2012
@@ -21,6 +21,7 @@ package org.apache.fop.fonts;
import java.io.IOException;
import java.io.Serializable;
+import java.net.URI;
import java.util.List;
/**
@@ -33,62 +34,66 @@ public class EmbedFontInfo implements Se
/** Serialization Version UID */
private static final long serialVersionUID = 8755432068669997369L;
- /** filename of the metrics file */
- protected String metricsFile;
- /** filename of the main font file */
- protected String embedFile;
+ protected final URI metricsURI;
+ protected final URI embedURI;
/** false, to disable kerning */
- protected boolean kerning;
+ protected final boolean kerning;
/** false, to disable advanced typographic features */
- protected boolean advanced;
+ protected final boolean advanced;
/** the requested encoding mode for the font */
- protected EncodingMode encodingMode = EncodingMode.AUTO;
+ private final EncodingMode encodingMode;
/** the requested embedding mode for this font */
- protected EmbeddingMode embeddingMode = EmbeddingMode.AUTO;
+ private final EmbeddingMode embeddingMode;
/** the PostScript name of the font */
- protected String postScriptName = null;
+ protected String postScriptName;
/** the sub-fontname of the font (used for TrueType Collections, null otherwise) */
- protected String subFontName = null;
+ protected String subFontName;
/** the list of associated font triplets */
- private List<FontTriplet> fontTriplets = null;
+ private List<FontTriplet> fontTriplets;
private transient boolean embedded = true;
/**
* Main constructor
- * @param metricsFile path to the xml file containing font metrics
- * @param kerning true if kerning should be enabled
+ * @param metricsURI the URI of the XML resource containing font metrics
+ * @param kerning True if kerning should be enabled
* @param advanced true if advanced typography features should be enabled
- * @param fontTriplets list of font triplets to associate with this font
- * @param embedFile path to the embeddable font file (may be null)
+ * @param fontTriplets List of font triplets to associate with this font
+ * @param embedURI Path to the embeddable font file (may be null)
* @param subFontName the sub-fontname used for TrueType Collections (null otherwise)
+ * @param encodingMode the encoding mode to use for this font
*/
- public EmbedFontInfo(String metricsFile, boolean kerning, boolean advanced,
- List<FontTriplet> fontTriplets, String embedFile, String subFontName) {
- this.metricsFile = metricsFile;
- this.embedFile = embedFile;
+ public EmbedFontInfo(URI metricsURI, boolean kerning, boolean advanced,
+ List<FontTriplet> fontTriplets, URI embedURI, String subFontName,
+ EncodingMode encodingMode, EmbeddingMode embeddingMode) {
+ this.metricsURI = metricsURI;
+ this.embedURI = embedURI;
this.kerning = kerning;
this.advanced = advanced;
this.fontTriplets = fontTriplets;
this.subFontName = subFontName;
+ this.encodingMode = encodingMode;
+ this.embeddingMode = embeddingMode;
}
/**
- * Returns the path to the metrics file
+ * Returns the URI of the metrics XML resource
+ *
* @return the metrics file path
*/
- public String getMetricsFile() {
- return metricsFile;
+ public URI getMetricsURI() {
+ return metricsURI;
}
/**
- * Returns the path to the embeddable font file
- * @return the font file path
+ * Returns the URI to the embeddable font resource
+ *
+ * @return the font resource URI
*/
- public String getEmbedFile() {
- return embedFile;
+ public URI getEmbedURI() {
+ return embedURI;
}
/**
@@ -145,7 +150,7 @@ public class EmbedFontInfo implements Se
* @return true if the font is embedded, false if it is referenced.
*/
public boolean isEmbedded() {
- if (metricsFile != null && embedFile == null) {
+ if (embedURI == null) {
return false;
} else {
return this.embedded;
@@ -176,28 +181,6 @@ public class EmbedFontInfo implements Se
return this.encodingMode;
}
- /**
- * Sets the requested encoding mode for this font.
- * @param mode the new encoding mode
- */
- public void setEncodingMode(EncodingMode mode) {
- if (mode == null) {
- throw new NullPointerException("mode must not be null");
- }
- this.encodingMode = mode;
- }
-
- /**
- * Sets the embedding mode for this font, currently not supported for Type 1 fonts.
- * @param embeddingMode the new embedding mode.
- */
- public void setEmbeddingMode(EmbeddingMode embeddingMode) {
- if (embeddingMode == null) {
- throw new NullPointerException("embeddingMode must not be null");
- }
- this.embeddingMode = embeddingMode;
- }
-
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
@@ -206,7 +189,7 @@ public class EmbedFontInfo implements Se
/** {@inheritDoc} */
public String toString() {
- return "metrics-url=" + metricsFile + ", embed-url=" + embedFile
+ return "metrics-uri=" + metricsURI + ", embed-uri=" + embedURI
+ ", kerning=" + kerning
+ ", advanced=" + advanced
+ ", enc-mode=" + encodingMode
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontAdder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontAdder.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontAdder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontAdder.java Tue Jul 3 09:46:41 2012
@@ -19,9 +19,11 @@
package org.apache.fop.fonts;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
+import org.apache.fop.apps.io.InternalResourceResolver;
import org.apache.fop.fonts.autodetect.FontInfoFinder;
/**
@@ -29,18 +31,19 @@ import org.apache.fop.fonts.autodetect.F
*/
public class FontAdder {
private final FontEventListener listener;
- private final FontResolver resolver;
+ private final InternalResourceResolver resourceResolver;
private final FontManager manager;
/**
* Main constructor
* @param manager a font manager
- * @param resolver a font resolver
+ * @param resourceResolver a font resolver
* @param listener a font event handler
*/
- public FontAdder(FontManager manager, FontResolver resolver, FontEventListener listener) {
+ public FontAdder(FontManager manager, InternalResourceResolver resourceResolver,
+ FontEventListener listener) {
this.manager = manager;
- this.resolver = resolver;
+ this.resourceResolver = resourceResolver;
this.listener = listener;
}
@@ -48,14 +51,16 @@ public class FontAdder {
* Iterates over font url list adding to font info list
* @param fontURLList font file list
* @param fontInfoList a configured font info list
+ * @throws URISyntaxException if a URI syntax error is found
*/
- public void add(List<URL> fontURLList, List<EmbedFontInfo> fontInfoList) {
+ public void add(List<URL> fontURLList, List<EmbedFontInfo> fontInfoList)
+ throws URISyntaxException {
FontCache cache = manager.getFontCache();
FontInfoFinder finder = new FontInfoFinder();
finder.setEventListener(listener);
for (URL fontURL : fontURLList) {
- EmbedFontInfo[] embedFontInfos = finder.find(fontURL, resolver, cache);
+ EmbedFontInfo[] embedFontInfos = finder.find(fontURL.toURI(), resourceResolver, cache);
if (embedFontInfos == null) {
continue;
}
Modified: xmlgraphics/fop/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=1356646&r1=1356645&r2=1356646&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 Tue Jul 3 09:46:41 2012
@@ -29,6 +29,7 @@ import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
@@ -40,6 +41,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.io.InternalResourceResolver;
import org.apache.fop.util.LogUtil;
/**
@@ -234,9 +236,9 @@ public final class FontCache implements
*/
protected static String getCacheKey(EmbedFontInfo fontInfo) {
if (fontInfo != null) {
- String embedFile = fontInfo.getEmbedFile();
- String metricsFile = fontInfo.getMetricsFile();
- return (embedFile != null) ? embedFile : metricsFile;
+ URI embedFile = fontInfo.getEmbedURI();
+ URI metricsFile = fontInfo.getMetricsURI();
+ return (embedFile != null) ? embedFile.toASCIIString() : metricsFile.toASCIIString();
}
return null;
}
@@ -318,7 +320,7 @@ public final class FontCache implements
* @param fontInfo
* font info
*/
- public void addFont(EmbedFontInfo fontInfo) {
+ public void addFont(EmbedFontInfo fontInfo, InternalResourceResolver resourceResolver) {
String cacheKey = getCacheKey(fontInfo);
synchronized (changeLock) {
CachedFontFile cachedFontFile;
@@ -329,10 +331,9 @@ public final class FontCache implements
}
} else {
// try and determine modified date
- File fontFile = getFileFromUrls(new String[] {
- fontInfo.getEmbedFile(), fontInfo.getMetricsFile() });
- long lastModified = (fontFile != null ? fontFile.lastModified()
- : -1);
+ URI fontUri = resourceResolver.resolveFromBase(fontInfo.getEmbedURI());
+ File fontFile = new File(fontUri);
+ long lastModified = (fontFile != null ? fontFile.lastModified() : -1);
cachedFontFile = new CachedFontFile(lastModified);
if (log.isTraceEnabled()) {
log.trace("Font added to cache: " + cacheKey);
@@ -467,8 +468,9 @@ public final class FontCache implements
* the URL
* @return the last modified date/time
*/
- public static long getLastModified(URL url) {
+ public static long getLastModified(URI uri) {
try {
+ URL url = uri.toURL();
URLConnection conn = url.openConnection();
try {
return conn.getLastModified();
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontDetector.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontDetector.java?rev=1356646&r1=1356645&r2=1356646&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontDetector.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontDetector.java Tue Jul 3 09:46:41 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;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org