]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
modify this class to only create a new PDFXobject if needed
authoreschaeffer <eschaeffer@unknown>
Tue, 23 May 2000 09:23:53 +0000 (09:23 +0000)
committereschaeffer <eschaeffer@unknown>
Tue, 23 May 2000 09:23:53 +0000 (09:23 +0000)
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

index a32342950ec6de1aa9e9426bf455778bfabdad42..ee0b39c538687982b36015e89a08b7b91bff5402 100644 (file)
@@ -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;
        }