xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sstei...@apache.org
Subject svn commit: r1657799 [2/2] - in /xmlgraphics/fop/branches/Temp_PDFLinearization: src/java/org/apache/fop/pdf/ src/java/org/apache/fop/pdf/xref/ src/java/org/apache/fop/render/pdf/ src/java/org/apache/fop/svg/ test/java/org/apache/fop/pdf/ test/java/org...
Date Fri, 06 Feb 2015 13:19:09 GMT
Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java
Fri Feb  6 13:19:08 2015
@@ -31,6 +31,7 @@ import org.apache.fop.pdf.PDFFactory;
 import org.apache.fop.pdf.PDFGoTo;
 import org.apache.fop.pdf.PDFLink;
 import org.apache.fop.pdf.PDFOutline;
+import org.apache.fop.pdf.PDFReference;
 import org.apache.fop.pdf.PDFStructElem;
 import org.apache.fop.render.intermediate.IFDocumentNavigationHandler;
 import org.apache.fop.render.intermediate.IFException;
@@ -87,7 +88,7 @@ public class PDFDocumentNavigationHandle
             parent = getPDFDoc().getOutlineRoot();
         }
         PDFAction action = getAction(bookmark.getAction());
-        String actionRef = (action != null ? action.makeReference().toString() : null);
+        PDFReference actionRef = (action != null ? action.makeReference() : null);
         PDFOutline pdfOutline = getPDFDoc().getFactory().makeOutline(parent,
             bookmark.getTitle(), actionRef, bookmark.isShown());
         Iterator iter = bookmark.getChildBookmarks().iterator();
@@ -194,7 +195,7 @@ public class PDFDocumentNavigationHandle
             p2d = new Point2D.Double(
                     action.getTargetLocation().x / 1000.0,
                     (pageRef.getPageDimension().height - action.getTargetLocation().y) /
1000.0);
-            String pdfPageRef = pageRef.getPageRef();
+            PDFReference pdfPageRef = pageRef.getPageRef();
             pdfGoTo.setPageReference(pdfPageRef);
             pdfGoTo.setPosition(p2d);
 

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFImageHandlerGraphics2D.java
Fri Feb  6 13:19:08 2015
@@ -85,7 +85,7 @@ public class PDFImageHandlerGraphics2D e
         final boolean textAsShapes = false;
         PDFGraphics2D graphics = new PDFGraphics2D(textAsShapes,
                 pdfContext.getFontInfo(), generator.getDocument(),
-                generator.getResourceContext(), pdfContext.getPage().referencePDF(),
+                generator.getResourceContext(), pdfContext.getPage().makeReference(),
                 "", 0.0f, null);
         graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
 

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java
Fri Feb  6 13:19:08 2015
@@ -171,7 +171,7 @@ public class PDFImageHandlerSVG implemen
 
         PDFGraphics2D graphics = new PDFGraphics2D(true, pdfContext.getFontInfo(),
                 generator.getDocument(),
-                generator.getResourceContext(), pdfContext.getPage().referencePDF(),
+                generator.getResourceContext(), pdfContext.getPage().makeReference(),
                 "", 0, new TransparencyIgnoredEventListener(pdfContext, imageSVG));
         graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
 

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererConfig.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererConfig.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererConfig.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererConfig.java
Fri Feb  6 13:19:08 2015
@@ -56,6 +56,7 @@ import static org.apache.fop.render.pdf.
 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.LINEARIZATION;
 import static org.apache.fop.render.pdf.PDFRendererOption.MERGE_FONTS;
 import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE;
 import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE;
@@ -137,6 +138,7 @@ public final class PDFRendererConfig imp
                 parseAndPut(OUTPUT_PROFILE, cfg);
                 parseAndPut(DISABLE_SRGB_COLORSPACE, cfg);
                 parseAndPut(MERGE_FONTS, cfg);
+                parseAndPut(LINEARIZATION, cfg);
 
                 parseAndPut(VERSION, cfg);
             } catch (ConfigurationException e) {

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererOption.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererOption.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererOption.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererOption.java
Fri Feb  6 13:19:08 2015
@@ -72,6 +72,12 @@ public enum PDFRendererOption implements
             return Boolean.valueOf(value);
         }
     },
+    LINEARIZATION("linearization", 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

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java
Fri Feb  6 13:19:08 2015
@@ -31,6 +31,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.LINEARIZATION;
 import static org.apache.fop.render.pdf.PDFRendererOption.MERGE_FONTS;
 import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE;
 import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE;
@@ -125,4 +126,8 @@ public final class PDFRendererOptionsCon
     public Boolean getMergeFontsEnabled() {
         return (Boolean)properties.get(MERGE_FONTS);
     }
+
+    public Boolean getLinearizationEnabled() {
+        return (Boolean)properties.get(LINEARIZATION);
+    }
 }

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
Fri Feb  6 13:19:08 2015
@@ -588,6 +588,7 @@ class PDFRenderingUtil {
 
         this.pdfDoc.enableAccessibility(userAgent.isAccessibilityEnabled());
         pdfDoc.setMergeFontsEnabled(rendererConfig.getMergeFontsEnabled());
+        pdfDoc.setLinearizationEnabled(rendererConfig.getLinearizationEnabled());
 
         return this.pdfDoc;
     }

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
Fri Feb  6 13:19:08 2015
@@ -337,7 +337,7 @@ public class PDFDocumentGraphics2D exten
                 width, height);
         resourceContext = page;
         pdfContext.setCurrentPage(page);
-        pageRef = page.referencePDF();
+        pageRef = page.makeReference();
 
         currentStream.write("q\n");
         AffineTransform at = new AffineTransform(1.0, 0.0, 0.0, -1.0,

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/svg/PDFGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/svg/PDFGraphics2D.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/svg/PDFGraphics2D.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/src/java/org/apache/fop/svg/PDFGraphics2D.java
Fri Feb  6 13:19:08 2015
@@ -88,6 +88,7 @@ import org.apache.fop.pdf.PDFLink;
 import org.apache.fop.pdf.PDFNumber;
 import org.apache.fop.pdf.PDFPaintingState;
 import org.apache.fop.pdf.PDFPattern;
+import org.apache.fop.pdf.PDFReference;
 import org.apache.fop.pdf.PDFResourceContext;
 import org.apache.fop.pdf.PDFResources;
 import org.apache.fop.pdf.PDFShading;
@@ -132,7 +133,7 @@ public class PDFGraphics2D extends Abstr
     /**
      * The PDF reference of the current page.
      */
-    protected String pageRef;
+    protected PDFReference pageRef;
 
     /**
      * The PDF painting state
@@ -212,7 +213,7 @@ public class PDFGraphics2D extends Abstr
      * @param size the current font size
      */
     public PDFGraphics2D(boolean textAsShapes, FontInfo fi, PDFDocument doc,
-                         PDFResourceContext page, String pref, String font, float size,
+                         PDFResourceContext page, PDFReference pref, String font, float size,
                          TransparencyIgnoredEventListener listener) {
         this(textAsShapes);
         pdfDoc = doc;
@@ -331,7 +332,7 @@ public class PDFGraphics2D extends Abstr
      * Gets the PDF reference of the current page.
      * @return the PDF reference of the current page
      */
-    public String getPageReference() {
+    public PDFReference getPageReference() {
         return this.pageRef;
     }
 
@@ -422,7 +423,7 @@ public class PDFGraphics2D extends Abstr
             if (linkType != PDFLink.EXTERNAL) {
                 String pdfdest = "/FitR " + dest;
                 resourceContext.addAnnotation(
-                    pdfDoc.getFactory().makeLink(rect, getPageReference(), pdfdest));
+                    pdfDoc.getFactory().makeLink(rect, getPageReference().toString(), pdfdest));
             } else {
                 resourceContext.addAnnotation(
                     pdfDoc.getFactory().makeLink(rect, dest, linkType, 0));
@@ -1068,13 +1069,13 @@ public class PDFGraphics2D extends Abstr
                 }
             }
 
-            String maskRef = null;
+            PDFReference maskRef = null;
             if (mask != null) {
                 BitmapImage fopimg = new BitmapImage(
                     "TempImageMask:" + pctx.toString(), devW, devH, mask, null);
                 fopimg.setColorSpace(new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_GRAY));
                 PDFImageXObject xobj = pdfDoc.addImage(resourceContext, fopimg);
-                maskRef = xobj.referencePDF();
+                maskRef = xobj.makeReference();
 
                 flushPDFDocument();
             }

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/AbstractPDFStreamTestCase.java
Fri Feb  6 13:19:08 2015
@@ -49,7 +49,7 @@ public class AbstractPDFStreamTestCase e
             encodedBytes[i++] = (byte) (in & 0xff);
         }
     }
-    private String startStream = "<< /Length 5 0 R /Filter /FlateDecode >>\n"
+    private String startStream = "<< /Length 1 0 R /Filter /FlateDecode >>\n"
                 + "stream\n";
 
     private String endStream = "endstream";

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/ObjectStreamManagerTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/ObjectStreamManagerTestCase.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/ObjectStreamManagerTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/ObjectStreamManagerTestCase.java
Fri Feb  6 13:19:08 2015
@@ -46,7 +46,7 @@ public class ObjectStreamManagerTestCase
         int objectStreamNumber2 = assertSameObjectStream(expectedCapacity, expectedCapacity
* 2);
         int objectStreamNumber3 = assertSameObjectStream(expectedCapacity * 2, numCompressedObjects);
         assertDifferent(objectStreamNumber1, objectStreamNumber2, objectStreamNumber3);
-        assertEquals(objectStreamNumber3, pdfDocument.previous.getObjectNumber());
+        assertEquals(objectStreamNumber3, pdfDocument.previous.getObjectNumber().getNumber());
     }
 
     private void createCompressObjectReferences(int numObjects) {
@@ -82,8 +82,8 @@ public class ObjectStreamManagerTestCase
     private CompressedObject createCompressedObject(final int objectNumber) {
         return new CompressedObject() {
 
-            public int getObjectNumber() {
-                return objectNumber;
+            public PDFObjectNumber getObjectNumber() {
+                return new PDFObjectNumber(objectNumber);
             }
 
             public int output(OutputStream outputStream) throws IOException {
@@ -101,7 +101,7 @@ public class ObjectStreamManagerTestCase
     }
 
     private int getObjectStreamNumber(int index) {
-        return compressedObjectReferences.get(index).getObjectStreamNumber();
+        return compressedObjectReferences.get(index).getObjectStreamNumber().getNumber();
     }
 
     private void assertDifferent(int objectStreamNumber1, int objectStreamNumber2,

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/ObjectStreamTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/ObjectStreamTestCase.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/ObjectStreamTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/ObjectStreamTestCase.java
Fri Feb  6 13:19:08 2015
@@ -86,13 +86,14 @@ public class ObjectStreamTestCase {
 
     private String getExpectedOutput() {
         int numObs = compressedObjects.size();
-        int objectStreamNumber = objectStream.getObjectNumber();
+        int objectStreamNumber = objectStream.getObjectNumber().getNumber();
         int offsetsLength = 9;
         StringBuilder expected = new StringBuilder();
         expected.append("<<\n");
         ObjectStream previous = (ObjectStream) objectStream.get("Extends");
         if (previous != null) {
             expected.append("  /Extends ").append(previous.getObjectNumber()).append(" 0
R\n");
+            objectStreamNumber++;
         }
         expected.append("  /Type /ObjStm\n")
                 .append("  /N ").append(numObs).append("\n")

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFEncryptionJCETestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFEncryptionJCETestCase.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFEncryptionJCETestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFEncryptionJCETestCase.java
Fri Feb  6 13:19:08 2015
@@ -286,7 +286,7 @@ public class PDFEncryptionJCETestCase {
     public final void testMake() {
         PDFEncryption testEncryptionObj = createEncryptionObject(new PDFEncryptionParams());
         assertTrue(testEncryptionObj instanceof PDFEncryptionJCE);
-        assertEquals(1, ((PDFEncryptionJCE) testEncryptionObj).getObjectNumber());
+        assertEquals(1, ((PDFEncryptionJCE) testEncryptionObj).getObjectNumber().getNumber());
     }
 
     @Test
@@ -608,7 +608,7 @@ public class PDFEncryptionJCETestCase {
                 };
             }
         };
-        return (PDFEncryptionJCE) PDFEncryptionJCE.make(1, params, doc);
+        return (PDFEncryptionJCE) PDFEncryptionJCE.make(new PDFObjectNumber(1), params, doc);
     }
 
     private void runEncryptionTests() throws IOException {

Added: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFLinearizationTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFLinearizationTestCase.java?rev=1657799&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFLinearizationTestCase.java
(added)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFLinearizationTestCase.java
Fri Feb  6 13:19:08 2015
@@ -0,0 +1,275 @@
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.fop.render.pdf.PDFContentGenerator;
+
+public class PDFLinearizationTestCase {
+    private int objectLeast;
+    private int[] objects;
+
+    @Test
+    public void testPDF() throws IOException {
+        PDFDocument doc = new PDFDocument("");
+        doc.setLinearizationEnabled(true);
+        PDFResources resources = new PDFResources(doc);
+        PDFResourceContext context = new PDFResourceContext(resources);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        PDFContentGenerator gen = null;
+        for (int i = 0; i < 2; i++) {
+            gen = new PDFContentGenerator(doc, out, context);
+            Rectangle2D.Float f = new Rectangle2D.Float();
+            PDFPage page = new PDFPage(resources, i, f, f, f, f);
+            doc.registerObject(page);
+//            doc.registerObject(gen.getStream());
+            page.setContents(gen.getStream());
+        }
+        gen.flushPDFDoc();
+        byte[] data = out.toByteArray();
+        checkPDF(data);
+    }
+
+    private void checkPDF(byte[] data) throws IOException {
+        checkHintTable(data);
+        InputStream is = new ByteArrayInputStream(data);
+        Map<String, StringBuilder> objs = readObjs(is);
+
+        List<String> keys = new ArrayList<String>(objs.keySet());
+        int start = keys.indexOf("1 0 obj");
+        Assert.assertTrue(start > 1);
+        int j = 1;
+        for (int i = start; i < keys.size(); i++) {
+            Assert.assertEquals(keys.get(i), j + " 0 obj");
+            j++;
+        }
+        for (int i = 0; i < start; i++) {
+            Assert.assertEquals(keys.get(i), j + " 0 obj");
+            j++;
+        }
+
+        checkFirstObj(data);
+        checkTrailer(data);
+
+        String firstObj = objs.values().iterator().next().toString().replace("\n", "");
+        Assert.assertTrue(firstObj.startsWith("<<  /Linearized 1  /L " + data.length));
+        Assert.assertTrue(firstObj.endsWith("startxref0%%EOF"));
+        int pageObjNumber = getValue("/O", firstObj);
+        Assert.assertTrue(objs.get(pageObjNumber + " 0 obj").toString().contains("/Type /Page"));
+        Assert.assertTrue(objs.get("5 0 obj").toString().contains("/Type /Pages"));
+
+        int total = 0;
+        for (int i : objects) {
+            total += i;
+        }
+        Assert.assertEquals(total, objs.size() - 6);
+    }
+
+    private void checkFirstObj(byte[] data) throws IOException {
+        int firstObjPos = getValue("/E", getFirstObj(data));
+        InputStream is = new ByteArrayInputStream(data);
+        Assert.assertEquals(is.skip(firstObjPos), firstObjPos);
+        byte[] obj = new byte[10];
+        Assert.assertEquals(is.read(obj), obj.length);
+        Assert.assertTrue(new String(obj).startsWith("1 0 obj"));
+    }
+
+    private void checkTrailer(byte[] data) throws IOException {
+        int trailerPos = getValue("/T", getFirstObj(data));
+        InputStream is = new ByteArrayInputStream(data);
+        Assert.assertEquals(is.skip(trailerPos), trailerPos);
+        byte[] obj = new byte[20];
+        Assert.assertEquals(is.read(obj), obj.length);
+        Assert.assertTrue(new String(obj).startsWith("0000000000 65535 f"));
+    }
+
+    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 int[] getArrayValue(String name, String firstObj) throws IOException {
+        String[] split = firstObj.split(" ");
+        for (int i = 0; i < split.length; i++) {
+            if (split[i].equals(name)) {
+                int[] v = new int[2];
+                v[0] = Integer.valueOf(split[i + 1].replace("[", ""));
+                v[1] = Integer.valueOf(split[i + 2].replace("]", ""));
+                return v;
+            }
+        }
+        throw new IOException(name + " not found " + firstObj);
+    }
+
+    private String getFirstObj(byte[] out) throws IOException {
+        InputStream data = new ByteArrayInputStream(out);
+        Map<String, StringBuilder> objs = readObjs(data);
+        return objs.values().iterator().next().toString().replace("\n", "");
+    }
+
+    private void checkHintTable(byte[] out) throws IOException {
+        String firstObj = getFirstObj(out);
+        int hintPos = getArrayValue("/H", firstObj)[0];
+        int hintLength = getArrayValue("/H", firstObj)[1];
+
+        InputStream data = new ByteArrayInputStream(out);
+        Assert.assertEquals(data.skip(hintPos), hintPos);
+
+        byte[] hintTable = new byte[hintLength];
+        Assert.assertEquals(data.read(hintTable), hintLength);
+        String hintTableStr = new String(hintTable);
+
+        Assert.assertTrue(hintTableStr.contains("/S "));
+        Assert.assertTrue(hintTableStr.contains("/C "));
+        Assert.assertTrue(hintTableStr.contains("/E "));
+        Assert.assertTrue(hintTableStr.contains("/L "));
+        Assert.assertTrue(hintTableStr.contains("/V "));
+        Assert.assertTrue(hintTableStr.contains("/O "));
+        Assert.assertTrue(hintTableStr.contains("/I "));
+        Assert.assertTrue(hintTableStr.contains("/Length "));
+        Assert.assertTrue(hintTableStr.contains("stream"));
+        Assert.assertTrue(hintTableStr.contains("endstream"));
+        Assert.assertTrue(hintTableStr.endsWith("endobj\n"));
+
+        data = new ByteArrayInputStream(hintTable);
+        readStart(data);
+        int pages = getValue("/N", firstObj);
+        readObjectsTable(data, pages);
+        readSharedObjectsTable(data);
+        Assert.assertEquals(objectLeast, 1);
+    }
+
+    private void readObjectsTable(InputStream data, int pages)
+            throws IOException {
+        objectLeast = read32(data);
+        read32(data);
+        int bitsDiffObjects = read16(data);
+        read32(data);
+        int bitsDiffPageLength = read16(data);
+        read32(data);
+        read16(data);
+        read32(data);
+        read16(data);
+        read16(data);
+        read16(data);
+        read16(data);
+        read16(data);
+
+        objects = new int[pages];
+        for (int i = 0; i < pages; i++) {
+            objects[i] = objectLeast + readBits(bitsDiffObjects, data);
+        }
+        for (int i = 0; i < pages; i++) {
+            readBits(bitsDiffPageLength, data);
+        }
+        for (int i = 0; i < pages; i++) {
+            readBits(32, data);
+        }
+    }
+
+    private void readSharedObjectsTable(InputStream str) throws IOException {
+        readBits(32, str);
+        readBits(32, str);
+        readBits(32, str);
+        int sharedGroups = readBits(32, str);
+        readBits(16, str);
+        readBits(32, str);
+        int bitsDiffGroupLength = readBits(16, str);
+        for (int i = 0; i < sharedGroups; i++) {
+            readBits(bitsDiffGroupLength, str);
+        }
+    }
+
+    private int readBits(int bits, InputStream data) throws IOException {
+        if (bits == 32) {
+            return read32(data);
+        }
+        if (bits == 16) {
+            return read16(data);
+        }
+        throw new IOException("Wrong bits");
+    }
+
+    private int read32(InputStream data) throws IOException {
+        int ch1 = data.read();
+        int ch2 = data.read();
+        int ch3 = data.read();
+        int ch4 = data.read();
+        return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4));
+    }
+
+    private int read16(InputStream data) throws IOException {
+        int ch1 = data.read();
+        int ch2 = data.read();
+        return (ch1 << 8) + (ch2);
+    }
+
+    private void readStart(InputStream inputStream) throws IOException {
+        StringBuilder sb = new StringBuilder();
+        while (inputStream.available() > 0) {
+            int data = inputStream.read();
+            if (data == '\n') {
+                if (sb.toString().equals("stream")) {
+                    return;
+                }
+                sb.setLength(0);
+            } else {
+                sb.append((char)data);
+            }
+        }
+    }
+
+    private Map<String, StringBuilder> readObjs(InputStream inputStream) throws IOException
{
+        Map<String, StringBuilder> objs = new LinkedHashMap<String, StringBuilder>();
+        StringBuilder sb = new StringBuilder();
+        String key = null;
+        while (inputStream.available() > 0) {
+            int data = inputStream.read();
+            if (data == '\n') {
+                if (sb.toString().endsWith(" 0 obj")) {
+                    key = sb.toString().trim();
+                    objs.put(key, new StringBuilder());
+                } else if (key != null) {
+                    objs.get(key).append(sb).append("\n");
+                }
+                sb.setLength(0);
+            } else {
+                sb.append((char)data);
+            }
+        }
+        return objs;
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFLinearizationTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFObjectTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFObjectTestCase.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFObjectTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/PDFObjectTestCase.java
Fri Feb  6 13:19:08 2015
@@ -58,10 +58,10 @@ public class PDFObjectTestCase {
     @Test
     public void testSetObjectNumber() {
         pdfObjectUnderTest.setObjectNumber(1);
-        assertEquals(1, pdfObjectUnderTest.getObjectNumber());
+        assertEquals(1, pdfObjectUnderTest.getObjectNumber().getNumber());
 
         pdfObjectUnderTest.setObjectNumber(5);
-        assertEquals(5, pdfObjectUnderTest.getObjectNumber());
+        assertEquals(5, pdfObjectUnderTest.getObjectNumber().getNumber());
     }
 
     /**
@@ -157,12 +157,12 @@ public class PDFObjectTestCase {
         PDFDictionary dict = new PDFDictionary();
         dict.setObjectNumber(7);
         PDFReference ref = dict.makeReference();
-        assertEquals(ref.getObjectNumber(), 7);
+        assertEquals(ref.getObjectNumber().getNumber(), 7);
         assertEquals(ref.getGeneration(), 0);
         assertEquals(ref.toString(), "7 0 R");
 
         ref = new PDFReference("8 0 R");
-        assertEquals(ref.getObjectNumber(), 8);
+        assertEquals(ref.getObjectNumber().getNumber(), 8);
         assertEquals(ref.getGeneration(), 0);
         assertEquals(ref.toString(), "8 0 R");
     }

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CompressedObjectReferenceTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CompressedObjectReferenceTestCase.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CompressedObjectReferenceTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CompressedObjectReferenceTestCase.java
Fri Feb  6 13:19:08 2015
@@ -27,6 +27,8 @@ import org.junit.Test;
 
 import static org.junit.Assert.assertArrayEquals;
 
+import org.apache.fop.pdf.PDFObjectNumber;
+
 public class CompressedObjectReferenceTestCase extends ObjectReferenceTest {
 
     @Test
@@ -41,7 +43,7 @@ public class CompressedObjectReferenceTe
 
     private void runTest(List<Integer> expectedObjectStreamBytes, int index) throws
IOException {
         int objectStreamNumber = (int) computeNumberFromBytes(expectedObjectStreamBytes);
-        sut = new CompressedObjectReference(0, objectStreamNumber, index);
+        sut = new CompressedObjectReference(new PDFObjectNumber(0), new PDFObjectNumber(objectStreamNumber),
index);
         byte[] expected = createExpectedOutput((byte) 2, expectedObjectStreamBytes, index);
         byte[] actual = getActualOutput();
         assertArrayEquals(expected, actual);

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceObjectTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceObjectTest.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceObjectTest.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceObjectTest.java
Fri Feb  6 13:19:08 2015
@@ -52,7 +52,7 @@ public abstract class CrossReferenceObje
         pdfDocument = new PDFDocument("Apache FOP");
         Map<String, List<String>> filterMap = pdfDocument.getFilterMap();
         filterMap.put("default", Arrays.asList("null"));
-        PDFRoot root = new PDFRoot(1, new PDFPages(10));
+        PDFRoot root = new PDFRoot(pdfDocument, new PDFPages(pdfDocument));
         PDFInfo info = new PDFInfo();
         info.setObjectNumber(2);
         byte[] fileID =

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceStreamTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceStreamTestCase.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceStreamTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceStreamTestCase.java
Fri Feb  6 13:19:08 2015
@@ -29,6 +29,8 @@ import java.util.List;
 
 import org.junit.Test;
 
+import org.apache.fop.pdf.PDFObjectNumber;
+
 public class CrossReferenceStreamTestCase extends CrossReferenceObjectTest {
 
     private List<Long> uncompressedObjectOffsets;
@@ -54,7 +56,7 @@ public class CrossReferenceStreamTestCas
     @Test
     public void testWithObjectStreams1() throws IOException {
         List<CompressedObjectReference> compressedObjectReferences =
-                Arrays.asList(new CompressedObjectReference(2, 1, 0));
+                Arrays.asList(new CompressedObjectReference(new PDFObjectNumber(2), new PDFObjectNumber(1),
0));
         test(Arrays.asList(0L, null), compressedObjectReferences);
     }
 
@@ -72,8 +74,8 @@ public class CrossReferenceStreamTestCas
         for (int index = 0; index < numCompressedObjects; index++) {
             indirectObjectOffsets.add(null);
             int obNum = numIndirectObjects + index + 1;
-            compressedObjectReferences.add(new CompressedObjectReference(obNum,
-                    numIndirectObjects, index));
+            compressedObjectReferences.add(new CompressedObjectReference(new PDFObjectNumber(obNum),
+                    new PDFObjectNumber(numIndirectObjects), index));
         }
         test(indirectObjectOffsets, compressedObjectReferences);
     }
@@ -108,7 +110,7 @@ public class CrossReferenceStreamTestCas
             objectReferences.add(offset == null ? null : new UncompressedObjectReference(offset));
         }
         for (CompressedObjectReference ref : compressedObjectReferences) {
-            objectReferences.set(ref.getObjectNumber() - 1, ref);
+            objectReferences.set(ref.getObjectNumber().getNumber() - 1, ref);
         }
         int maxObjectNumber = objectReferences.size() + 1;
         ByteArrayOutputStream stream = new ByteArrayOutputStream();

Modified: xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceTableTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceTableTestCase.java?rev=1657799&r1=1657798&r2=1657799&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceTableTestCase.java
(original)
+++ xmlgraphics/fop/branches/Temp_PDFLinearization/test/java/org/apache/fop/pdf/xref/CrossReferenceTableTestCase.java
Fri Feb  6 13:19:08 2015
@@ -53,7 +53,7 @@ public class CrossReferenceTableTestCase
 
     @Override
     protected CrossReferenceObject createCrossReferenceObject() {
-        return new CrossReferenceTable(trailerDictionary, STARTXREF, offsets);
+        return new CrossReferenceTable(trailerDictionary, STARTXREF, offsets, 0, offsets.size(),
offsets.size());
     }
 
     @Override



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message