From: Simon Pepping Date: Thu, 23 Dec 2010 10:28:11 +0000 (+0000) Subject: Keep a reference to a pageRef string, not to the page itself; suggested by Alexis... X-Git-Tag: fop-1_1rc1old~388 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c65432227a41435e7955060b1bd140d41a446a7e;p=xmlgraphics-fop.git Keep a reference to a pageRef string, not to the page itself; suggested by Alexis Giotis git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1052214 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java b/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java index c7210344d..1cf291112 100644 --- a/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java @@ -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 pageReferences = + new java.util.HashMap(); 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; } diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java b/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java index c215243a7..c8fa481d4 100644 --- a/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java @@ -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);