You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ss...@apache.org on 2021/02/25 14:11:37 UTC

svn commit: r1886918 - in /xmlgraphics/fop-pdf-images/trunk: src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java test/java/org/apache/fop/render/pdf/pdfbox/ test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java

Author: ssteiner
Date: Thu Feb 25 14:11:37 2021
New Revision: 1886918

URL: http://svn.apache.org/viewvc?rev=1886918&view=rev
Log:
FOP-3001: Deduplicate streams in arrays

Added:
    xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/pdfbox/
    xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java   (with props)
Modified:
    xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java

Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java?rev=1886918&r1=1886917&r2=1886918&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java Thu Feb 25 14:11:37 2021
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
@@ -78,6 +79,24 @@ public final class PDFBoxAdapterUtil {
         } else if (base instanceof COSObject) {
             COSObject obj = (COSObject) base;
             return "COSObject{" + getDictionaryHash(obj.getObject(), objs) + "}";
+        } else if (base instanceof COSArray) {
+            COSArray array = (COSArray) base;
+            StringBuilder sb = new StringBuilder("COSArray[");
+            for (Object o : array) {
+                if (o instanceof COSObject) {
+                    COSBase obj = ((COSObject) o).getObject();
+                    if (obj instanceof COSStream) {
+                        sb.append(getDictionaryHash(obj, objs));
+                    } else {
+                        sb.append(o);
+                    }
+                } else {
+                    sb.append(o);
+                }
+                sb.append(",");
+            }
+            sb.append("]");
+            return sb.toString();
         } else {
             return base.toString();
         }

Added: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java?rev=1886918&view=auto
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java (added)
+++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java Thu Feb 25 14:11:37 2021
@@ -0,0 +1,49 @@
+/*
+ * 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.pdfbox;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSObject;
+import org.apache.pdfbox.cos.COSStream;
+
+public class PDFClonerTestCase {
+    @Test
+    public void testCompareTree() throws IOException {
+        Assert.assertEquals(PDFBoxAdapterUtil.getBaseKey(makeTree(2)),
+                PDFBoxAdapterUtil.getBaseKey(makeTree(1)));
+    }
+
+    private COSDictionary makeTree(long objNumber) throws IOException {
+        COSStream stream = new COSStream();
+        COSObject obj = new COSObject(stream);
+        obj.setObjectNumber(objNumber);
+        COSArray array = new COSArray();
+        array.add(obj);
+        COSDictionary root = new COSDictionary();
+        root.setItem(COSName.C, array);
+        return root;
+    }
+}

Propchange: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native



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