Author: ssteiner
Date: Fri Jul 31 14:36:56 2015
New Revision: 1693610

URL: http://svn.apache.org/r1693610
Log:
FOP-2507: PDFVT and Page Piece exception using IF

Added:
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFPagePieceExtension.java
   (with props)
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFVTExtension.java
   (with props)
Modified:
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionHandler.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/pdf/PDFVTTestCase.java

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionHandler.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionHandler.java?rev=1693610&r1=1693609&r2=1693610&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionHandler.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFExtensionHandler.java
 Fri Jul 31 14:36:56 2015
@@ -108,6 +108,12 @@ public class PDFExtensionHandler extends
             } else if (PDFDictionaryType.Info.elementName().equals(localName)) 
{
                 PDFDocumentInformationExtension info = new 
PDFDocumentInformationExtension();
                 collections.push(info);
+            } else if (PDFDictionaryType.VT.elementName().equals(localName)) {
+                PDFVTExtension dictionary = new PDFVTExtension();
+                collections.push(dictionary);
+            } else if 
(PDFDictionaryType.PagePiece.elementName().equals(localName)) {
+                PDFPagePieceExtension dictionary = new PDFPagePieceExtension();
+                collections.push(dictionary);
             } else if (PDFObjectType.hasValueOfElementName(localName)) {
                 PDFCollectionEntryExtension entry;
                 if (PDFObjectType.Reference.elementName().equals(localName)) {

Added: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFPagePieceExtension.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFPagePieceExtension.java?rev=1693610&view=auto
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFPagePieceExtension.java
 (added)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFPagePieceExtension.java
 Fri Jul 31 14:36:56 2015
@@ -0,0 +1,25 @@
+/*
+ * 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.extensions;
+
+public class PDFPagePieceExtension extends PDFDictionaryExtension {
+    PDFPagePieceExtension() {
+        super(PDFDictionaryType.PagePiece);
+    }
+}

Propchange: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFPagePieceExtension.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFVTExtension.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFVTExtension.java?rev=1693610&view=auto
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFVTExtension.java
 (added)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFVTExtension.java
 Fri Jul 31 14:36:56 2015
@@ -0,0 +1,25 @@
+/*
+ * 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.extensions;
+
+public class PDFVTExtension extends PDFDictionaryExtension {
+    PDFVTExtension() {
+        super(PDFDictionaryType.VT);
+    }
+}

Propchange: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/extensions/PDFVTExtension.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/pdf/PDFVTTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/pdf/PDFVTTestCase.java?rev=1693610&r1=1693609&r2=1693610&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/pdf/PDFVTTestCase.java 
(original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/pdf/PDFVTTestCase.java Fri 
Jul 31 14:36:56 2015
@@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
@@ -34,6 +35,7 @@ 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.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
 import org.junit.Assert;
@@ -48,6 +50,12 @@ 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.intermediate.IFContext;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.IFParser;
+import org.apache.fop.render.intermediate.IFSerializer;
+import org.apache.fop.render.intermediate.IFUtil;
 import org.apache.fop.render.pdf.PDFContentGenerator;
 
 public class PDFVTTestCase {
@@ -100,18 +108,63 @@ public class PDFVTTestCase {
     }
 
     @Test
-    public void textFO() throws IOException, SAXException, 
TransformerException {
+    public void textFO() throws IOException, SAXException, 
TransformerException, IFException {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI(),
-                new 
FileInputStream("test/java/org/apache/fop/pdf/PDFVT.xconf"));
+        foToOutput(out, MimeConstants.MIME_PDF);
+        checkPDF(out);
+    }
+
+    @Test
+    public void textIF() throws IOException, SAXException, 
TransformerException, IFException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        foToOutput(out, MimeConstants.MIME_FOP_IF);
+        iFToPDF(new ByteArrayInputStream(out.toByteArray()));
+    }
+
+
+    private void foToOutput(ByteArrayOutputStream out, String mimeFopIf)
+        throws IOException, SAXException, TransformerException {
+        FopFactory fopFactory = getFopFactory();
         FOUserAgent userAgent = fopFactory.newFOUserAgent();
 
-        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);
+        if (mimeFopIf.equals(MimeConstants.MIME_FOP_IF)) {
+            IFSerializer serializer = new IFSerializer(new 
IFContext(userAgent));
+            IFDocumentHandler targetHandler
+                    = 
userAgent.getRendererFactory().createDocumentHandler(userAgent, 
MimeConstants.MIME_PDF);
+            serializer.mimicDocumentHandler(targetHandler);
+            userAgent.setDocumentHandlerOverride(serializer);
+        }
+
+        Fop fop = fopFactory.newFop(mimeFopIf, 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);
+    }
+
+    private FopFactory getFopFactory() throws IOException, SAXException {
+        return FopFactory.newInstance(new File(".").toURI(),
+                new 
FileInputStream("test/java/org/apache/fop/pdf/PDFVT.xconf"));
+    }
+
+    private void iFToPDF(InputStream is) throws IOException, SAXException, 
TransformerException, IFException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+        FOUserAgent userAgent = getFopFactory().newFOUserAgent();
+        Transformer transformer = 
TransformerFactory.newInstance().newTransformer();
+        Source src = new StreamSource(is);
+        IFDocumentHandler documentHandler
+                = 
userAgent.getRendererFactory().createDocumentHandler(userAgent, 
MimeConstants.MIME_PDF);
+        documentHandler.setResult(new StreamResult(out));
+        IFUtil.setupFonts(documentHandler);
+        IFParser parser = new IFParser();
+        Result res = new SAXResult(parser.getContentHandler(documentHandler, 
userAgent));
+        transformer.transform(src, res);
+
+        checkPDF(out);
+    }
 
+    private void checkPDF(ByteArrayOutputStream out) throws IOException {
         Map<String, StringBuilder> objs =
                 PDFLinearizationTestCase.readObjs(new 
ByteArrayInputStream(out.toByteArray()));
         String dpart = getObj(objs.values(), "/DParts");



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to