summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2019-09-09 09:08:12 +0000
committerSimon Steiner <ssteiner@apache.org>2019-09-09 09:08:12 +0000
commitb518b28e0ff2f75a36892ccd88fbd475b5138ab2 (patch)
tree1be847332edc61282dfd0ac9d631351c6b7e7a93
parentafdf427804303fe997a3928709fcf222e1d7244a (diff)
downloadxmlgraphics-fop-b518b28e0ff2f75a36892ccd88fbd475b5138ab2.tar.gz
xmlgraphics-fop-b518b28e0ff2f75a36892ccd88fbd475b5138ab2.zip
FOP-2882: Allow PDFFormXObject to improve performance
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1866666 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java9
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererConfig.java3
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOption.java6
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java5
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java1
-rw-r--r--fop-core/src/test/java/org/apache/fop/apps/PDFRendererConfBuilder.java6
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/pdf/PDFRendererConfiguratorTestCase.java76
7 files changed, 105 insertions, 1 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java
index f5b886bc6..6e82d89d2 100644
--- a/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java
+++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java
@@ -174,6 +174,8 @@ public class PDFDocument {
private boolean linearizationEnabled;
+ private boolean formXObjectEnabled;
+
protected boolean outputStarted;
/**
@@ -1229,4 +1231,11 @@ public class PDFDocument {
linearizationEnabled = b;
}
+ public boolean isFormXObjectEnabled() {
+ return formXObjectEnabled;
+ }
+
+ public void setFormXObjectEnabled(boolean b) {
+ formXObjectEnabled = b;
+ }
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererConfig.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererConfig.java
index 851189cd7..1e95a8616 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererConfig.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererConfig.java
@@ -57,6 +57,7 @@ import static org.apache.fop.render.pdf.PDFEncryptionOption.OWNER_PASSWORD;
import static org.apache.fop.render.pdf.PDFEncryptionOption.USER_PASSWORD;
import static org.apache.fop.render.pdf.PDFRendererOption.DISABLE_SRGB_COLORSPACE;
import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST;
+import static org.apache.fop.render.pdf.PDFRendererOption.FORM_XOBJECT;
import static org.apache.fop.render.pdf.PDFRendererOption.LINEARIZATION;
import static org.apache.fop.render.pdf.PDFRendererOption.MERGE_FONTS;
import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE;
@@ -150,7 +151,7 @@ public final class PDFRendererConfig implements RendererConfig {
parseAndPut(DISABLE_SRGB_COLORSPACE, cfg);
parseAndPut(MERGE_FONTS, cfg);
parseAndPut(LINEARIZATION, cfg);
-
+ parseAndPut(FORM_XOBJECT, cfg);
parseAndPut(VERSION, cfg);
} catch (ConfigurationException e) {
LogUtil.handleException(LOG, e, strict);
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOption.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOption.java
index 422a5d0ac..677256fe4 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOption.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOption.java
@@ -93,6 +93,12 @@ public enum PDFRendererOption implements RendererConfigOption {
return Boolean.valueOf(value);
}
},
+ FORM_XOBJECT("form-xobject", false) {
+ @Override
+ Boolean deserialize(String value) {
+ return Boolean.valueOf(value);
+ }
+ },
/** Rendering Options key for the ICC profile for the output intent. */
OUTPUT_PROFILE("output-profile") {
@Override
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java
index 54d236db8..02cc9f57d 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java
@@ -33,6 +33,7 @@ import org.apache.fop.pdf.Version;
import static org.apache.fop.render.pdf.PDFRendererOption.DISABLE_SRGB_COLORSPACE;
import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST;
+import static org.apache.fop.render.pdf.PDFRendererOption.FORM_XOBJECT;
import static org.apache.fop.render.pdf.PDFRendererOption.LINEARIZATION;
import static org.apache.fop.render.pdf.PDFRendererOption.MERGE_FONTS;
import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE;
@@ -142,4 +143,8 @@ public final class PDFRendererOptionsConfig {
public Boolean getLinearizationEnabled() {
return (Boolean)properties.get(LINEARIZATION);
}
+
+ public Boolean getFormXObjectEnabled() {
+ return (Boolean)properties.get(FORM_XOBJECT);
+ }
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
index 5ba2cae1b..9ecff2148 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
@@ -620,6 +620,7 @@ class PDFRenderingUtil {
this.pdfDoc.enableAccessibility(userAgent.isAccessibilityEnabled());
pdfDoc.setMergeFontsEnabled(rendererConfig.getMergeFontsEnabled());
pdfDoc.setLinearizationEnabled(rendererConfig.getLinearizationEnabled());
+ pdfDoc.setFormXObjectEnabled(rendererConfig.getFormXObjectEnabled());
return this.pdfDoc;
}
diff --git a/fop-core/src/test/java/org/apache/fop/apps/PDFRendererConfBuilder.java b/fop-core/src/test/java/org/apache/fop/apps/PDFRendererConfBuilder.java
index 3da4e1daf..d21739476 100644
--- a/fop-core/src/test/java/org/apache/fop/apps/PDFRendererConfBuilder.java
+++ b/fop-core/src/test/java/org/apache/fop/apps/PDFRendererConfBuilder.java
@@ -31,6 +31,7 @@ import static org.apache.fop.render.pdf.PDFEncryptionOption.OWNER_PASSWORD;
import static org.apache.fop.render.pdf.PDFEncryptionOption.USER_PASSWORD;
import static org.apache.fop.render.pdf.PDFRendererOption.DISABLE_SRGB_COLORSPACE;
import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST;
+import static org.apache.fop.render.pdf.PDFRendererOption.FORM_XOBJECT;
import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE;
import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE;
import static org.apache.fop.render.pdf.PDFRendererOption.PDF_X_MODE;
@@ -93,6 +94,11 @@ public final class PDFRendererConfBuilder extends RendererConfBuilder {
return this;
}
+ public PDFRendererConfBuilder setFormXObjectEnabled(boolean b) {
+ createTextElement(FORM_XOBJECT, String.valueOf(b));
+ return this;
+ }
+
public final class EncryptionParamsBuilder {
private final Element el;
diff --git a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFRendererConfiguratorTestCase.java b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFRendererConfiguratorTestCase.java
new file mode 100644
index 000000000..08a19d809
--- /dev/null
+++ b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFRendererConfiguratorTestCase.java
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package org.apache.fop.render.pdf;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+import javax.xml.transform.stream.StreamResult;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.fop.apps.AbstractRendererConfiguratorTest;
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.apps.PDFRendererConfBuilder;
+import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFException;
+
+public class PDFRendererConfiguratorTestCase extends
+ AbstractRendererConfiguratorTest<PDFRendererConfigurator, PDFRendererConfBuilder> {
+
+ public PDFRendererConfiguratorTestCase() throws IFException {
+ super(MimeConstants.MIME_PDF, PDFRendererConfBuilder.class, PDFDocumentHandler.class);
+ FOUserAgent userAgent = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent();
+ docHandler = new MyPDFDocumentHandler(new IFContext(userAgent));
+ docHandler.setResult(new StreamResult(new ByteArrayOutputStream()));
+ }
+
+ static class MyPDFDocumentHandler extends PDFDocumentHandler {
+ MyPDFDocumentHandler(IFContext context) {
+ super(context);
+ }
+
+ PDFDocument getThePDFDocument() {
+ return getPDFDocument();
+ }
+ }
+
+ @Override
+ public void setUpDocumentHandler() {
+ }
+
+ @Override
+ protected PDFRendererConfigurator createConfigurator() {
+ return new PDFRendererConfigurator(userAgent, new PDFRendererConfig.PDFRendererConfigParser());
+ }
+
+ private MyPDFDocumentHandler getDocHandler() {
+ return (MyPDFDocumentHandler) docHandler;
+ }
+
+ @Test
+ public void testFormXObjectEnabled() throws Exception {
+ parseConfig(createBuilder().setFormXObjectEnabled(true));
+ docHandler.startDocument();
+ Assert.assertTrue(getDocHandler().getThePDFDocument().isFormXObjectEnabled());
+ }
+}