]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Keep a reference to a pageRef string, not to the page itself; suggested by Alexis...
authorSimon Pepping <spepping@apache.org>
Thu, 23 Dec 2010 10:28:11 +0000 (10:28 +0000)
committerSimon Pepping <spepping@apache.org>
Thu, 23 Dec 2010 10:28:11 +0000 (10:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1052214 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java
src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java

index c7210344d43dc45facb968a43a12800c872f85cf..1cf2911126b81d52f2140521057d51a4e8a3db08 100644 (file)
@@ -39,7 +39,6 @@ import org.apache.fop.fo.extensions.xmp.XMPMetadata;
 import org.apache.fop.pdf.PDFAnnotList;
 import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFPage;
-import org.apache.fop.pdf.PDFReference;
 import org.apache.fop.pdf.PDFResourceContext;
 import org.apache.fop.pdf.PDFResources;
 import org.apache.fop.render.extensions.prepress.PageBoundaries;
@@ -93,7 +92,8 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
     protected PageReference currentPageRef;
 
     /** Used for bookmarks/outlines. */
-    protected Map pageReferences = new java.util.HashMap();
+    protected Map<Integer, PageReference> pageReferences =
+        new java.util.HashMap<Integer, PageReference>();
 
     private final PDFDocumentNavigationHandler documentNavigationHandler
             = new PDFDocumentNavigationHandler(this);
@@ -238,7 +238,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
         pdfUtil.generatePageLabel(index, name);
 
         currentPageRef = new PageReference(currentPage, size);
-        this.pageReferences.put(new Integer(index), currentPageRef);
+        this.pageReferences.put(Integer.valueOf(index), currentPageRef);
 
         this.generator = new PDFContentGenerator(this.pdfDoc, this.outputStream,
                 this.currentPage);
@@ -308,21 +308,22 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
     }
 
     PageReference getPageReference(int pageIndex) {
-        return (PageReference)this.pageReferences.get(
-                new Integer(pageIndex));
+        return this.pageReferences.get(Integer.valueOf(pageIndex));
     }
 
     static final class PageReference {
 
-        private final PDFReference pageRef;
+        private final String pageRef;
         private final Dimension pageDimension;
 
         private PageReference(PDFPage page, Dimension dim) {
-            this.pageRef = page.makeReference();
+            // Avoid keeping references to PDFPage as memory usage is
+            // considerably increased when handling thousands of pages.
+            this.pageRef = page.makeReference().toString();
             this.pageDimension = new Dimension(dim);
         }
 
-        public PDFReference getPageRef() {
+        public String getPageRef() {
             return this.pageRef;
         }
 
index c215243a7d437a1d3647a34c9bb67cdab9ece7c2..c8fa481d4ade4a61e8ad1a4c1beaa1aec27cf65f 100644 (file)
@@ -189,7 +189,7 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler
         p2d = new Point2D.Double(
                 action.getTargetLocation().x / 1000.0,
                 (pageRef.getPageDimension().height - action.getTargetLocation().y) / 1000.0);
-        String pdfPageRef = pageRef.getPageRef().toString();
+        String pdfPageRef = pageRef.getPageRef();
         pdfGoTo.setPageReference(pdfPageRef);
         pdfGoTo.setPosition(p2d);