diff options
-rw-r--r-- | src/documentation/content/xdocs/trunk/configuration.xml | 18 | ||||
-rw-r--r-- | src/documentation/content/xdocs/trunk/output.xml | 2 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/pdf/PDFRenderer.java | 31 | ||||
-rw-r--r-- | src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java | 5 | ||||
-rw-r--r-- | status.xml | 4 | ||||
-rw-r--r-- | test/java/org/apache/fop/StandardTestSuite.java | 8 | ||||
-rw-r--r-- | test/java/org/apache/fop/render/pdf/PDFsRGBSettingsTestCase.java | 64 |
7 files changed, 121 insertions, 11 deletions
diff --git a/src/documentation/content/xdocs/trunk/configuration.xml b/src/documentation/content/xdocs/trunk/configuration.xml index 410b17098..e82a6e862 100644 --- a/src/documentation/content/xdocs/trunk/configuration.xml +++ b/src/documentation/content/xdocs/trunk/configuration.xml @@ -277,7 +277,23 @@ <output-profile>C:\FOP\Color\EuropeISOCoatedFOGRA27.icc</output-profile> <fonts.... - </renderer>]]></source> + </renderer>]]></source> + <p> + Some people don't have high requirements on color fidelity but instead want the smallest + PDF file sizes possible. In this case it's possible to disable the default sRGB color space + which XSL-FO requires. This will cause RGB colors to be generated as device-specific RGB. + Please note that this option is unavailable (and will cause an error) if you enable + PDF/A or PDF/X functionality or if you specify an output profile. This setting will make the + PDF about 4KB smaller. To disable the sRGB color space add the following setting: + </p> + <source><![CDATA[ + <renderer mime="application/pdf"> + <filterList... + + <disable-srgb-colorspace>true</disable-srgb-colorspace> + + <fonts.... + </renderer>]]></source> </section> <section id="ps-renderer"> <title>Special Settings for the PostScript Renderer</title> diff --git a/src/documentation/content/xdocs/trunk/output.xml b/src/documentation/content/xdocs/trunk/output.xml index 663168a3c..d6021414f 100644 --- a/src/documentation/content/xdocs/trunk/output.xml +++ b/src/documentation/content/xdocs/trunk/output.xml @@ -105,7 +105,7 @@ out = proc.getOutputStream();]]></source> <section id="pdf-postprocess"> <title>Post-processing</title> <p> - FOP does not currently support several desirable PDF features: XMP metadata and watermarks. + FOP does not currently support several desirable PDF features: watermarks and signatures. One workaround is to use Adobe Acrobat (the full version, not the Reader) to process the file manually or with scripting that it supports. </p> diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index 86c01f673..09c6fbed4 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -147,6 +147,11 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { public static final String PDF_X_MODE = "pdf-x-mode"; /** Rendering Options key for the ICC profile for the output intent. */ public static final String KEY_OUTPUT_PROFILE = "output-profile"; + /** + * Rendering Options key for disabling the sRGB color space (only possible if no PDF/A or + * PDF/X profile is active). + */ + public static final String KEY_DISABLE_SRGB_COLORSPACE = "disable-srgb-colorspace"; /** Controls whether comments are written to the PDF stream. */ protected static final boolean WRITE_COMMENTS = true; @@ -233,10 +238,10 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { /** the ICC stream used as output profile by this document for PDF/A and PDF/X functionality. */ protected PDFICCStream outputProfile; - /** the ICC stream for the sRGB color space. */ - //protected PDFICCStream sRGBProfile; /** the default sRGB color space. */ protected PDFICCBasedColorSpace sRGBColorSpace; + /** controls whether the sRGB color space should be installed */ + protected boolean disableSRGBColorSpace = false; /** Optional URI to an output profile to be used. */ protected String outputProfileURI; @@ -344,6 +349,10 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { if (s != null) { this.outputProfileURI = s; } + setting = agent.getRendererOptions().get(KEY_DISABLE_SRGB_COLORSPACE); + if (setting != null) { + this.disableSRGBColorSpace = booleanValueOf(setting); + } } /** @@ -387,11 +396,21 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { } private void addsRGBColorSpace() throws IOException { - if (this.sRGBColorSpace != null) { - return; + if (disableSRGBColorSpace) { + if (this.pdfAMode != PDFAMode.DISABLED + || this.pdfXMode != PDFXMode.DISABLED + || this.outputProfileURI != null) { + throw new IllegalStateException("It is not possible to disable the sRGB color" + + " space if PDF/A or PDF/X functionality is enabled or an" + + " output profile is set!"); + } + } else { + if (this.sRGBColorSpace != null) { + return; + } + //Map sRGB as default RGB profile for DeviceRGB + this.sRGBColorSpace = PDFICCBasedColorSpace.setupsRGBAsDefaultRGBColorSpace(pdfDoc); } - //Map sRGB as default RGB profile for DeviceRGB - this.sRGBColorSpace = PDFICCBasedColorSpace.setupsRGBAsDefaultRGBColorSpace(pdfDoc); } private void addDefaultOutputProfile() throws IOException { diff --git a/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java b/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java index aec094e3b..2fce8859a 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java +++ b/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; + import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.pdf.PDFAMode; @@ -81,6 +82,10 @@ public class PDFRendererConfigurator extends PrintRendererConfigurator { if (s != null) { pdfRenderer.setOutputProfileURI(s); } + Configuration child = cfg.getChild(PDFRenderer.KEY_DISABLE_SRGB_COLORSPACE, false); + if (child != null) { + pdfRenderer.disableSRGBColorSpace = child.getValueAsBoolean(false); + } } } diff --git a/status.xml b/status.xml index 3cc0f5b46..49b238a38 100644 --- a/status.xml +++ b/status.xml @@ -28,6 +28,10 @@ <changes> <release version="FOP Trunk"> + <action context="Fonts" dev="JM" type="add"> + Added an option to disable the default sRGB profile in PDF output for those who + don't care about color fidelity, but care about PDF file size. + </action> <action context="Code" dev="AD" type="fix" fixes-bug="43705"> Fixed a bug when the rgb-icc() function was used either before the fo:declarations, or in documents without a fo:declarations node. In such cases, the sRGB fallback diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java index 4066e00a0..648f3d5d1 100644 --- a/test/java/org/apache/fop/StandardTestSuite.java +++ b/test/java/org/apache/fop/StandardTestSuite.java @@ -19,14 +19,15 @@ package org.apache.fop; +import junit.framework.Test; +import junit.framework.TestSuite; + import org.apache.fop.render.pdf.PDFAConformanceTestCase; import org.apache.fop.render.pdf.PDFCMapTestCase; import org.apache.fop.render.pdf.PDFEncodingTestCase; +import org.apache.fop.render.pdf.PDFsRGBSettingsTestCase; import org.apache.fop.render.rtf.RichTextFormatTestSuite; -import junit.framework.Test; -import junit.framework.TestSuite; - /** * Test suite for basic functionality of FOP. */ @@ -45,6 +46,7 @@ public class StandardTestSuite { suite.addTest(new TestSuite(PDFAConformanceTestCase.class)); suite.addTest(new TestSuite(PDFEncodingTestCase.class)); suite.addTest(new TestSuite(PDFCMapTestCase.class)); + suite.addTest(new TestSuite(PDFsRGBSettingsTestCase.class)); suite.addTest(RichTextFormatTestSuite.suite()); //$JUnit-END$ return suite; diff --git a/test/java/org/apache/fop/render/pdf/PDFsRGBSettingsTestCase.java b/test/java/org/apache/fop/render/pdf/PDFsRGBSettingsTestCase.java new file mode 100644 index 000000000..45f982b00 --- /dev/null +++ b/test/java/org/apache/fop/render/pdf/PDFsRGBSettingsTestCase.java @@ -0,0 +1,64 @@ +/* + * 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.pdf; + +import java.io.File; + +import org.apache.fop.apps.FOUserAgent; + +/** + * Tests the disables-srgb-colorspace setting. + */ +public class PDFsRGBSettingsTestCase extends BasePDFTestCase { + + private File foBaseDir = new File("test/xml/pdf-a"); + + /** + * Main constructor + * @param name name of the test case + */ + public PDFsRGBSettingsTestCase(String name) { + super(name); + } + + private FOUserAgent getUserAgent(boolean enablePDFA) { + final FOUserAgent a = fopFactory.newFOUserAgent(); + if (enablePDFA) { + a.getRendererOptions().put("pdf-a-mode", "PDF/A-1b"); + } + a.getRendererOptions().put("disable-srgb-colorspace", Boolean.TRUE); + return a; + } + + /** + * Verify that the PDFRenderer complains if PDF/A or PDF/X is used when sRGB is disabled. + * @throws Exception if the test fails + */ + public void testPDFAWithDisabledSRGB() throws Exception { + File foFile = new File(foBaseDir, "minimal-pdf-a.fo"); + try { + convertFO(foFile, getUserAgent(true), false); + fail("PDFRenderer must fail if PDF/A is active!"); + } catch (IllegalStateException e) { + //exception expected! + } + } + +} |