import org.apache.commons.io.IOUtils;
-import org.apache.fop.afp.util.AFPResourceUtil;
import org.apache.fop.afp.util.AFPResourceAccessor;
-
+import org.apache.fop.afp.util.AFPResourceUtil;
/**
* Encapsulates an included resource object that is loaded from an external file.
import java.net.URI;
import java.net.URISyntaxException;
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.io.InternalResourceResolver;
/**
private final String baseURI;
/**
- * Constructor for resource to be accessed via the {@link FOUserAgent}. This contructor
- * takes a base URI for resolving font resource URIs. So, if fonts need to be accessed, you can
- * set the {@link FontManager}'s base URI instead of the one on the {@link FopFactory}.
+ * Constructor for resource to be accessed via the {@link org.apache.fop.apps.FOUserAgent}. This
+ * contructor takes a base URI for resolving font resource URIs. So, if fonts need to be
+ * accessed, you can set the {@link FontManager}'s base URI instead of the one on the
+ * {@link org.apache.fop.apps.FopFactory}.
*
* @param InternalResourceResolver resource resolver
* @param baseURI the custom base URI to resolve relative URIs against (may be null)
}
/**
- * Constructor for resource to be accessed via the {@link FOUserAgent}.
+ * Constructor for resource to be accessed via the {@link org.apache.fop.apps.FOUserAgent}.
*
* @param InternalResourceResolver resource resolver
*/
public InputStream createInputStream(URI uri) throws IOException {
return resourceResolver.getResource(getResourceURI(uri));
}
-
}
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import org.xml.sax.SAXException;
import org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry;
import org.apache.xmlgraphics.image.loader.util.Penalty;
+import org.apache.fop.apps.io.InternalResourceResolver;
import org.apache.fop.apps.io.ResourceResolver;
import org.apache.fop.apps.io.ResourceResolverFactory;
-import org.apache.fop.apps.io.InternalResourceResolver;
import org.apache.fop.fonts.FontManagerConfigurator;
import org.apache.fop.hyphenation.HyphenationTreeCache;
import org.apache.fop.util.LogUtil;
}
// configure font manager
- new FontManagerConfigurator(cfg, fopFactoryBuilder.getBaseUri(), resourceResolver).configure(
+ new FontManagerConfigurator(cfg, fopFactoryBuilder.getBaseURI(), resourceResolver).configure(
fopFactoryBuilder.getFontManager(), strict);
// configure image loader framework
+ " element must consist of exactly two letters ("
+ location + ")", error);
}
- lang = lang.toLowerCase();
+ lang = lang.toLowerCase(Locale.getDefault());
country = hyphPatConfig[i].getAttribute("country", null);
if ("".equals(country)) {
+ " element must consist of exactly two letters ("
+ location + ")", error);
}
- country = country.toUpperCase();
+ country = country.toUpperCase(Locale.getDefault());
}
filename = hyphPatConfig[i].getValue(null);
String className = penaltyCfg.getAttribute("class");
String value = penaltyCfg.getAttribute("value");
Penalty p = null;
- if (value.toUpperCase().startsWith("INF")) {
+ if (value.toUpperCase(Locale.getDefault()).startsWith("INF")) {
p = Penalty.INFINITE_PENALTY;
} else {
try {
*
* @return the base URI
*/
- URI getBaseUri() {
+ URI getBaseURI() {
return config.getBaseURI();
}
public OutputStream getOutputStream(String id) throws IOException {
File file = getTempFile(id);
- file.createNewFile();
- return new FileOutputStream(file);
+ if (file.createNewFile()) {
+ return new FileOutputStream(file);
+ } else {
+ throw new IOException("Filed to create temporary file: " + id);
+ }
}
}
throw new FOPException(e);
}
fopFactoryBuilder.setStrictFOValidation(strictValidation);
+ fopFactoryBuilder.setComplexScriptFeatures(useComplexScriptFeatures);
}
factory = fopFactoryBuilder.build();
}
*/
public final class DefaultFontConfig implements FontConfig {
- protected static Log log = LogFactory.getLog(DefaultFontConfig.class);
+ private static final Log log = LogFactory.getLog(DefaultFontConfig.class);
private final List<Directory> directories = new ArrayList<Directory>();
*/
public class DefaultFontConfigurator implements FontConfigurator<EmbedFontInfo> {
/** logger instance */
- protected static Log log = LogFactory.getLog(DefaultFontConfigurator.class);
+ protected static final Log log = LogFactory.getLog(DefaultFontConfigurator.class);
private final FontManager fontManager;
private final InternalResourceResolver resourceResolver;
* Initializes font info settings from the user configuration
* @throws FOPException if an exception occurs while processing the configuration
*/
- public List<EmbedFontInfo> configure(FontConfig fontInfoConfig)
- throws FOPException {
+ public List<EmbedFontInfo> configure(FontConfig fontInfoConfig) throws FOPException {
List<EmbedFontInfo> fontInfoList = new ArrayList<EmbedFontInfo>();
- DefaultFontConfig adobeFontInfoConfig = (DefaultFontConfig) fontInfoConfig;
- if (adobeFontInfoConfig != null) {
+ if (fontInfoConfig != null) {
+ assert fontInfoConfig instanceof DefaultFontConfig;
+ DefaultFontConfig adobeFontInfoConfig = (DefaultFontConfig) fontInfoConfig;
long start = 0;
if (log.isDebugEnabled()) {
log.debug("Starting font configuration...");
// no font triplet info
if (tripletList.size() == 0) {
URI fontUri = resourceResolver.resolveFromBase(embedUri);
- if (fontUri != null) {
- FontInfoFinder finder = new FontInfoFinder();
- finder.setEventListener(listener);
- EmbedFontInfo[] infos = finder.find(fontUri, resourceResolver, fontCache);
- return infos[0]; //When subFont is set, only one font is returned
- } else {
- return null;
- }
+ FontInfoFinder finder = new FontInfoFinder();
+ finder.setEventListener(listener);
+ EmbedFontInfo[] infos = finder.find(fontUri, resourceResolver, fontCache);
+ return infos[0]; //When subFont is set, only one font is returned
}
EncodingMode encodingMode = EncodingMode.getValue(font.getEncodingMode());
EmbeddingMode embeddingMode = EmbeddingMode.getValue(font.getEmbeddingMode());
// try and determine modified date
URI fontUri = resourceResolver.resolveFromBase(fontInfo.getEmbedURI());
File fontFile = new File(fontUri);
- long lastModified = (fontFile != null ? fontFile.lastModified() : -1);
+ long lastModified = fontFile.lastModified();
cachedFontFile = new CachedFontFile(lastModified);
if (log.isTraceEnabled()) {
log.trace("Font added to cache: " + cacheKey);
loader = new Type1FontLoader(fontFileURI, embedded, useKerning, resourceResolver);
} else {
loader = new TTFFontLoader(fontFileURI, subFontName, embedded, embeddingMode,
- encodingMode, useKerning, useAdvanced, resourceResolver);
+ encodingMode, useKerning, useAdvanced, resourceResolver);
}
return loader.getFont();
}
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.base14.Base14FontCollection;
-import sun.font.FontResolver;
-
/** Abstract base class of "Print" type renderers. */
public abstract class PrintRenderer extends AbstractRenderer {
/** Font configuration */
protected FontInfo fontInfo;
- /** Font resolver */
- protected FontResolver fontResolver = null;
-
/** list of fonts */
protected List<EmbedFontInfo> embedFontInfoList = null;
import java.util.Collections;
import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.io.InternalResourceResolver;
public abstract class PrintRendererConfigurator extends AbstractRendererConfigurator
implements IFDocumentHandlerConfigurator {
- /** logger instance */
- private static Log LOG = LogFactory.getLog(PrintRendererConfigurator.class);
-
private final RendererConfigParser rendererConfigParser;
private final FontConfigurator<EmbedFontInfo> fontInfoConfigurator;
private List<EmbedFontInfo> buildFontList(String mimeType) throws FOPException {
return fontInfoConfigurator.configure(getRendererConfig(mimeType).getFontInfoConfig());
}
+
+ public static PrintRendererConfigurator createDefaultInstance(FOUserAgent userAgent) {
+ return new PrintRendererConfigurator(userAgent, null) {
+ @Override
+ protected List<FontCollection> getDefaultFontCollection() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
}
CharacterSet characterSet = null;
if (base14 != null) {
try {
- Class<? extends Typeface> clazz = Class.forName(
- "org.apache.fop.fonts.base14." + base14).asSubclass(Typeface.class);
- try {
- Typeface tf = clazz.newInstance();
- characterSet = CharacterSetBuilder.getSingleByteInstance()
- .build(characterset, super.codePage,
- super.encoding,
- tf, eventProducer);
- } catch (Exception ie) {
- String msg = "The base 14 font class " + clazz.getName()
- + " could not be instantiated";
- LOG.error(msg);
- }
+ Typeface tf = getTypeFace(base14);
+ characterSet = CharacterSetBuilder.getSingleByteInstance()
+ .build(characterset, super.codePage,
+ super.encoding, tf, eventProducer);
} catch (ClassNotFoundException cnfe) {
String msg = "The base 14 font class for " + characterset
+ " could not be found";
}
}
+ private static Typeface getTypeFace(String base14Name) throws ClassNotFoundException {
+ try {
+ Class<? extends Typeface> clazz = Class.forName("org.apache.fop.fonts.base14."
+ + base14Name).asSubclass(Typeface.class);
+ return clazz.newInstance();
+ } catch (IllegalAccessException iae) {
+ LOG.error(iae.getMessage());
+ } catch (ClassNotFoundException cnfe) {
+ LOG.error(cnfe.getMessage());
+ } catch (InstantiationException ie) {
+ LOG.error(ie.getMessage());
+ }
+ throw new ClassNotFoundException("Couldn't load file for AFP font with base14 name: "
+ + base14Name);
+ }
+
static final class RasterFontConfig extends AFPFontConfigData {
private final List<RasterCharactersetData> charsets;
for (RasterCharactersetData charset : charsets) {
if (charset.base14 != null) {
try {
- Class<? extends Typeface> clazz = Class.forName(
- "org.apache.fop.fonts.base14." + charset.base14).asSubclass(
- Typeface.class);
- try {
- Typeface tf = clazz.newInstance();
- rasterFont.addCharacterSet(charset.size,
- CharacterSetBuilder.getSingleByteInstance().build(
- charset.characterset, super.codePage, super.encoding,
- tf, eventProducer));
- } catch (Exception ie) {
- String msg = "The base 14 font class " + clazz.getName()
- + " could not be instantiated";
- LOG.error(msg);
- }
+ Typeface tf = getTypeFace(charset.base14);
+ rasterFont.addCharacterSet(charset.size,
+ CharacterSetBuilder.getSingleByteInstance().build(
+ charset.characterset, super.codePage, super.encoding,
+ tf, eventProducer));
+
} catch (ClassNotFoundException cnfe) {
String msg = "The base 14 font class for " + charset.characterset
+ " could not be found";
LOG.error(msg);
+ } catch (IOException ie) {
+ String msg = "The base 14 font class " + charset.characterset
+ + " could not be instantiated";
+ LOG.error(msg);
}
} else {
AFPResourceAccessor accessor = getAccessor(resourceResolver);
/** {@inheritDoc} */
public AFPRendererConfig build(FOUserAgent userAgent, Configuration cfg) throws FOPException {
- boolean strict = userAgent != null ? userAgent.validateUserConfigStrictly() : false;
+ boolean strict = userAgent.validateUserConfigStrictly();
AFPRendererConfig config = null;
AFPEventProducer eventProducer = AFPEventProducer.Provider.get(userAgent.getEventBroadcaster());
try {
*/
public class AFPRendererConfigurator extends PrintRendererConfigurator implements
IFDocumentHandlerConfigurator {
- private static Log LOG = LogFactory.getLog(AFPRendererConfigurator.class);
+ private static Log log = LogFactory.getLog(AFPRendererConfigurator.class);
private final AFPEventProducer eventProducer;
config.getFontInfoConfig(), mimeType));
} catch (IOException e) {
eventProducer.invalidConfiguration(this, e);
- LogUtil.handleException(LOG, e, userAgent.validateUserConfigStrictly());
+ LogUtil.handleException(log, e, userAgent.validateUserConfigStrictly());
} catch (IllegalArgumentException iae) {
eventProducer.invalidConfiguration(this, iae);
- LogUtil.handleException(LOG, iae, userAgent.validateUserConfigStrictly());
+ LogUtil.handleException(log, iae, userAgent.validateUserConfigStrictly());
}
}
return new AFPFontCollection(userAgent.getEventBroadcaster(), null);
package org.apache.fop.render.afp;
import java.io.ObjectStreamException;
-import java.io.Serializable;
/** Enumeration of the AFP shading modes. */
-public enum AFPShadingMode implements Serializable {
+public enum AFPShadingMode {
/** the color mode (the default) */
COLOR("COLOR"),
/** the dithered mode */
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.bitmap.PNGRendererConfig.PNGRendererConfigParser;
import org.apache.fop.render.intermediate.IFContext;
-import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/**
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.bitmap.TIFFRendererConfig.TIFFRendererConfigParser;
import org.apache.fop.render.intermediate.IFContext;
-import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/**
import java.util.Locale;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import org.apache.fop.accessibility.DummyStructureTreeEventHandler;
import org.apache.fop.accessibility.StructureTreeEventHandler;
import org.apache.fop.apps.FOUserAgent;
*/
public abstract class AbstractIFDocumentHandler implements IFDocumentHandler {
- /** logging instance */
- private static Log log = LogFactory.getLog(AbstractIFDocumentHandler.class);
-
private final IFContext ifContext;
/**
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
import org.apache.fop.render.intermediate.IFContext;
-import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFPainter;
import org.apache.fop.render.pcl.PCLRendererConfig.PCLRendererConfigParser;
import org.apache.fop.render.pcl.extensions.PCLElementMapping;
-
/**
* {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation
* that produces PCL 5.
package org.apache.fop.render.pcl;
import java.io.ObjectStreamException;
-import java.io.Serializable;
/**
* Enumeration class for PCL rendering modes.
*/
-public enum PCLRenderingMode implements Serializable {
+public enum PCLRenderingMode {
/** "Quality" rendering (mixed native and bitmap for improved quality) */
QUALITY("quality", 1.0f),
/** "Speed" rendering (maximum speed with native rendering, reduced visual quality) */
package org.apache.fop.render.pdf;
-import org.apache.fop.pdf.PDFAMode;
-import org.apache.fop.pdf.PDFXMode;
import org.apache.fop.render.RendererConfigOption;
public enum PDFEncryptionOption implements RendererConfigOption {
}
},
/** Rendering Options key for the PDF/A mode, default: {@link PDFAMode#DISABLED} */
- PDF_A_MODE("pdf-a-mode", PDFAMode.DISABLED){
+ PDF_A_MODE("pdf-a-mode", PDFAMode.DISABLED) {
@Override
PDFAMode deserialize(String value) {
return PDFAMode.getValueOf(value);
}
},
/** Rendering Options key for the PDF/X mode, default: {@link PDFXMode#DISABLED} */
- PDF_X_MODE("pdf-x-mode", PDFXMode.DISABLED){
+ PDF_X_MODE("pdf-x-mode", PDFXMode.DISABLED) {
@Override
PDFXMode deserialize(String value) {
return PDFXMode.getValueOf(value);
static {
final EnumMap<PDFRendererOption, Object> props
= new EnumMap<PDFRendererOption, Object>(PDFRendererOption.class);
- for(PDFRendererOption option : PDFRendererOption.values()) {
+ for (PDFRendererOption option : PDFRendererOption.values()) {
props.put(option, option.getDefaultValue());
}
DEFAULT = new PDFRendererOptionsConfig(props, null);
package org.apache.fop.render.print;
-import java.util.List;
-
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.fonts.FontCollection;
import org.apache.fop.render.AbstractRendererMaker;
import org.apache.fop.render.PrintRendererConfigurator;
import org.apache.fop.render.Renderer;
@Override
public void configureRenderer(FOUserAgent userAgent, Renderer renderer) throws FOPException {
- // TODO what constructor params?
- new PrintRendererConfigurator(userAgent, null) {
- @Override
- protected List<FontCollection> getDefaultFontCollection() {
- throw new UnsupportedOperationException();
- }
- } .configure(renderer);
+ PrintRendererConfigurator.createDefaultInstance(userAgent).configure(renderer);
}
@Override
public String[] getSupportedMimeTypes() {
return MIMES;
}
-
}
import org.apache.fop.apps.io.TempResourceURIGenerator;
import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
import org.apache.fop.render.intermediate.IFContext;
-import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFPainter;
import org.apache.fop.render.ps.extensions.PSSetPageDevice;
import org.apache.fop.render.ps.extensions.PSSetupCode;
-
/**
* {@link org.apache.fop.render.intermediate.IFDocumentHandler} implementation
* that produces PostScript.
package org.apache.fop.render.xml;
-import java.util.List;
-
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.fonts.FontCollection;
import org.apache.fop.render.AbstractRendererMaker;
import org.apache.fop.render.PrintRendererConfigurator;
import org.apache.fop.render.Renderer;
@Override
public void configureRenderer(FOUserAgent userAgent, Renderer renderer) throws FOPException {
- // TODO what constructor params?
- new PrintRendererConfigurator(userAgent, null) {
- @Override
- protected List<FontCollection> getDefaultFontCollection() {
- throw new UnsupportedOperationException();
- }
- } .configure(renderer);
+ PrintRendererConfigurator.createDefaultInstance(userAgent).configure(renderer);
}
@Override
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URI;
} catch (Exception e) {
// Ignore exception - will be logged a bit further down
// (colorSpace == null case)
+ log.warn("Exception thrown resolving the color space: " + e.getMessage());
}
if (colorSpace != null) {
import org.apache.fop.render.bitmap.MultiFileRenderingUtil;
import org.apache.fop.render.intermediate.DelegatingFragmentContentHandler;
import org.apache.fop.render.intermediate.IFContext;
-import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFPainter;
import org.apache.fop.util.GenerationHelperContentHandler;
import org.apache.fop.render.intermediate.IFConstants;
import org.apache.fop.render.intermediate.IFContext;
-import org.apache.fop.render.intermediate.IFDocumentHandler;
import org.apache.fop.render.intermediate.IFException;
import org.apache.fop.render.intermediate.IFPainter;
import org.apache.fop.util.XMLUtil;