aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-03-19 10:20:31 +0000
committerJeremias Maerki <jeremias@apache.org>2009-03-19 10:20:31 +0000
commit3c5ac0297c39c7cf7280afa95155dbea07e67d4c (patch)
tree5cba55c8324846a88d97c67fcad9b8b53d67806a
parent633d03c8966b3656e12d5e5727c09071a3fd14c4 (diff)
downloadxmlgraphics-fop-3c5ac0297c39c7cf7280afa95155dbea07e67d4c.tar.gz
xmlgraphics-fop-3c5ac0297c39c7cf7280afa95155dbea07e67d4c.zip
Bugfix: IFSerializer's mimicking feature didn't work properly. The wrong configuration got selected.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@755894 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/apps/FopFactory.java8
-rw-r--r--src/java/org/apache/fop/render/PrintRendererConfigurator.java3
-rw-r--r--src/java/org/apache/fop/render/intermediate/IFUtil.java17
-rw-r--r--test/java/org/apache/fop/StandardTestSuite.java2
-rw-r--r--test/java/org/apache/fop/intermediate/IFMimickingTestCase.java120
-rw-r--r--test/test-no-xml-metrics.xconf26
6 files changed, 172 insertions, 4 deletions
diff --git a/src/java/org/apache/fop/apps/FopFactory.java b/src/java/org/apache/fop/apps/FopFactory.java
index 96c22f964..9ddc164c5 100644
--- a/src/java/org/apache/fop/apps/FopFactory.java
+++ b/src/java/org/apache/fop/apps/FopFactory.java
@@ -264,9 +264,11 @@ public class FopFactory implements ImageContext {
*/
public Fop newFop(FOUserAgent userAgent) throws FOPException {
if (userAgent.getRendererOverride() == null
- && userAgent.getFOEventHandlerOverride() == null) {
- throw new IllegalStateException("Either the overriding renderer or the overriding"
- + " FOEventHandler must be set when this factory method is used!");
+ && userAgent.getFOEventHandlerOverride() == null
+ && userAgent.getDocumentHandlerOverride() == null) {
+ throw new IllegalStateException("An overriding renderer,"
+ + " FOEventHandler or IFDocumentHandler must be set on the user agent"
+ + " when this factory method is used!");
}
return newFop(null, userAgent);
}
diff --git a/src/java/org/apache/fop/render/PrintRendererConfigurator.java b/src/java/org/apache/fop/render/PrintRendererConfigurator.java
index f1a76be1d..3f5a2eb39 100644
--- a/src/java/org/apache/fop/render/PrintRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/PrintRendererConfigurator.java
@@ -58,6 +58,7 @@ 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.render.intermediate.IFUtil;
import org.apache.fop.util.LogUtil;
/**
@@ -471,7 +472,7 @@ public class PrintRendererConfigurator extends AbstractRendererConfigurator
List fontCollections = new java.util.ArrayList();
fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));
- Configuration cfg = super.getRendererConfig(documentHandler.getMimeType());
+ Configuration cfg = super.getRendererConfig(IFUtil.getEffectiveMIMEType(documentHandler));
if (cfg != null) {
FontResolver fontResolver = new DefaultFontResolver(userAgent);
FontEventListener listener = new FontEventAdapter(
diff --git a/src/java/org/apache/fop/render/intermediate/IFUtil.java b/src/java/org/apache/fop/render/intermediate/IFUtil.java
index 2654eb2a3..58399f3ac 100644
--- a/src/java/org/apache/fop/render/intermediate/IFUtil.java
+++ b/src/java/org/apache/fop/render/intermediate/IFUtil.java
@@ -172,4 +172,21 @@ public class IFUtil {
setupFonts(documentHandler, null);
}
+ /**
+ * Returns the MIME type of the output format that the given document handler is supposed to
+ * handle. If the document handler is an {@link IFSerializer} it returns the MIME type of the
+ * document handler it is mimicking.
+ * @param documentHandler the document handler
+ * @return the effective MIME type
+ */
+ public static String getEffectiveMIMEType(IFDocumentHandler documentHandler) {
+ if (documentHandler instanceof IFSerializer) {
+ IFDocumentHandler mimic = ((IFSerializer)documentHandler).getMimickedDocumentHandler();
+ if (mimic != null) {
+ return mimic.getMimeType();
+ }
+ }
+ return documentHandler.getMimeType();
+ }
+
}
diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java
index 290b29050..e6a718643 100644
--- a/test/java/org/apache/fop/StandardTestSuite.java
+++ b/test/java/org/apache/fop/StandardTestSuite.java
@@ -25,6 +25,7 @@ import junit.framework.TestSuite;
import org.apache.fop.fonts.TrueTypeAnsiTestCase;
import org.apache.fop.image.loader.batik.ImageLoaderTestCase;
import org.apache.fop.image.loader.batik.ImagePreloaderTestCase;
+import org.apache.fop.intermediate.IFMimickingTestCase;
import org.apache.fop.render.pdf.PDFAConformanceTestCase;
import org.apache.fop.render.pdf.PDFCMapTestCase;
import org.apache.fop.render.pdf.PDFEncodingTestCase;
@@ -54,6 +55,7 @@ public class StandardTestSuite {
suite.addTest(RichTextFormatTestSuite.suite());
suite.addTest(new TestSuite(ImageLoaderTestCase.class));
suite.addTest(new TestSuite(ImagePreloaderTestCase.class));
+ suite.addTest(new TestSuite(IFMimickingTestCase.class));
//$JUnit-END$
return suite;
}
diff --git a/test/java/org/apache/fop/intermediate/IFMimickingTestCase.java b/test/java/org/apache/fop/intermediate/IFMimickingTestCase.java
new file mode 100644
index 000000000..b6b6aebd6
--- /dev/null
+++ b/test/java/org/apache/fop/intermediate/IFMimickingTestCase.java
@@ -0,0 +1,120 @@
+/*
+ * 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.intermediate;
+
+import java.io.File;
+
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.events.Event;
+import org.apache.fop.events.EventFormatter;
+import org.apache.fop.events.EventListener;
+import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFSerializer;
+
+/**
+ * This test checks the correct mimicking of a different output format.
+ */
+public class IFMimickingTestCase extends TestCase {
+
+ /**
+ * Tests IF document handler mimicking.
+ * @throws Exception if an error occurs
+ */
+ public void testMimicking() throws Exception {
+ FopFactory fopFactory = FopFactory.newInstance();
+ File configFile = new File("test/test-no-xml-metrics.xconf");
+ fopFactory.setUserConfig(configFile);
+
+ //Set up XMLRenderer to render to a DOM
+ DOMResult domResult = new DOMResult();
+
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
+ userAgent.getEventBroadcaster().addEventListener(new EventListener() {
+
+ public void processEvent(Event event) {
+ if (event.getEventGroupID().equals("org.apache.fop.fonts.FontEventAdapter")) {
+ fail("There must be no font-related event! Got: "
+ + EventFormatter.format(event));
+ }
+ }
+
+ });
+
+ //Create an instance of the target renderer so the XMLRenderer can use its font setup
+ IFDocumentHandler targetHandler = userAgent.getRendererFactory().createDocumentHandler(
+ userAgent, MimeConstants.MIME_PDF);
+
+ //Setup painter
+ IFSerializer serializer = new IFSerializer();
+ serializer.setContext(new IFContext(userAgent));
+ serializer.mimicDocumentHandler(targetHandler);
+ serializer.setResult(domResult);
+
+ userAgent.setDocumentHandlerOverride(serializer);
+
+ Fop fop = fopFactory.newFop(userAgent);
+
+ //minimal-pdf-a.fo uses the Gladiator font so is an ideal FO file for this test:
+ StreamSource src = new StreamSource(new File("test/xml/pdf-a/minimal-pdf-a.fo"));
+
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ Transformer transformer = tFactory.newTransformer();
+ setErrorListener(transformer);
+
+ transformer.transform(src, new SAXResult(fop.getDefaultHandler()));
+ }
+
+ /**
+ * Sets an error listener which doesn't swallow errors like Xalan's default one.
+ * @param transformer the transformer to set the error listener on
+ */
+ protected void setErrorListener(Transformer transformer) {
+ transformer.setErrorListener(new ErrorListener() {
+
+ public void error(TransformerException exception) throws TransformerException {
+ throw exception;
+ }
+
+ public void fatalError(TransformerException exception) throws TransformerException {
+ throw exception;
+ }
+
+ public void warning(TransformerException exception) throws TransformerException {
+ //ignore
+ }
+
+ });
+ }
+
+}
diff --git a/test/test-no-xml-metrics.xconf b/test/test-no-xml-metrics.xconf
new file mode 100644
index 000000000..d47e0ec8f
--- /dev/null
+++ b/test/test-no-xml-metrics.xconf
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<fop version="1.0">
+ <!-- Switch off font caching for the purposes of the unit test -->
+ <use-cache>false</use-cache>
+
+ <!-- Base URL for resolving relative URLs -->
+ <base>./</base>
+
+ <!-- Font Base URL for resolving relative font URLs -->
+ <font-base>./test/resources/fonts</font-base>
+
+ <renderers>
+ <renderer mime="application/pdf">
+ <filterList type="content">
+ <value>null</value>
+ </filterList>
+ <fonts>
+ <font embed-url="glb12.ttf" kerning="yes">
+ <font-triplet name="Gladiator Bold" style="normal" weight="normal"/>
+ <font-triplet name="Gladiator" style="normal" weight="bold"/>
+ <font-triplet name="Gladiator" style="normal" weight="normal"/>
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+</fop>