aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r--src/java/org/apache/fop/render/PrintRendererConfigurator.java36
-rw-r--r--src/java/org/apache/fop/render/RendererFactory.java7
-rw-r--r--src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java6
-rw-r--r--src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java6
-rw-r--r--src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandlerMaker.java8
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFParser.java28
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFRenderer.java7
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFSerializer.java11
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFSerializerConfiguration.java80
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFSerializerMaker.java (renamed from src/java/org/apache/fop/render/intermediate/IFRendererMaker.java)27
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFUtil.java35
-rw-r--r--src/java/org/apache/fop/render/intermediate/util/IFConcatenator.java182
-rw-r--r--src/java/org/apache/fop/render/intermediate/util/IFDocumentHandlerProxy.java187
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java6
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java6
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java41
-rw-r--r--src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java6
-rw-r--r--src/java/org/apache/fop/render/ps/PSRendererConfigurator.java32
18 files changed, 487 insertions, 224 deletions
diff --git a/src/java/org/apache/fop/render/PrintRendererConfigurator.java b/src/java/org/apache/fop/render/PrintRendererConfigurator.java
index e01750b99..f1a76be1d 100644
--- a/src/java/org/apache/fop/render/PrintRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/PrintRendererConfigurator.java
@@ -41,9 +41,11 @@ import org.apache.xmlgraphics.util.ClasspathResource;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FopFactory;
+import org.apache.fop.fonts.CustomFontCollection;
import org.apache.fop.fonts.EmbedFontInfo;
import org.apache.fop.fonts.EncodingMode;
import org.apache.fop.fonts.FontCache;
+import org.apache.fop.fonts.FontCollection;
import org.apache.fop.fonts.FontEventAdapter;
import org.apache.fop.fonts.FontEventListener;
import org.apache.fop.fonts.FontInfo;
@@ -53,13 +55,16 @@ import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.FontUtil;
import org.apache.fop.fonts.autodetect.FontFileFinder;
import org.apache.fop.fonts.autodetect.FontInfoFinder;
+import org.apache.fop.fonts.base14.Base14FontCollection;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
import org.apache.fop.util.LogUtil;
/**
* Base Print renderer configurator (mostly handles font configuration)
*/
public class PrintRendererConfigurator extends AbstractRendererConfigurator
- implements RendererConfigurator {
+ implements RendererConfigurator, IFDocumentHandlerConfigurator {
/** logger instance */
protected static Log log = LogFactory.getLog(PrintRendererConfigurator.class);
@@ -452,4 +457,33 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator
return embedFontInfo;
}
+ // ---=== IFDocumentHandler configuration ===---
+
+ /** {@inheritDoc} */
+ public void configure(IFDocumentHandler documentHandler) throws FOPException {
+ //nop
+ }
+
+ /** {@inheritDoc} */
+ public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
+ throws FOPException {
+ FontManager fontManager = userAgent.getFactory().getFontManager();
+ List fontCollections = new java.util.ArrayList();
+ fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));
+
+ Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
+ if (cfg != null) {
+ FontResolver fontResolver = new DefaultFontResolver(userAgent);
+ FontEventListener listener = new FontEventAdapter(
+ userAgent.getEventBroadcaster());
+ List fontList = buildFontList(cfg, fontResolver, listener);
+ fontCollections.add(new CustomFontCollection(fontResolver, fontList));
+ }
+
+ fontManager.setup(fontInfo,
+ (FontCollection[])fontCollections.toArray(
+ new FontCollection[fontCollections.size()]));
+ documentHandler.setFontInfo(fontInfo);
+ }
+
}
diff --git a/src/java/org/apache/fop/render/RendererFactory.java b/src/java/org/apache/fop/render/RendererFactory.java
index 2b26e4881..b12664818 100644
--- a/src/java/org/apache/fop/render/RendererFactory.java
+++ b/src/java/org/apache/fop/render/RendererFactory.java
@@ -287,7 +287,8 @@ public class RendererFactory {
} else {
AbstractRendererMaker rendMaker = getRendererMaker(outputFormat);
AbstractIFDocumentHandlerMaker documentHandlerMaker = null;
- boolean outputStreamMissing = (userAgent.getRendererOverride() == null);
+ boolean outputStreamMissing = (userAgent.getRendererOverride() == null)
+ && (userAgent.getDocumentHandlerOverride() == null);
if (rendMaker == null) {
documentHandlerMaker = getDocumentHandlerMaker(outputFormat);
if (documentHandlerMaker != null) {
@@ -299,6 +300,7 @@ public class RendererFactory {
}
if (userAgent.getRendererOverride() != null
|| rendMaker != null
+ || userAgent.getDocumentHandlerOverride() != null
|| documentHandlerMaker != null) {
if (outputStreamMissing) {
throw new FOPException(
@@ -418,7 +420,8 @@ public class RendererFactory {
Iterator providers = Service.providers(IFDocumentHandler.class);
if (providers != null) {
while (providers.hasNext()) {
- AbstractIFDocumentHandlerMaker maker = (AbstractIFDocumentHandlerMaker)providers.next();
+ AbstractIFDocumentHandlerMaker maker
+ = (AbstractIFDocumentHandlerMaker)providers.next();
try {
if (log.isDebugEnabled()) {
log.debug("Dynamically adding maker for IFDocumentHandler: "
diff --git a/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java b/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java
index b788a1011..e0b13d979 100644
--- a/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java
+++ b/src/java/org/apache/fop/render/afp/AFPDocumentHandlerMaker.java
@@ -24,7 +24,6 @@ import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
-import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/**
* Intermediate format document handler factory for AFP output.
@@ -52,9 +51,4 @@ public class AFPDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
return MIMES;
}
- /** {@inheritDoc} */
- public IFDocumentHandlerConfigurator getConfigurator(FOUserAgent userAgent) {
- return new AFPRendererConfigurator(userAgent);
- }
-
}
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java b/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java
index 230ff49a3..4a6c9cbb7 100644
--- a/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java
+++ b/src/java/org/apache/fop/render/bitmap/TIFFDocumentHandlerMaker.java
@@ -24,7 +24,6 @@ import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
-import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/**
* Document handler factory for TIFF output.
@@ -51,9 +50,4 @@ public class TIFFDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
return MIMES;
}
- /** {@inheritDoc} */
- public IFDocumentHandlerConfigurator getConfigurator(FOUserAgent userAgent) {
- return new TIFFRendererConfigurator(userAgent);
- }
-
}
diff --git a/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandlerMaker.java b/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandlerMaker.java
index f163c3776..7162a976c 100644
--- a/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandlerMaker.java
+++ b/src/java/org/apache/fop/render/intermediate/AbstractIFDocumentHandlerMaker.java
@@ -45,14 +45,6 @@ public abstract class AbstractIFDocumentHandlerMaker {
public abstract String[] getSupportedMimeTypes();
/**
- * Returns a configurator object that can be used to
- * configure the document handler.
- * @param userAgent the user agent
- * @return a configurator object that can be used to configure the document handler
- */
- public abstract IFDocumentHandlerConfigurator getConfigurator(FOUserAgent userAgent);
-
- /**
* Indicates whether a specific MIME type is supported by this document handler.
* @param mimeType the MIME type (ex. "application/pdf")
* @return true if the MIME type is supported
diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java
index 61d1838bc..92e71d105 100644
--- a/src/java/org/apache/fop/render/intermediate/IFParser.java
+++ b/src/java/org/apache/fop/render/intermediate/IFParser.java
@@ -79,15 +79,29 @@ public class IFParser implements IFConstants {
* @param documentHandler the intermediate format document handler used to process the IF events
* @param userAgent the user agent
* @throws TransformerException if an error occurs while parsing the area tree XML
+ * @throws IFException if an IF-related error occurs inside the target document handler
*/
public void parse(Source src, IFDocumentHandler documentHandler, FOUserAgent userAgent)
- throws TransformerException {
- Transformer transformer = tFactory.newTransformer();
- transformer.setErrorListener(new DefaultErrorListener(log));
-
- SAXResult res = new SAXResult(getContentHandler(documentHandler, userAgent));
-
- transformer.transform(src, res);
+ throws TransformerException, IFException {
+ try {
+ Transformer transformer = tFactory.newTransformer();
+ transformer.setErrorListener(new DefaultErrorListener(log));
+
+ SAXResult res = new SAXResult(getContentHandler(documentHandler, userAgent));
+
+ transformer.transform(src, res);
+ } catch (TransformerException te) {
+ //Unpack original IFException if applicable
+ if (te.getCause() instanceof SAXException) {
+ SAXException se = (SAXException)te.getCause();
+ if (se.getCause() instanceof IFException) {
+ throw (IFException)se.getCause();
+ }
+ } else if (te.getCause() instanceof IFException) {
+ throw (IFException)te.getCause();
+ }
+ throw te;
+ }
}
/**
diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
index 03ec6a4c0..558ddfab8 100644
--- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java
+++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java
@@ -176,12 +176,7 @@ public class IFRenderer extends AbstractPathOrientedRenderer {
if (this.documentHandler == null) {
this.documentHandler = createDefaultDocumentHandler();
}
- IFDocumentHandlerConfigurator configurator = this.documentHandler.getConfigurator();
- if (configurator != null) {
- configurator.setupFontInfo(documentHandler, inFontInfo);
- } else {
- this.documentHandler.setDefaultFontInfo(inFontInfo);
- }
+ IFUtil.setupFonts(this.documentHandler, inFontInfo);
this.fontInfo = inFontInfo;
}
diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializer.java b/src/java/org/apache/fop/render/intermediate/IFSerializer.java
index e4aa86e9e..cccef80c6 100644
--- a/src/java/org/apache/fop/render/intermediate/IFSerializer.java
+++ b/src/java/org/apache/fop/render/intermediate/IFSerializer.java
@@ -38,6 +38,7 @@ import org.apache.xmlgraphics.util.QName;
import org.apache.xmlgraphics.util.XMLizable;
import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.render.PrintRendererConfigurator;
import org.apache.fop.render.RenderingContext;
import org.apache.fop.render.intermediate.extensions.AbstractAction;
import org.apache.fop.render.intermediate.extensions.Bookmark;
@@ -91,7 +92,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler
if (this.mimicHandler != null) {
return getMimickedDocumentHandler().getConfigurator();
} else {
- return new IFSerializerConfiguration(getUserAgent());
+ return new PrintRendererConfigurator(getUserAgent());
}
}
@@ -128,12 +129,16 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler
/** {@inheritDoc} */
public void setFontInfo(FontInfo fontInfo) {
- //nop, not used
+ if (this.mimicHandler != null) {
+ this.mimicHandler.setFontInfo(fontInfo);
+ }
}
/** {@inheritDoc} */
public void setDefaultFontInfo(FontInfo fontInfo) {
- //nop, not used
+ if (this.mimicHandler != null) {
+ this.mimicHandler.setDefaultFontInfo(fontInfo);
+ }
}
/** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializerConfiguration.java b/src/java/org/apache/fop/render/intermediate/IFSerializerConfiguration.java
deleted file mode 100644
index 8f47c5511..000000000
--- a/src/java/org/apache/fop/render/intermediate/IFSerializerConfiguration.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.render.intermediate;
-
-import java.util.List;
-
-import org.apache.avalon.framework.configuration.Configuration;
-
-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.FontEventListener;
-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;
-import org.apache.fop.render.PrintRendererConfigurator;
-
-/**
- * Configurator for the IFSerializer.
- */
-public class IFSerializerConfiguration extends PrintRendererConfigurator
- implements IFDocumentHandlerConfigurator {
-
- /**
- * Default constructor
- * @param userAgent user agent
- */
- public IFSerializerConfiguration(FOUserAgent userAgent) {
- super(userAgent);
- }
-
- /** {@inheritDoc} */
- public void configure(IFDocumentHandler documentHandler) throws FOPException {
- //nothing to do here
- }
-
- /** {@inheritDoc} */
- public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
- throws FOPException {
- FontManager fontManager = userAgent.getFactory().getFontManager();
- List fontCollections = new java.util.ArrayList();
- fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));
-
- Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
- if (cfg != null) {
- FontResolver fontResolver = new DefaultFontResolver(userAgent);
- FontEventListener listener = new FontEventAdapter(
- userAgent.getEventBroadcaster());
- List fontList = buildFontList(cfg, fontResolver, listener);
- fontCollections.add(new CustomFontCollection(fontResolver, fontList));
- }
-
- fontManager.setup(fontInfo,
- (FontCollection[])fontCollections.toArray(
- new FontCollection[fontCollections.size()]));
- documentHandler.setFontInfo(fontInfo);
- }
-
-}
diff --git a/src/java/org/apache/fop/render/intermediate/IFRendererMaker.java b/src/java/org/apache/fop/render/intermediate/IFSerializerMaker.java
index eb70f3028..699fd0549 100644
--- a/src/java/org/apache/fop/render/intermediate/IFRendererMaker.java
+++ b/src/java/org/apache/fop/render/intermediate/IFSerializerMaker.java
@@ -21,36 +21,27 @@ package org.apache.fop.render.intermediate;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.render.AbstractRendererMaker;
-import org.apache.fop.render.PrintRendererConfigurator;
-import org.apache.fop.render.Renderer;
-import org.apache.fop.render.RendererConfigurator;
/**
- * RendererMaker for the Intermediate Format Renderer.
+ * Intermediate format document handler factory for intermediate format XML output.
*/
-public class IFRendererMaker extends AbstractRendererMaker {
+public class IFSerializerMaker extends AbstractIFDocumentHandlerMaker {
- private static final String[] MIMES = new String[] {MimeConstants.MIME_FOP_IF};
-
- /**{@inheritDoc} */
- public Renderer makeRenderer(FOUserAgent userAgent) {
- return new IFRenderer();
- }
-
- /**{@inheritDoc} */
- public RendererConfigurator getConfigurator(FOUserAgent userAgent) {
- return new PrintRendererConfigurator(userAgent);
+ /** {@inheritDoc} */
+ public IFDocumentHandler makeIFDocumentHandler(FOUserAgent ua) {
+ IFSerializer handler = new IFSerializer();
+ handler.setContext(new IFContext(ua));
+ return handler;
}
/** {@inheritDoc} */
public boolean needsOutputStream() {
- return false;
+ return true;
}
/** {@inheritDoc} */
public String[] getSupportedMimeTypes() {
- return MIMES;
+ return new String[] {MimeConstants.MIME_FOP_IF};
}
}
diff --git a/src/java/org/apache/fop/render/intermediate/IFUtil.java b/src/java/org/apache/fop/render/intermediate/IFUtil.java
index 513e1c786..2654eb2a3 100644
--- a/src/java/org/apache/fop/render/intermediate/IFUtil.java
+++ b/src/java/org/apache/fop/render/intermediate/IFUtil.java
@@ -22,6 +22,9 @@ package org.apache.fop.render.intermediate;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.fonts.FontInfo;
import org.apache.fop.util.DecimalFormatCache;
/**
@@ -137,4 +140,36 @@ public class IFUtil {
return sb.toString();
}
+ /**
+ * Sets up the fonts on a document handler. If the document handler provides a configurator
+ * object the configuration from the {@link FopFactory} will be used. Otherwise,
+ * a default font configuration will be set up.
+ * @param documentHandler the document handler
+ * @param fontInfo the font info object (may be null)
+ * @throws FOPException if an error occurs while setting up the fonts
+ */
+ public static void setupFonts(IFDocumentHandler documentHandler, FontInfo fontInfo)
+ throws FOPException {
+ if (fontInfo == null) {
+ fontInfo = new FontInfo();
+ }
+ IFDocumentHandlerConfigurator configurator = documentHandler.getConfigurator();
+ if (configurator != null) {
+ configurator.setupFontInfo(documentHandler, fontInfo);
+ } else {
+ documentHandler.setDefaultFontInfo(fontInfo);
+ }
+ }
+
+ /**
+ * Sets up the fonts on a document handler. If the document handler provides a configurator
+ * object the configuration from the {@link FopFactory} will be used. Otherwise,
+ * a default font configuration will be set up.
+ * @param documentHandler the document handler
+ * @throws FOPException if an error occurs while setting up the fonts
+ */
+ public static void setupFonts(IFDocumentHandler documentHandler) throws FOPException {
+ setupFonts(documentHandler, null);
+ }
+
}
diff --git a/src/java/org/apache/fop/render/intermediate/util/IFConcatenator.java b/src/java/org/apache/fop/render/intermediate/util/IFConcatenator.java
new file mode 100644
index 000000000..4b0a3fe68
--- /dev/null
+++ b/src/java/org/apache/fop/render/intermediate/util/IFConcatenator.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.intermediate.util;
+
+
+import java.awt.Dimension;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+import org.apache.xmlgraphics.xmp.Metadata;
+
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFDocumentNavigationHandler;
+import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.IFParser;
+
+/**
+ * This class allows to concatenate multiple intermediate format files to a single output file
+ * in the final format. It is based on the SAX API and is therefore very fast and does not
+ * require to load the individual documents into memory as DOM documents, for example.
+ * <p>
+ * Note: This class will filter/ignore any document navigation events. Support for this may be
+ * added later.
+ */
+public class IFConcatenator {
+
+ private IFDocumentHandler targetHandler;
+
+ private int nextPageIndex = 0;
+
+ /**
+ * Creates a new IF concatenator.
+ * @param targetHandler the target document handler
+ * @param metadata the metadata object for the generated file (may be null)
+ * @throws IFException if an IF-related error occurs
+ */
+ public IFConcatenator(IFDocumentHandler targetHandler, Metadata metadata) throws IFException {
+ this.targetHandler = targetHandler;
+ startDocument(metadata);
+ }
+
+ private void startDocument(Metadata metadata) throws IFException {
+ this.targetHandler.startDocument();
+ this.targetHandler.startDocumentHeader();
+ if (metadata != null) {
+ this.targetHandler.handleExtensionObject(metadata);
+ }
+ this.targetHandler.endDocumentHeader();
+ }
+
+ private void endDocument() throws IFException {
+ this.targetHandler.startPageTrailer();
+ this.targetHandler.endPageTrailer();
+ this.targetHandler.endDocument();
+ }
+
+ /**
+ * Returns the target document handler.
+ * @return the target document handler
+ */
+ protected IFDocumentHandler getTargetHandler() {
+ return this.targetHandler;
+ }
+
+ /**
+ * Properly finishes the current output file by creating an empty document trailer and calling
+ * {@link IFDocumentHandler#endDocument()}.
+ * @throws IFException if an IF-related error occurs
+ */
+ public void finish() throws IFException {
+ endDocument();
+ }
+
+ /**
+ * Appends another intermediate format document to the current output file. All document-level
+ * content (i.e. the document header and trailer) is ignored. This method shall not be called
+ * after {@link #finish()} has been called.
+ * @param src the JAXP Source identifying the input document
+ * @throws TransformerException if an XML-related exception occurs during
+ * @throws IFException if an IF-related error occurs
+ */
+ public void appendDocument(Source src) throws TransformerException, IFException {
+ IFParser parser = new IFParser();
+ parser.parse(src, new IFPageSequenceFilter(getTargetHandler()),
+ getTargetHandler().getContext().getUserAgent());
+ }
+
+ private class IFPageSequenceFilter extends IFDocumentHandlerProxy {
+
+ private boolean inPageSequence = false;
+
+ public IFPageSequenceFilter(IFDocumentHandler delegate) {
+ super(delegate);
+ }
+
+ /** {@inheritDoc} */
+ public void startDocument() throws IFException {
+ //ignore
+ }
+
+ /** {@inheritDoc} */
+ public void startDocumentHeader() throws IFException {
+ //ignore
+ }
+
+ /** {@inheritDoc} */
+ public void endDocumentHeader() throws IFException {
+ //ignore
+ }
+
+ /** {@inheritDoc} */
+ public void startPageSequence(String id) throws IFException {
+ assert !this.inPageSequence;
+ this.inPageSequence = true;
+
+ super.startPageSequence(id);
+ }
+
+ /** {@inheritDoc} */
+ public void startPage(int index, String name, String pageMasterName, Dimension size)
+ throws IFException {
+ //Adjust page indices
+ super.startPage(nextPageIndex, name, pageMasterName, size);
+ nextPageIndex++;
+ }
+
+ /** {@inheritDoc} */
+ public void endPageSequence() throws IFException {
+ super.endPageSequence();
+
+ assert this.inPageSequence;
+ this.inPageSequence = false;
+ }
+
+ /** {@inheritDoc} */
+ public void startDocumentTrailer() throws IFException {
+ //ignore
+ }
+
+ /** {@inheritDoc} */
+ public void endDocumentTrailer() throws IFException {
+ //ignore
+ }
+
+ /** {@inheritDoc} */
+ public void endDocument() throws IFException {
+ //ignore
+ }
+
+ /** {@inheritDoc} */
+ public void handleExtensionObject(Object extension) throws IFException {
+ if (inPageSequence) {
+ //Only pass through when inside page-sequence
+ super.handleExtensionObject(extension);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public IFDocumentNavigationHandler getDocumentNavigationHandler() {
+ return null; //Document Navigation is filtered!!!
+ }
+
+ }
+}
diff --git a/src/java/org/apache/fop/render/intermediate/util/IFDocumentHandlerProxy.java b/src/java/org/apache/fop/render/intermediate/util/IFDocumentHandlerProxy.java
new file mode 100644
index 000000000..3d89e812e
--- /dev/null
+++ b/src/java/org/apache/fop/render/intermediate/util/IFDocumentHandlerProxy.java
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.intermediate.util;
+
+import java.awt.Dimension;
+
+import javax.xml.transform.Result;
+
+import org.apache.fop.fonts.FontInfo;
+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.IFDocumentNavigationHandler;
+import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.IFPainter;
+
+/**
+ * This class is a simple proxy that delegates all method calls to another {@link IFDocumentHandler}
+ * instance.
+ */
+public class IFDocumentHandlerProxy implements IFDocumentHandler {
+
+ /** the delegate IFDocumentHandler */
+ protected IFDocumentHandler delegate;
+
+ /**
+ * Creates a new proxy instance.
+ * @param delegate the delegate instance
+ */
+ public IFDocumentHandlerProxy(IFDocumentHandler delegate) {
+ this.delegate = delegate;
+ }
+
+ /** {@inheritDoc} */
+ public boolean supportsPagesOutOfOrder() {
+ return this.delegate.supportsPagesOutOfOrder();
+ }
+
+ /** {@inheritDoc} */
+ public String getMimeType() {
+ return this.delegate.getMimeType();
+ }
+
+ /** {@inheritDoc} */
+ public void setContext(IFContext context) {
+ this.delegate.setContext(context);
+ }
+
+ /** {@inheritDoc} */
+ public IFContext getContext() {
+ return this.delegate.getContext();
+ }
+
+ /** {@inheritDoc} */
+ public FontInfo getFontInfo() {
+ return this.delegate.getFontInfo();
+ }
+
+ /** {@inheritDoc} */
+ public void setFontInfo(FontInfo fontInfo) {
+ this.delegate.setFontInfo(fontInfo);
+ }
+
+ /** {@inheritDoc} */
+ public void setDefaultFontInfo(FontInfo fontInfo) {
+ this.delegate.setDefaultFontInfo(fontInfo);
+ }
+
+ /** {@inheritDoc} */
+ public IFDocumentHandlerConfigurator getConfigurator() {
+ return this.delegate.getConfigurator();
+ }
+
+ /** {@inheritDoc} */
+ public IFDocumentNavigationHandler getDocumentNavigationHandler() {
+ return this.delegate.getDocumentNavigationHandler();
+ }
+
+ /** {@inheritDoc} */
+ public void setResult(Result result) throws IFException {
+ this.delegate.setResult(result);
+ }
+
+ /** {@inheritDoc} */
+ public void startDocument() throws IFException {
+ this.delegate.startDocument();
+ }
+
+ /** {@inheritDoc} */
+ public void startDocumentHeader() throws IFException {
+ this.delegate.startDocumentHeader();
+ }
+
+ /** {@inheritDoc} */
+ public void endDocumentHeader() throws IFException {
+ this.delegate.endDocumentHeader();
+ }
+
+ /** {@inheritDoc} */
+ public void startPageSequence(String id) throws IFException {
+ this.delegate.startPageSequence(id);
+ }
+
+ /** {@inheritDoc} */
+ public void startPage(int index, String name, String pageMasterName, Dimension size)
+ throws IFException {
+ this.delegate.startPage(index, name, pageMasterName, size);
+ }
+
+ /** {@inheritDoc} */
+ public void startPageHeader() throws IFException {
+ this.delegate.startPageHeader();
+ }
+
+ /** {@inheritDoc} */
+ public void endPageHeader() throws IFException {
+ this.delegate.endPageHeader();
+ }
+
+ /** {@inheritDoc} */
+ public IFPainter startPageContent() throws IFException {
+ return this.delegate.startPageContent();
+ }
+
+ /** {@inheritDoc} */
+ public void endPageContent() throws IFException {
+ this.delegate.endPageContent();
+ }
+
+ /** {@inheritDoc} */
+ public void startPageTrailer() throws IFException {
+ this.delegate.startPageTrailer();
+ }
+
+ /** {@inheritDoc} */
+ public void endPageTrailer() throws IFException {
+ this.delegate.endPageTrailer();
+ }
+
+ /** {@inheritDoc} */
+ public void endPage() throws IFException {
+ this.delegate.endPage();
+ }
+
+ /** {@inheritDoc} */
+ public void endPageSequence() throws IFException {
+ this.delegate.endPageSequence();
+ }
+
+ /** {@inheritDoc} */
+ public void startDocumentTrailer() throws IFException {
+ this.delegate.startDocumentTrailer();
+ }
+
+ /** {@inheritDoc} */
+ public void endDocumentTrailer() throws IFException {
+ this.delegate.endDocumentTrailer();
+ }
+
+ /** {@inheritDoc} */
+ public void endDocument() throws IFException {
+ this.delegate.endDocument();
+ }
+
+ /** {@inheritDoc} */
+ public void handleExtensionObject(Object extension) throws IFException {
+ this.delegate.handleExtensionObject(extension);
+ }
+
+} \ No newline at end of file
diff --git a/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java b/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java
index 62c2a4e77..db47c9712 100644
--- a/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java
+++ b/src/java/org/apache/fop/render/pcl/PCLDocumentHandlerMaker.java
@@ -24,7 +24,6 @@ import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
-import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/**
* Document handler factory for PCL output.
@@ -51,9 +50,4 @@ public class PCLDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
return MIMES;
}
- /** {@inheritDoc} */
- public IFDocumentHandlerConfigurator getConfigurator(FOUserAgent userAgent) {
- return new PCLRendererConfigurator(userAgent);
- }
-
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java b/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java
index fa0a49ee7..532b50f80 100644
--- a/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java
+++ b/src/java/org/apache/fop/render/pdf/PDFDocumentHandlerMaker.java
@@ -24,7 +24,6 @@ import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
-import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/**
* Intermediate format document handler factory for PDF output.
@@ -51,9 +50,4 @@ public class PDFDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
return MIMES;
}
- /** {@inheritDoc} */
- public IFDocumentHandlerConfigurator getConfigurator(FOUserAgent userAgent) {
- return new PDFRendererConfigurator(userAgent);
- }
-
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java b/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java
index fccba1c25..f3511298e 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java
@@ -27,34 +27,23 @@ 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.FontEventListener;
-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.IFDocumentHandler;
-import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
import org.apache.fop.util.LogUtil;
/**
* PDF renderer configurator.
*/
-public class PDFRendererConfigurator extends PrintRendererConfigurator
- implements IFDocumentHandlerConfigurator {
+public class PDFRendererConfigurator extends PrintRendererConfigurator {
/**
* Default constructor
- *
+ *
* @param userAgent user agent
*/
public PDFRendererConfigurator(FOUserAgent userAgent) {
@@ -65,7 +54,7 @@ public class PDFRendererConfigurator extends PrintRendererConfigurator
* Configure the PDF renderer.
* Get the configuration to be used for pdf stream filters,
* fonts etc.
- *
+ *
* @param renderer pdf renderer
* @throws FOPException fop exception
*/
@@ -155,7 +144,7 @@ public class PDFRendererConfigurator extends PrintRendererConfigurator
/**
* Builds a filter map from an Avalon Configuration object.
- *
+ *
* @param cfg the Configuration object
* @return Map the newly built filter map
* @throws ConfigurationException if a filter list is defined twice
@@ -214,26 +203,4 @@ public class PDFRendererConfigurator extends PrintRendererConfigurator
}
}
- /** {@inheritDoc} */
- public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
- throws FOPException {
- FontManager fontManager = userAgent.getFactory().getFontManager();
- List fontCollections = new java.util.ArrayList();
- fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));
-
- Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
- if (cfg != null) {
- FontResolver fontResolver = new DefaultFontResolver(userAgent);
- FontEventListener listener = new FontEventAdapter(
- userAgent.getEventBroadcaster());
- List fontList = buildFontList(cfg, fontResolver, listener);
- fontCollections.add(new CustomFontCollection(fontResolver, fontList));
- }
-
- fontManager.setup(fontInfo,
- (FontCollection[])fontCollections.toArray(
- new FontCollection[fontCollections.size()]));
- documentHandler.setFontInfo(fontInfo);
- }
-
}
diff --git a/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java b/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java
index e105ac836..eb085c0a4 100644
--- a/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java
+++ b/src/java/org/apache/fop/render/ps/PSDocumentHandlerMaker.java
@@ -24,7 +24,6 @@ import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractIFDocumentHandlerMaker;
import org.apache.fop.render.intermediate.IFContext;
import org.apache.fop.render.intermediate.IFDocumentHandler;
-import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator;
/**
* Intermediate format document handler factory for PostScript output.
@@ -52,9 +51,4 @@ public class PSDocumentHandlerMaker extends AbstractIFDocumentHandlerMaker {
return MIMES;
}
- /** {@inheritDoc} */
- public IFDocumentHandlerConfigurator getConfigurator(FOUserAgent userAgent) {
- return new PSRendererConfigurator(userAgent);
- }
-
}
diff --git a/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java b/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java
index 7ea4fe547..0f880a928 100644
--- a/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/ps/PSRendererConfigurator.java
@@ -19,23 +19,12 @@
package org.apache.fop.render.ps;
-import java.util.List;
-
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.xmlgraphics.ps.PSGenerator;
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.FontEventListener;
-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;
import org.apache.fop.render.PrintRendererConfigurator;
import org.apache.fop.render.Renderer;
import org.apache.fop.render.intermediate.IFDocumentHandler;
@@ -99,25 +88,4 @@ public class PSRendererConfigurator extends PrintRendererConfigurator
}
- /** {@inheritDoc} */
- public void setupFontInfo(IFDocumentHandler documentHandler, FontInfo fontInfo)
- throws FOPException {
- FontManager fontManager = userAgent.getFactory().getFontManager();
- List fontCollections = new java.util.ArrayList();
- fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));
-
- Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
- if (cfg != null) {
- FontResolver fontResolver = new DefaultFontResolver(userAgent);
- FontEventListener listener = new FontEventAdapter(
- userAgent.getEventBroadcaster());
- List fontList = buildFontList(cfg, fontResolver, listener);
- fontCollections.add(new CustomFontCollection(fontResolver, fontList));
- }
-
- fontManager.setup(fontInfo,
- (FontCollection[])fontCollections.toArray(
- new FontCollection[fontCollections.size()]));
- documentHandler.setFontInfo(fontInfo);
- }
}