Author: ssteiner
Date: Wed Jul 12 10:21:56 2017
New Revision: 1801716
URL: http://svn.apache.org/viewvc?rev=1801716&view=rev
Log:
FOP-2723: PDF to PDF deduplicate more types of streams
Modified:
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.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=1801716&r1=1801715&r2=1801716&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
Wed Jul 12 10:21:56 2017
@@ -44,14 +44,7 @@ public final class PDFBoxAdapterUtil {
}
private static Integer getStreamHash(COSStream o) throws IOException {
- for (COSBase x : o.getValues()) {
- if (x instanceof COSObject || x instanceof COSDictionary) {
- return null;
- }
- }
- InputStream stream = o.getFilteredStream();
- byte[] b = IOUtils.toByteArray(stream);
- return Arrays.deepHashCode(new Object[]{b, o.toString()});
+ return getDictionaryHash(o).hashCode();
}
private static String getDictionaryHash(COSBase base) throws IOException {
Modified:
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java?rev=1801716&r1=1801715&r2=1801716&view=diff
==============================================================================
---
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
(original)
+++
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
Wed Jul 12 10:21:56 2017
@@ -29,6 +29,7 @@ import java.io.OutputStream;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
@@ -196,10 +197,7 @@ public class PDFBoxAdapterTestCase {
@Test
public void testTaggedPDFWriter() throws IOException {
- PDFDocument pdfdoc = new PDFDocument("");
- PDFPage pdfpage = getPDFPage(pdfdoc);
- pdfpage.setDocument(pdfdoc);
- PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap(), new
HashMap<Integer, PDFArray>());
+ PDFBoxAdapter adapter = getPDFBoxAdapter(false);
adapter.setCurrentMCID(5);
PDDocument doc = PDDocument.load(new File(HELLOTagged));
PDPage page = doc.getPage(0);
@@ -440,23 +438,14 @@ public class PDFBoxAdapterTestCase {
@Test
public void testPDFCache() throws IOException {
PDFDocument pdfdoc = new PDFDocument("");
- PDFPage pdfpage = getPDFPage(pdfdoc);
- pdfdoc.assignObjectNumber(pdfpage);
- pdfpage.setDocument(pdfdoc);
- Map<Object, Object> pdfCache = new HashMap<Object, Object>();
- Map<Object, Object> objectCachePerFile = new HashMap<Object, Object>();
- PDFBoxAdapter adapter = new PDFBoxAdapter(
- pdfpage, objectCachePerFile, new HashMap<Integer, PDFArray>(),
pdfCache);
- PDDocument doc = PDDocument.load(new File(LOOP));
- PDPage page = doc.getPage(0);
- adapter.createStreamFromPDFBoxPage(doc, page, "key", new
AffineTransform(), null, new Rectangle());
- doc.close();
+ Map<Object, Object> pdfCache = new LinkedHashMap<Object, Object>();
+ Map<Object, Object> objectCachePerFile = loadPDFWithCache(pdfdoc,
pdfCache, LOOP);
Object item = pdfCache.values().iterator().next();
Assert.assertEquals(item.getClass(), PDFStream.class);
item = pdfCache.keySet().iterator().next();
Assert.assertEquals(item.getClass(), Integer.class);
- Assert.assertEquals(pdfCache.size(), 11);
+ Assert.assertEquals(pdfCache.size(), 12);
int pdfDictionary = 0;
int strings = 0;
@@ -469,10 +458,37 @@ public class PDFBoxAdapterTestCase {
}
}
Assert.assertEquals(pdfDictionary, 26);
- Assert.assertEquals(strings, 34);
+ Assert.assertEquals(strings, 33);
Assert.assertEquals(objectCachePerFile.size(), 45);
}
+ private Map<Object, Object> loadPDFWithCache(PDFDocument pdfdoc,
Map<Object, Object> pdfCache, String pdf)
+ throws IOException {
+ Map<Object, Object> objectCachePerFile = new LinkedHashMap<Object,
Object>();
+ PDFPage pdfpage = getPDFPage(pdfdoc);
+ pdfdoc.assignObjectNumber(pdfpage);
+ pdfpage.setDocument(pdfdoc);
+ PDFBoxAdapter adapter = new PDFBoxAdapter(
+ pdfpage, objectCachePerFile, new HashMap<Integer, PDFArray>(),
pdfCache);
+ PDDocument doc = PDDocument.load(new File(pdf));
+ PDPage page = doc.getPage(0);
+ adapter.createStreamFromPDFBoxPage(doc, page, "key", new
AffineTransform(), null, new Rectangle());
+ doc.close();
+ return objectCachePerFile;
+ }
+
+ @Test
+ public void testPDFSize() throws IOException {
+ PDFDocument pdfdoc = new PDFDocument("");
+ Map<Object, Object> pdfCache = new HashMap<Object, Object>();
+ loadPDFWithCache(pdfdoc, pdfCache, ANNOT);
+ loadPDFWithCache(pdfdoc, pdfCache, ANNOT);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ pdfdoc.output(bos);
+ Assert.assertEquals(pdfCache.size(), 2);
+ Assert.assertTrue(bos.size() <= 6418);
+ }
+
@Test
public void testErrorMsgToPS() throws IOException, ImageException {
String msg = "";
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]