aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-07-23 09:34:17 +0000
committerJeremias Maerki <jeremias@apache.org>2008-07-23 09:34:17 +0000
commit2d83907e2d37f04aa8bebd938b737189d59eb62d (patch)
treec42d29083d95e098f521591b156a3f1df55bf2b8 /src/java
parent8091bd11210ac68aa3289532643e42b66545a495 (diff)
downloadxmlgraphics-fop-2d83907e2d37f04aa8bebd938b737189d59eb62d.tar.gz
xmlgraphics-fop-2d83907e2d37f04aa8bebd938b737189d59eb62d.zip
Improved/fixed font setup for painters. Reduced the whole thing to pass in a fully set-up FontInfo object to reduce dependencies on the font package to the necessary.
Fixed problem with some JAXP implementations for "lastProprties" in IFParser. Support for XMP parsing added in IFParser. Added round-trip testing for new IF. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@679047 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/fop/render/PrintRendererConfigurator.java27
-rw-r--r--src/java/org/apache/fop/render/RendererFactory.java1
-rw-r--r--src/java/org/apache/fop/render/intermediate/AbstractBinaryWritingIFPainter.java67
-rw-r--r--src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java12
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFPainter.java12
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFPainterConfigurator.java7
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFParser.java24
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFRenderer.java5
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFPainter.java8
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java52
10 files changed, 120 insertions, 95 deletions
diff --git a/src/java/org/apache/fop/render/PrintRendererConfigurator.java b/src/java/org/apache/fop/render/PrintRendererConfigurator.java
index 6849f867f..93c5353ba 100644
--- a/src/java/org/apache/fop/render/PrintRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/PrintRendererConfigurator.java
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -71,7 +71,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator
/**
* Builds a list of EmbedFontInfo objects for use with the setup() method.
- *
+ *
* @param renderer print renderer
* @throws FOPException if something's wrong with the config data
*/
@@ -84,6 +84,19 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator
PrintRenderer printRenderer = (PrintRenderer)renderer;
FontResolver fontResolver = printRenderer.getFontResolver();
+
+ List embedFontInfoList = buildFontList(cfg, fontResolver);
+ printRenderer.addFontList(embedFontInfoList);
+ }
+
+ /**
+ * Builds the font list from configuration.
+ * @param cfg the configuration object
+ * @param fontResolver a font resolver
+ * @return the list of {@code EmbedFontInfo} objects
+ * @throws FOPException if an error occurs while processing the configuration
+ */
+ protected List buildFontList(Configuration cfg, FontResolver fontResolver) throws FOPException {
FopFactory factory = userAgent.getFactory();
FontManager fontManager = factory.getFontManager();
if (fontResolver == null) {
@@ -100,12 +113,12 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator
if (fontCache != null && fontCache.hasChanged()) {
fontCache.save();
}
- printRenderer.addFontList(embedFontInfoList);
+ return embedFontInfoList;
}
/**
* Builds a list of EmbedFontInfo objects for use with the setup() method.
- *
+ *
* @param cfg Configuration object
* @param fontResolver the FontResolver to use
* @param strict true if an Exception should be thrown if an error is found.
@@ -285,7 +298,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator
/**
* Creates a new FontTriplet given a triple Configuration
- *
+ *
* @param tripletCfg a triplet configuration
* @param strict use strict validation
* @return a font triplet font key
@@ -323,7 +336,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator
/**
* Returns a font info from a font node Configuration definition
- *
+ *
* @param fontCfg Configuration object (font node)
* @param fontResolver font resolver used to resolve font
* @param strict validate configuration strictly
diff --git a/src/java/org/apache/fop/render/RendererFactory.java b/src/java/org/apache/fop/render/RendererFactory.java
index 3bf4881b9..412f3e2cd 100644
--- a/src/java/org/apache/fop/render/RendererFactory.java
+++ b/src/java/org/apache/fop/render/RendererFactory.java
@@ -331,6 +331,7 @@ public class RendererFactory {
IFPainterConfigurator configurator = maker.getConfigurator(userAgent);
if (configurator != null) {
configurator.configure(painter);
+ configurator.setupFontInfo(painter);
}
return painter;
//}
diff --git a/src/java/org/apache/fop/render/intermediate/AbstractBinaryWritingIFPainter.java b/src/java/org/apache/fop/render/intermediate/AbstractBinaryWritingIFPainter.java
index 860de7946..7f82f3d93 100644
--- a/src/java/org/apache/fop/render/intermediate/AbstractBinaryWritingIFPainter.java
+++ b/src/java/org/apache/fop/render/intermediate/AbstractBinaryWritingIFPainter.java
@@ -23,7 +23,6 @@ import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
-import java.util.List;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
@@ -31,13 +30,11 @@ import javax.xml.transform.stream.StreamResult;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
-import org.apache.fop.fonts.CustomFontCollection;
import org.apache.fop.fonts.FontCollection;
+import org.apache.fop.fonts.FontEventAdapter;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontManager;
-import org.apache.fop.fonts.FontResolver;
import org.apache.fop.fonts.base14.Base14FontCollection;
-import org.apache.fop.render.DefaultFontResolver;
/**
* Abstract base class for binary-writing IFPainter implementations.
@@ -52,12 +49,6 @@ public abstract class AbstractBinaryWritingIFPainter extends AbstractIFPainter {
/** Font configuration */
protected FontInfo fontInfo;
- /** Font resolver */
- protected FontResolver fontResolver = null;
-
- /** list of fonts */
- protected List/*<EmbedFontInfo>*/ embedFontInfoList = null;
-
/** {@inheritDoc} */
public void setResult(Result result) throws IFException {
if (result instanceof StreamResult) {
@@ -93,43 +84,6 @@ public abstract class AbstractBinaryWritingIFPainter extends AbstractIFPainter {
}
/**
- * Adds a font list to current list of fonts
- * @param fontList a font info list
- */
- public void addFontList(List/*<EmbedFontInfo>*/ fontList) {
- if (embedFontInfoList == null) {
- setFontList(fontList);
- } else {
- embedFontInfoList.addAll(fontList);
- }
- }
-
- /**
- * @param embedFontInfoList list of available fonts
- */
- public void setFontList(List/*<EmbedFontInfo>*/ embedFontInfoList) {
- this.embedFontInfoList = embedFontInfoList;
- }
-
- /**
- * @return list of available embedded fonts
- */
- public List/*<EmbedFontInfo>*/ getFontList() {
- return this.embedFontInfoList;
- }
-
- /**
- * Returns the {@code FontResolver} used by this painter.
- * @return the font resolver
- */
- public FontResolver getFontResolver() {
- if (this.fontResolver == null) {
- this.fontResolver = new DefaultFontResolver(getUserAgent());
- }
- return this.fontResolver;
- }
-
- /**
* Returns the {@code FontInfo} object.
* @return the font info
*/
@@ -137,23 +91,22 @@ public abstract class AbstractBinaryWritingIFPainter extends AbstractIFPainter {
return this.fontInfo;
}
+ /** {@inheritDoc} */
public void setFontInfo(FontInfo fontInfo) {
this.fontInfo = fontInfo;
}
- /**
- * Set up the font info
- *
- * @param inFontInfo font info to set up
- */
- public void setupFontInfo(FontInfo inFontInfo) {
- setFontInfo(inFontInfo);
+ /** {@inheritDoc} */
+ public void setDefaultFontInfo() {
FontManager fontManager = getUserAgent().getFactory().getFontManager();
FontCollection[] fontCollections = new FontCollection[] {
- new Base14FontCollection(fontManager.isBase14KerningEnabled()),
- new CustomFontCollection(getFontResolver(), getFontList())
+ new Base14FontCollection(fontManager.isBase14KerningEnabled())
};
- fontManager.setup(getFontInfo(), fontCollections);
+
+ FontInfo fi = new FontInfo();
+ fi.setEventListener(new FontEventAdapter(getUserAgent().getEventBroadcaster()));
+ fontManager.setup(fi, fontCollections);
+ setFontInfo(fi);
}
/** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java b/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java
index bb226dd0c..4336b0bf9 100644
--- a/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java
+++ b/src/java/org/apache/fop/render/intermediate/AbstractXMLWritingIFPainter.java
@@ -37,6 +37,8 @@ import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
+import org.apache.fop.fonts.FontInfo;
+
/**
* Abstract base class for XML-writing IFPainter implementations.
*/
@@ -66,6 +68,16 @@ public abstract class AbstractXMLWritingIFPainter extends AbstractIFPainter {
}
}
+ /** {@inheritDoc} */
+ public void setFontInfo(FontInfo fontInfo) {
+ //nop, not used
+ }
+
+ /** {@inheritDoc} */
+ public void setDefaultFontInfo() {
+ //nop, not used
+ }
+
/**
* Returns the main namespace used for generated XML content.
* @return the main namespace
diff --git a/src/java/org/apache/fop/render/intermediate/IFPainter.java b/src/java/org/apache/fop/render/intermediate/IFPainter.java
index 44e02fe68..66d7a0750 100644
--- a/src/java/org/apache/fop/render/intermediate/IFPainter.java
+++ b/src/java/org/apache/fop/render/intermediate/IFPainter.java
@@ -28,6 +28,7 @@ import java.awt.geom.AffineTransform;
import javax.xml.transform.Result;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fonts.FontInfo;
/**
* Interface used to paint whole documents layouted by Apache FOP.
@@ -90,6 +91,17 @@ public interface IFPainter {
void setResult(Result result) throws IFException;
/**
+ * Sets the font set to work with.
+ * @param fontInfo the font info object
+ */
+ void setFontInfo(FontInfo fontInfo);
+
+ /**
+ * Sets the default font set (with no custom configuration).
+ */
+ void setDefaultFontInfo();
+
+ /**
* Indicates whether the painter supports to handle the pages in mixed order rather than
* ascending order.
* @return true if out-of-order handling is supported
diff --git a/src/java/org/apache/fop/render/intermediate/IFPainterConfigurator.java b/src/java/org/apache/fop/render/intermediate/IFPainterConfigurator.java
index e42f52665..71a3a484a 100644
--- a/src/java/org/apache/fop/render/intermediate/IFPainterConfigurator.java
+++ b/src/java/org/apache/fop/render/intermediate/IFPainterConfigurator.java
@@ -32,4 +32,11 @@ public interface IFPainterConfigurator {
* @throws FOPException if an error occurs while configuring the object
*/
void configure(IFPainter painter) throws FOPException;
+
+ /**
+ * Sets up the {@code FontInfo} object for the IFPainter.
+ * @param painter the painter instance
+ * @throws FOPException if an error occurs while configuring the object
+ */
+ void setupFontInfo(IFPainter painter) throws FOPException;
}
diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java
index ba0a6c60b..6f85c5801 100644
--- a/src/java/org/apache/fop/render/intermediate/IFParser.java
+++ b/src/java/org/apache/fop/render/intermediate/IFParser.java
@@ -41,6 +41,7 @@ import org.w3c.dom.Document;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.DefaultHandler;
import org.apache.commons.logging.Log;
@@ -49,7 +50,6 @@ import org.apache.commons.logging.LogFactory;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.ElementMappingRegistry;
import org.apache.fop.fo.expr.PropertyException;
-import org.apache.fop.fo.extensions.ExtensionAttachment;
import org.apache.fop.util.ColorUtil;
import org.apache.fop.util.ContentHandlerFactory;
import org.apache.fop.util.ContentHandlerFactoryRegistry;
@@ -167,7 +167,7 @@ public class IFParser implements IFConstants {
delegate.startDocument();
delegate.startElement(uri, localName, qName, attributes);
} else {
- lastAttributes = attributes;
+ lastAttributes = new AttributesImpl(attributes);
boolean handled = true;
if (NAMESPACE.equals(uri)) {
ElementHandler elementHandler = (ElementHandler)elementHandlers.get(localName);
@@ -456,21 +456,13 @@ public class IFParser implements IFConstants {
* Handles objects created by "sub-parsers" that implement the ObjectSource interface.
* An example of object handled here are ExtensionAttachments.
* @param obj the Object to be handled.
+ * @throws SAXException if an error occurs while handling the extension object
*/
- protected void handleExternallyGeneratedObject(Object obj) {
- if (obj instanceof ExtensionAttachment) {
- ExtensionAttachment attachment = (ExtensionAttachment)obj;
- //TODO Implement me
- /*
- if (this.currentPageViewport == null) {
- this.treeModel.handleOffDocumentItem(
- new OffDocumentExtensionAttachment(attachment));
- } else {
- this.currentPageViewport.addExtensionAttachment(attachment);
- }
- */
- } else {
- log.warn("Don't know how to handle externally generated object: " + obj);
+ protected void handleExternallyGeneratedObject(Object obj) throws SAXException {
+ try {
+ painter.handleExtensionObject(obj);
+ } catch (IFException ife) {
+ handleIFException(ife);
}
}
diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
index c4243a86a..8df052663 100644
--- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java
+++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
@@ -165,10 +165,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
this.painter = new IFSerializer();
}
this.painter.setUserAgent(getUserAgent());
- if (this.painter instanceof AbstractBinaryWritingIFPainter) {
- //TODO THIS IS UGLY. FIX ME!!!
- ((AbstractBinaryWritingIFPainter)this.painter).setFontInfo(fontInfo);
- }
+ this.painter.setFontInfo(fontInfo);
this.painter.setResult(result);
}
super.startRenderer(null);
diff --git a/src/java/org/apache/fop/render/pdf/PDFPainter.java b/src/java/org/apache/fop/render/pdf/PDFPainter.java
index 8d1b80c28..ec83db707 100644
--- a/src/java/org/apache/fop/render/pdf/PDFPainter.java
+++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java
@@ -30,6 +30,8 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xmlgraphics.xmp.Metadata;
+
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.fo.extensions.xmp.XMPMetadata;
@@ -423,6 +425,9 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
}
private Typeface getTypeface(String fontName) {
+ if (fontName == null) {
+ throw new NullPointerException("fontName must not be null");
+ }
Typeface tf = (Typeface) fontInfo.getFonts().get(fontName);
if (tf instanceof LazyFont) {
tf = ((LazyFont)tf).getRealFont();
@@ -528,6 +533,9 @@ public class PDFPainter extends AbstractBinaryWritingIFPainter {
public void handleExtensionObject(Object extension) throws IFException {
if (extension instanceof XMPMetadata) {
pdfUtil.renderXMPMetadata((XMPMetadata)extension);
+ } else if (extension instanceof Metadata) {
+ XMPMetadata wrapper = new XMPMetadata(((Metadata)extension));
+ pdfUtil.renderXMPMetadata(wrapper);
} else {
throw new UnsupportedOperationException(
"Don't know how to handle extension object: " + extension);
diff --git a/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java b/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java
index bee8e1175..2504a4457 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java
@@ -27,10 +27,18 @@ import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.fonts.CustomFontCollection;
+import org.apache.fop.fonts.FontCollection;
+import org.apache.fop.fonts.FontEventAdapter;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontManager;
+import org.apache.fop.fonts.FontResolver;
+import org.apache.fop.fonts.base14.Base14FontCollection;
import org.apache.fop.pdf.PDFAMode;
import org.apache.fop.pdf.PDFEncryptionParams;
import org.apache.fop.pdf.PDFFilterList;
import org.apache.fop.pdf.PDFXMode;
+import org.apache.fop.render.DefaultFontResolver;
import org.apache.fop.render.PrintRendererConfigurator;
import org.apache.fop.render.Renderer;
import org.apache.fop.render.intermediate.IFPainter;
@@ -141,17 +149,6 @@ public class PDFRendererConfigurator extends PrintRendererConfigurator
}
}
- public void configure(IFPainter painter) throws FOPException {
- Configuration cfg = super.getRendererConfig(painter.getMimeType());
- if (cfg != null) {
- PDFPainter pdfPainter = (PDFPainter)painter;
- PDFRenderingUtil pdfUtil = pdfPainter.getPDFUtil();
- configure(cfg, pdfUtil);
-
- //TODO Configure fonts
- }
- }
-
/**
* Builds a filter map from an Avalon Configuration object.
* @param cfg the Configuration object
@@ -200,4 +197,37 @@ public class PDFRendererConfigurator extends PrintRendererConfigurator
return filterMap;
}
+ // ---=== IFPainter configuration ===---
+
+ /** {@inheritDoc} */
+ public void configure(IFPainter painter) throws FOPException {
+ Configuration cfg = super.getRendererConfig(painter.getMimeType());
+ if (cfg != null) {
+ PDFPainter pdfPainter = (PDFPainter)painter;
+ PDFRenderingUtil pdfUtil = pdfPainter.getPDFUtil();
+ configure(cfg, pdfUtil);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public void setupFontInfo(IFPainter painter) throws FOPException {
+ FontManager fontManager = userAgent.getFactory().getFontManager();
+ List fontCollections = new java.util.ArrayList();
+ fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));
+
+ Configuration cfg = super.getRendererConfig(painter.getMimeType());
+ if (cfg != null) {
+ FontResolver fontResolver = new DefaultFontResolver(userAgent);
+ List fontList = buildFontList(cfg, fontResolver);
+ fontCollections.add(new CustomFontCollection(fontResolver, fontList));
+ }
+
+ FontInfo fontInfo = new FontInfo();
+ fontInfo.setEventListener(new FontEventAdapter(userAgent.getEventBroadcaster()));
+ fontManager.setup(fontInfo,
+ (FontCollection[])fontCollections.toArray(
+ new FontCollection[fontCollections.size()]));
+ painter.setFontInfo(fontInfo);
+ }
+
}