From db0063f4d8c568ddc05c4d8c6151a742a6afb217 Mon Sep 17 00:00:00 2001 From: eschaeffer Date: Tue, 23 May 2000 09:23:53 +0000 Subject: [PATCH] modify this class to only create a new PDFXobject if needed git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193374 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/pdf/PDFDocument.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index a32342950..ee0b39c53 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -63,6 +63,7 @@ import org.apache.fop.datatypes.ColorSpace; import java.io.IOException; import java.io.PrintWriter; import java.util.Vector; +import java.util.Hashtable; import java.awt.Rectangle; /** @@ -123,6 +124,10 @@ public class PDFDocument { /** the XObjects */ protected Vector xObjects = new Vector(); + /** the XObjects Map. + Should be modified (works only for image subtype) */ + protected Hashtable xObjectsMap = new Hashtable(); + /** * creates an empty PDF document */ @@ -729,10 +734,16 @@ public class PDFDocument { } public int addImage(FopImage img) { - PDFXObject xObject = new PDFXObject(++this.objectcount, + // check if already created + String url = img.getURL(); + PDFXObject xObject = (PDFXObject) this.xObjectsMap.get(url); + if (xObject != null) return xObject.getXNumber(); + // else, create a new one + xObject = new PDFXObject(++this.objectcount, ++this.xObjectCount, img); this.objects.addElement(xObject); this.xObjects.addElement(xObject); + this.xObjectsMap.put(url, xObject); return xObjectCount; } -- 2.39.5