diff options
author | Simon Steiner <ssteiner@apache.org> | 2015-03-12 10:13:48 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2015-03-12 10:13:48 +0000 |
commit | de3950df5e27c9e8a7901a3377891bfab9bb4b1c (patch) | |
tree | d2fa421d4740b3ae727eb0b6aec499230ece6bd8 /src/java/org/apache/fop/pdf | |
parent | b28c99c038ebe6ed1c9c8690a68a7c6deab97ff7 (diff) | |
download | xmlgraphics-fop-de3950df5e27c9e8a7901a3377891bfab9bb4b1c.tar.gz xmlgraphics-fop-de3950df5e27c9e8a7901a3377891bfab9bb4b1c.zip |
FOP-2456: PDF VT and Page Piece support
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1666117 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/pdf')
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFDPart.java | 47 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFDPartRoot.java | 42 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFFactory.java | 22 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFImageXObject.java | 7 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFMetadata.java | 35 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFProfile.java | 35 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFRoot.java | 10 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFVTMode.java | 45 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFXMode.java | 12 |
9 files changed, 243 insertions, 12 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFDPart.java b/src/java/org/apache/fop/pdf/PDFDPart.java new file mode 100644 index 000000000..bd7262713 --- /dev/null +++ b/src/java/org/apache/fop/pdf/PDFDPart.java @@ -0,0 +1,47 @@ +/* + * 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.pdf; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +public class PDFDPart extends PDFDictionary { + private List<PDFPage> pages = new ArrayList<PDFPage>(); + private PDFDictionary parent; + public PDFDPart(PDFDictionary parent) { + this.parent = parent; + put("Type", new PDFName("DPart")); + } + + public void addPage(PDFPage p) { + pages.add(p); + } + + @Override + public int output(OutputStream stream) throws IOException { + put("Parent", parent.makeReference()); + if (!pages.isEmpty()) { + put("Start", pages.get(0).makeReference()); + put("End", pages.get(pages.size() - 1).makeReference()); + } + return super.output(stream); + } +} diff --git a/src/java/org/apache/fop/pdf/PDFDPartRoot.java b/src/java/org/apache/fop/pdf/PDFDPartRoot.java new file mode 100644 index 000000000..cd1d3b446 --- /dev/null +++ b/src/java/org/apache/fop/pdf/PDFDPartRoot.java @@ -0,0 +1,42 @@ +/* + * 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.pdf; + +public class PDFDPartRoot extends PDFDictionary { + private PDFArray parts = new PDFArray(); + protected PDFDPart dpart; + + public PDFDPartRoot(PDFDocument document) { + put("Type", new PDFName("DPartRoot")); + dpart = new PDFDPart(this); + document.registerTrailerObject(dpart); + PDFArray dparts = new PDFArray(); + dparts.add(parts); + dpart.put("DParts", dparts); + put("DPartRootNode", dpart.makeReference()); + PDFArray nodeNameList = new PDFArray(); + nodeNameList.add(new PDFName("root")); + nodeNameList.add(new PDFName("record")); + put("NodeNameList", nodeNameList); + } + + public void add(PDFDPart part) { + parts.add(part); + } +} diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java index 86a480780..b1152df16 100644 --- a/src/java/org/apache/fop/pdf/PDFFactory.java +++ b/src/java/org/apache/fop/pdf/PDFFactory.java @@ -28,6 +28,7 @@ import java.io.InputStream; import java.text.DecimalFormat; import java.util.Arrays; import java.util.BitSet; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -76,6 +77,7 @@ public class PDFFactory { private Log log = LogFactory.getLog(PDFFactory.class); private int subsetFontCounter = -1; + private Map<String, PDFDPart> dparts = new HashMap<String, PDFDPart>(); /** * Creates a new PDFFactory. @@ -1487,4 +1489,24 @@ public class PDFFactory { return navigator; } + public void makeDPart(PDFPage page, String pageMasterName) { + PDFDPartRoot root = getDocument().getRoot().getDPartRoot(); + PDFDPart dPart; + if (dparts.containsKey(pageMasterName)) { + dPart = dparts.get(pageMasterName); + } else { + dPart = new PDFDPart(root.dpart); + root.add(dPart); + getDocument().registerTrailerObject(dPart); + dparts.put(pageMasterName, dPart); + } + dPart.addPage(page); + page.put("DPart", dPart); + } + + public PDFDPartRoot makeDPartRoot() { + PDFDPartRoot pdfdPartRoot = new PDFDPartRoot(getDocument()); + getDocument().registerTrailerObject(pdfdPartRoot); + return pdfdPartRoot; + } } diff --git a/src/java/org/apache/fop/pdf/PDFImageXObject.java b/src/java/org/apache/fop/pdf/PDFImageXObject.java index e472efbea..bbee663da 100644 --- a/src/java/org/apache/fop/pdf/PDFImageXObject.java +++ b/src/java/org/apache/fop/pdf/PDFImageXObject.java @@ -20,9 +20,11 @@ package org.apache.fop.pdf; // Java +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Set; +import java.util.UUID; /* modified by JKT to integrate with 0.12.0 */ /* modified by Eric SCHAEFFER to integrate with 0.13.0 */ @@ -63,6 +65,11 @@ public class PDFImageXObject extends PDFXObject { * @return the length of the data written */ public int output(OutputStream stream) throws IOException { + if (getDocument().getProfile().isPDFVTActive()) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + pdfimage.outputContents(baos); + put("GTS_XID", "uuid:" + UUID.nameUUIDFromBytes(baos.toByteArray())); + } int length = super.output(stream); // let it gc diff --git a/src/java/org/apache/fop/pdf/PDFMetadata.java b/src/java/org/apache/fop/pdf/PDFMetadata.java index 203429147..370c0017a 100644 --- a/src/java/org/apache/fop/pdf/PDFMetadata.java +++ b/src/java/org/apache/fop/pdf/PDFMetadata.java @@ -22,6 +22,7 @@ package org.apache.fop.pdf; import java.io.IOException; import java.io.OutputStream; import java.util.Date; +import java.util.UUID; import javax.xml.transform.TransformerConfigurationException; @@ -37,6 +38,12 @@ import org.apache.xmlgraphics.xmp.schemas.pdf.AdobePDFAdapter; import org.apache.xmlgraphics.xmp.schemas.pdf.AdobePDFSchema; import org.apache.xmlgraphics.xmp.schemas.pdf.PDFAAdapter; import org.apache.xmlgraphics.xmp.schemas.pdf.PDFAXMPSchema; +import org.apache.xmlgraphics.xmp.schemas.pdf.PDFVTAdapter; +import org.apache.xmlgraphics.xmp.schemas.pdf.PDFVTXMPSchema; +import org.apache.xmlgraphics.xmp.schemas.pdf.PDFXAdapter; +import org.apache.xmlgraphics.xmp.schemas.pdf.PDFXXMPSchema; +import org.apache.xmlgraphics.xmp.schemas.pdf.XAPMMAdapter; +import org.apache.xmlgraphics.xmp.schemas.pdf.XAPMMXMPSchema; /** * Special PDFStream for Metadata. @@ -161,11 +168,35 @@ public class PDFMetadata extends PDFStream { pdfa.setPart(pdfaMode.getPart()); pdfa.setConformance(String.valueOf(pdfaMode.getConformanceLevel())); } + AdobePDFAdapter adobePDF = AdobePDFSchema.getAdapter(meta); + PDFXMode pdfxMode = pdfDoc.getProfile().getPDFXMode(); + if (pdfxMode != PDFXMode.DISABLED) { + PDFXAdapter pdfx = PDFXXMPSchema.getAdapter(meta); + pdfx.setVersion(pdfxMode.getName()); + + XAPMMAdapter xapmm = XAPMMXMPSchema.getAdapter(meta); + xapmm.setVersion("1"); + xapmm.setDocumentID("uuid:" + UUID.randomUUID().toString()); + xapmm.setInstanceID("uuid:" + UUID.randomUUID().toString()); + xapmm.setRenditionClass("default"); + adobePDF.setTrapped("False"); + } + PDFProfile profile = pdfDoc.getProfile(); + PDFVTMode pdfvtMode = profile.getPDFVTMode(); + if (pdfvtMode != PDFVTMode.DISABLED) { + PDFVTAdapter pdfvt = PDFVTXMPSchema.getAdapter(meta); + pdfvt.setVersion("PDF/VT-1"); + if (info.getModDate() != null) { + pdfvt.setModifyDate(info.getModDate()); + } else if (profile.isModDateRequired()) { + //if modify date is needed but none is in the Info object, use creation date + pdfvt.setModifyDate(info.getCreationDate()); + } + } //XMP Basic Schema XMPBasicAdapter xmpBasic = XMPBasicSchema.getAdapter(meta); xmpBasic.setCreateDate(info.getCreationDate()); - PDFProfile profile = pdfDoc.getProfile(); if (info.getModDate() != null) { xmpBasic.setModifyDate(info.getModDate()); } else if (profile.isModDateRequired()) { @@ -176,7 +207,7 @@ public class PDFMetadata extends PDFStream { xmpBasic.setCreatorTool(info.getCreator()); } - AdobePDFAdapter adobePDF = AdobePDFSchema.getAdapter(meta); + if (info.getKeywords() != null) { adobePDF.setKeywords(info.getKeywords()); } diff --git a/src/java/org/apache/fop/pdf/PDFProfile.java b/src/java/org/apache/fop/pdf/PDFProfile.java index 4289d0ee8..219623842 100644 --- a/src/java/org/apache/fop/pdf/PDFProfile.java +++ b/src/java/org/apache/fop/pdf/PDFProfile.java @@ -43,6 +43,8 @@ public class PDFProfile { */ protected PDFXMode pdfXMode = PDFXMode.DISABLED; + protected PDFVTMode pdfVTMode = PDFVTMode.DISABLED; + private PDFDocument doc; /** @@ -59,12 +61,15 @@ public class PDFProfile { protected void validateProfileCombination() { if (pdfAMode != PDFAMode.DISABLED) { if (pdfAMode == PDFAMode.PDFA_1B) { - if (pdfXMode != PDFXMode.DISABLED && pdfXMode != PDFXMode.PDFX_3_2003) { + if (pdfXMode != PDFXMode.DISABLED && pdfXMode != PDFXMode.PDFX_3_2003 && pdfXMode != PDFXMode.PDFX_4) { throw new PDFConformanceException( pdfAMode + " and " + pdfXMode + " are not compatible!"); } } } + if (pdfVTMode != PDFVTMode.DISABLED && pdfXMode != PDFXMode.PDFX_4) { + throw new PDFConformanceException(pdfVTMode.name() + " requires " + PDFXMode.PDFX_4.getName() + " enabled"); + } } /** @return the PDFDocument this profile is attached to */ @@ -99,11 +104,19 @@ public class PDFProfile { return this.pdfXMode; } + public PDFVTMode getPDFVTMode() { + return this.pdfVTMode; + } + /** @return true if any PDF/X mode is active */ public boolean isPDFXActive() { return getPDFXMode() != PDFXMode.DISABLED; } + public boolean isPDFVTActive() { + return getPDFVTMode() != PDFVTMode.DISABLED; + } + /** * Sets the PDF/X mode * @param mode the PDF/X mode @@ -116,6 +129,18 @@ public class PDFProfile { validateProfileCombination(); } + /** + * Sets the PDF/X mode + * @param mode the PDF/X mode + */ + public void setPDFVTMode(PDFVTMode mode) { + if (mode == null) { + mode = PDFVTMode.DISABLED; + } + this.pdfVTMode = mode; + validateProfileCombination(); + } + /** {@inheritDoc} */ public String toString() { StringBuffer sb = new StringBuffer(); @@ -186,7 +211,7 @@ public class PDFProfile { if (pdfAMode.isPart1()) { return getPDFAMode(); } - if (isPDFXActive()) { + if (getPDFXMode() == PDFXMode.PDFX_3_2003) { return getPDFXMode(); } return null; @@ -194,7 +219,7 @@ public class PDFProfile { /** Checks if the right PDF version is set. */ public void verifyPDFVersion() { - final String err = "PDF version must be 1.4 for {0}"; + String err = "PDF version must be 1.4 for {0}"; if (getPDFAMode().isPart1() && !Version.V1_4.equals(getDocument().getPDFVersion())) { throw new PDFConformanceException(format(err, getPDFAMode())); @@ -252,12 +277,12 @@ public class PDFProfile { /** @return true if the ModDate Info entry must be present. */ public boolean isModDateRequired() { - return getPDFXMode() == PDFXMode.PDFX_3_2003; + return getPDFXMode() != PDFXMode.DISABLED; } /** @return true if the Trapped Info entry must be present. */ public boolean isTrappedEntryRequired() { - return getPDFXMode() == PDFXMode.PDFX_3_2003; + return getPDFXMode() != PDFXMode.DISABLED; } /** @return true if annotations are allowed */ diff --git a/src/java/org/apache/fop/pdf/PDFRoot.java b/src/java/org/apache/fop/pdf/PDFRoot.java index 0a0f03d6d..66e58c5f0 100644 --- a/src/java/org/apache/fop/pdf/PDFRoot.java +++ b/src/java/org/apache/fop/pdf/PDFRoot.java @@ -52,6 +52,8 @@ public class PDFRoot extends PDFDictionary { private final PDFDocument document; + private PDFDPartRoot dPartRoot; + private static final PDFName[] PAGEMODE_NAMES = new PDFName[] { new PDFName("UseNone"), @@ -318,4 +320,12 @@ public class PDFRoot extends PDFDictionary { public PDFDictionary getMarkInfo() { return (PDFDictionary)get("MarkInfo"); } + + public PDFDPartRoot getDPartRoot() { + if (dPartRoot == null) { + dPartRoot = getDocument().getFactory().makeDPartRoot(); + put("DPartRoot", dPartRoot.makeReference()); + } + return dPartRoot; + } } diff --git a/src/java/org/apache/fop/pdf/PDFVTMode.java b/src/java/org/apache/fop/pdf/PDFVTMode.java new file mode 100644 index 000000000..0dbb65873 --- /dev/null +++ b/src/java/org/apache/fop/pdf/PDFVTMode.java @@ -0,0 +1,45 @@ +/* + * 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.pdf; + +public enum PDFVTMode { + DISABLED("PDF/VT disabled"), + PDFVT_1("PDF/VT-1"); + + private String name; + + PDFVTMode(String s) { + name = s; + } + + /** + * Returns the mode enum object given a String. + * + * @param s the string + * @return the PDFVTMode enum object (DISABLED will be returned if no match is found) + */ + public static PDFVTMode getValueOf(String s) { + for (PDFVTMode mode : values()) { + if (mode.name.equalsIgnoreCase(s)) { + return mode; + } + } + return DISABLED; + } +} diff --git a/src/java/org/apache/fop/pdf/PDFXMode.java b/src/java/org/apache/fop/pdf/PDFXMode.java index be0312891..84e7f785a 100644 --- a/src/java/org/apache/fop/pdf/PDFXMode.java +++ b/src/java/org/apache/fop/pdf/PDFXMode.java @@ -25,7 +25,8 @@ public enum PDFXMode { /** PDF/X disabled */ DISABLED("PDF/X disabled"), /** PDF/X-3:2003 enabled */ - PDFX_3_2003("PDF/X-3:2003"); + PDFX_3_2003("PDF/X-3:2003"), + PDFX_4("PDF/X-4"); private String name; @@ -48,11 +49,12 @@ public enum PDFXMode { * @return the PDFAMode enum object (DISABLED will be returned if no match is found) */ public static PDFXMode getValueOf(String s) { - if (PDFX_3_2003.getName().equalsIgnoreCase(s)) { - return PDFX_3_2003; - } else { - return DISABLED; + for (PDFXMode mode : values()) { + if (mode.name.equalsIgnoreCase(s)) { + return mode; + } } + return DISABLED; } /** {@inheritDoc} */ |