summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2015-03-12 10:13:48 +0000
committerSimon Steiner <ssteiner@apache.org>2015-03-12 10:13:48 +0000
commitde3950df5e27c9e8a7901a3377891bfab9bb4b1c (patch)
treed2fa421d4740b3ae727eb0b6aec499230ece6bd8 /test
parentb28c99c038ebe6ed1c9c8690a68a7c6deab97ff7 (diff)
downloadxmlgraphics-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 'test')
-rw-r--r--test/java/org/apache/fop/pdf/PDFLinearizationTestCase.java2
-rw-r--r--test/java/org/apache/fop/pdf/PDFPagePieceTestCase.java67
-rw-r--r--test/java/org/apache/fop/pdf/PDFVT.fo29
-rw-r--r--test/java/org/apache/fop/pdf/PDFVT.xconf15
-rw-r--r--test/java/org/apache/fop/pdf/PDFVTTestCase.java142
-rw-r--r--test/resources/color/ISOcoated_v2_300_bas.iccbin0 -> 1053552 bytes
6 files changed, 254 insertions, 1 deletions
diff --git a/test/java/org/apache/fop/pdf/PDFLinearizationTestCase.java b/test/java/org/apache/fop/pdf/PDFLinearizationTestCase.java
index 7b78c1f5b..3df497e0f 100644
--- a/test/java/org/apache/fop/pdf/PDFLinearizationTestCase.java
+++ b/test/java/org/apache/fop/pdf/PDFLinearizationTestCase.java
@@ -288,7 +288,7 @@ public class PDFLinearizationTestCase {
}
}
- private Map<String, StringBuilder> readObjs(InputStream inputStream) throws IOException {
+ public static Map<String, StringBuilder> readObjs(InputStream inputStream) throws IOException {
Map<String, StringBuilder> objs = new LinkedHashMap<String, StringBuilder>();
StringBuilder sb = new StringBuilder();
String key = null;
diff --git a/test/java/org/apache/fop/pdf/PDFPagePieceTestCase.java b/test/java/org/apache/fop/pdf/PDFPagePieceTestCase.java
new file mode 100644
index 000000000..4ee98b665
--- /dev/null
+++ b/test/java/org/apache/fop/pdf/PDFPagePieceTestCase.java
@@ -0,0 +1,67 @@
+/*
+ * 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.awt.Dimension;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.util.Arrays;
+
+import javax.xml.transform.stream.StreamResult;
+
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.pdf.PDFDocumentHandler;
+import org.apache.fop.render.pdf.extensions.PDFCollectionEntryExtension;
+import org.apache.fop.render.pdf.extensions.PDFDictionaryAttachment;
+import org.apache.fop.render.pdf.extensions.PDFDictionaryExtension;
+import org.apache.fop.render.pdf.extensions.PDFDictionaryType;
+
+import junit.framework.Assert;
+
+public class PDFPagePieceTestCase {
+ @Test
+ public void testPDF() throws IFException {
+ FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
+ PDFDocumentHandler documentHandler = new PDFDocumentHandler(new IFContext(userAgent));
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ documentHandler.setResult(new StreamResult(bos));
+ documentHandler.startDocument();
+ documentHandler.startPage(0, "", "", new Dimension());
+
+ PDFDictionaryExtension dictionaryExtension = mock(PDFDictionaryExtension.class);
+ when(dictionaryExtension.getDictionaryType()).thenReturn(PDFDictionaryType.PagePiece);
+
+ PDFDictionaryExtension child = mock(PDFDictionaryExtension.class);
+ when(child.getKey()).thenReturn("a");
+ when(dictionaryExtension.getEntries()).thenReturn(Arrays.<PDFCollectionEntryExtension>asList(child));
+ documentHandler.handleExtensionObject(new PDFDictionaryAttachment(dictionaryExtension));
+
+ documentHandler.endPage();
+ Assert.assertTrue(bos.toString(), bos.toString().contains("/PieceInfo << /a << >> /LastModified (D:"));
+ }
+}
diff --git a/test/java/org/apache/fop/pdf/PDFVT.fo b/test/java/org/apache/fop/pdf/PDFVT.fo
new file mode 100644
index 000000000..6919afcf6
--- /dev/null
+++ b/test/java/org/apache/fop/pdf/PDFVT.fo
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Arial" xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="simple" page-height="27.9cm" page-width="21.6cm">
+ <fo:region-body />
+ <pdf:vt>
+ <pdf:dictionary key="DPM/CIP4_Root/CIP4_Production/CIP4_Part">
+ <pdf:string key="CIP4_ProductType">frontpages</pdf:string>
+ </pdf:dictionary>
+ </pdf:vt>
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+ <fo:declarations>
+ <x:xmpmeta xmlns:x="adobe:ns:meta/">
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <dc:title>Document title</dc:title>
+ <dc:creator>Document author</dc:creator>
+ <dc:description>Document subject</dc:description>
+ </rdf:Description>
+ </rdf:RDF>
+ </x:xmpmeta>
+ </fo:declarations>
+ <fo:page-sequence format="1" id="th_default_sequence1" master-reference="simple">
+ <fo:flow flow-name="xsl-region-body">
+ <fo:block>page 1</fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+</fo:root>
diff --git a/test/java/org/apache/fop/pdf/PDFVT.xconf b/test/java/org/apache/fop/pdf/PDFVT.xconf
new file mode 100644
index 000000000..52588f0b0
--- /dev/null
+++ b/test/java/org/apache/fop/pdf/PDFVT.xconf
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<fop version="1.0">
+ <renderers>
+ <renderer mime="application/pdf">
+ <pdf-x-mode>PDF/X-4</pdf-x-mode>
+ <pdf-vt-mode>PDF/VT-1</pdf-vt-mode>
+ <output-profile>test/resources/color/ISOcoated_v2_300_bas.icc</output-profile>
+ <fonts>
+ <font kerning="yes" embed-url="test/resources/fonts/ttf/DejaVuLGCSerif.ttf">
+ <font-triplet name="Arial" style="normal" weight="normal"/>
+ </font>
+ </fonts>
+ </renderer>
+ </renderers>
+</fop>
diff --git a/test/java/org/apache/fop/pdf/PDFVTTestCase.java b/test/java/org/apache/fop/pdf/PDFVTTestCase.java
new file mode 100644
index 000000000..e3dcf2cf6
--- /dev/null
+++ b/test/java/org/apache/fop/pdf/PDFVTTestCase.java
@@ -0,0 +1,142 @@
+/*
+ * 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.awt.geom.Rectangle2D;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.xml.sax.SAXException;
+
+import org.apache.xmlgraphics.util.QName;
+import org.apache.xmlgraphics.xmp.Metadata;
+
+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.render.pdf.PDFContentGenerator;
+
+public class PDFVTTestCase {
+ @Test
+ public void testXMP() throws IOException {
+ PDFDocument doc = new PDFDocument("");
+ doc.getProfile().setPDFXMode(PDFXMode.PDFX_4);
+ doc.getProfile().setPDFVTMode(PDFVTMode.PDFVT_1);
+ Metadata metadata = PDFMetadata.createXMPFromPDFDocument(doc);
+ StringBuilder sb = new StringBuilder();
+ Iterator i = metadata.iterator();
+ while (i.hasNext()) {
+ QName k = (QName) i.next();
+ sb.append(k + ": " + metadata.getProperty(k).getValue() + "\n");
+ }
+ String s = sb.toString();
+ Assert.assertTrue(s.contains("pdfxid:GTS_PDFXVersion: PDF/X-4"));
+ Assert.assertTrue(s.contains("xmpMM:VersionID: 1"));
+ Assert.assertTrue(s.contains("pdf:Trapped: False"));
+ Assert.assertTrue(s.contains("xmpMM:RenditionClass: default"));
+ Assert.assertTrue(s.contains("pdf:PDFVersion: 1.4"));
+ Assert.assertTrue(s.contains("pdfvtid:GTS_PDFVTVersion: PDF/VT-1"));
+ }
+
+ @Test
+ public void testPDF() throws IOException {
+ PDFDocument doc = new PDFDocument("");
+ doc.getInfo().setTitle("title");
+ doc.getProfile().setPDFXMode(PDFXMode.PDFX_4);
+ doc.getProfile().setPDFVTMode(PDFVTMode.PDFVT_1);
+ PDFResources resources = new PDFResources(doc);
+ doc.addObject(resources);
+ PDFResourceContext context = new PDFResourceContext(resources);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ PDFContentGenerator gen = new PDFContentGenerator(doc, out, context);
+ Rectangle2D.Float f = new Rectangle2D.Float();
+ PDFPage page = new PDFPage(resources, 0, f, f, f, f);
+ doc.addImage(context, new BitmapImage("", 1, 1, new byte[0], null));
+ doc.registerObject(page);
+ doc.getFactory().makeDPart(page, "master");
+ gen.flushPDFDoc();
+ doc.outputTrailer(out);
+
+ Collection<StringBuilder> objs = PDFLinearizationTestCase.readObjs(
+ new ByteArrayInputStream(out.toByteArray())).values();
+ Assert.assertTrue(getObj(objs, "/Type /Catalog").contains("/DPartRoot "));
+ Assert.assertTrue(getObj(objs, "/Type /DPartRoot").contains("/NodeNameList [/root /record]"));
+ Assert.assertTrue(
+ getObj(objs, "/Subtype /Image").contains("/GTS_XID (uuid:d41d8cd9-8f00-3204-a980-0998ecf8427e)"));
+ }
+
+ @Test
+ public void textFO() throws IOException, SAXException, TransformerException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI(),
+ new FileInputStream("test/java/org/apache/fop/pdf/PDFVT.xconf"));
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
+
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ Source src = new StreamSource(new FileInputStream("test/java/org/apache/fop/pdf/PDFVT.fo"));
+ Result res = new SAXResult(fop.getDefaultHandler());
+ transformer.transform(src, res);
+
+ Map<String, StringBuilder> objs =
+ PDFLinearizationTestCase.readObjs(new ByteArrayInputStream(out.toByteArray()));
+ String dpart = getObj(objs.values(), "/DParts");
+ int v = getValue("/DParts", dpart);
+ String dpm = objs.get(v + " 0 obj").toString();
+ Assert.assertTrue(dpm.contains(
+ "/DPM << /CIP4_Root << /CIP4_Production << /CIP4_Part << /CIP4_ProductType (frontpages) >>"));
+ }
+
+ private int getValue(String name, String firstObj) throws IOException {
+ String[] split = firstObj.split(" ");
+ for (int i = 0; i < split.length; i++) {
+ if (split[i].equals(name)) {
+ return Integer.valueOf(split[i + 1].replace("[[", ""));
+ }
+ }
+ throw new IOException(name + " not found " + firstObj);
+ }
+
+ private String getObj(Collection<StringBuilder> objs, String x) {
+ for (StringBuilder s : objs) {
+ if (s.toString().contains(x)) {
+ return s.toString();
+ }
+ }
+ return null;
+ }
+}
diff --git a/test/resources/color/ISOcoated_v2_300_bas.icc b/test/resources/color/ISOcoated_v2_300_bas.icc
new file mode 100644
index 000000000..71faa91f9
--- /dev/null
+++ b/test/resources/color/ISOcoated_v2_300_bas.icc
Binary files differ