From b518b28e0ff2f75a36892ccd88fbd475b5138ab2 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Mon, 9 Sep 2019 09:08:12 +0000 Subject: [PATCH] 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 --- .../java/org/apache/fop/pdf/PDFDocument.java | 9 +++ .../fop/render/pdf/PDFRendererConfig.java | 3 +- .../fop/render/pdf/PDFRendererOption.java | 6 ++ .../render/pdf/PDFRendererOptionsConfig.java | 5 ++ .../fop/render/pdf/PDFRenderingUtil.java | 1 + .../fop/apps/PDFRendererConfBuilder.java | 6 ++ .../pdf/PDFRendererConfiguratorTestCase.java | 76 +++++++++++++++++++ 7 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 fop-core/src/test/java/org/apache/fop/render/pdf/PDFRendererConfiguratorTestCase.java 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 { + + 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()); + } +} -- 2.39.5