diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-10-18 16:06:31 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-10-18 16:06:31 +0000 |
commit | 20be3fe07bda82ab51d180744cba05ed707d8276 (patch) | |
tree | e7b9a68ba93e08aa7b77fd8b38a8cafbf7a69fda /src/java/org/apache/fop/pdf | |
parent | 4273340fedb25e6f3ea47f5750d3c5592fd4630f (diff) | |
download | xmlgraphics-fop-20be3fe07bda82ab51d180744cba05ed707d8276.tar.gz xmlgraphics-fop-20be3fe07bda82ab51d180744cba05ed707d8276.zip |
Fix for internal forward references in PDF output (basic-link with internal-destination):
Implemented by making out-of-order processing possible. The problem will still surface if supportsOutOfOrder() returns false.
PDF library now supports the addition of pages in non-consecutive order. This is a backwards-compatible change. The old behaviour and the old method signatures are still in place.
PageViewport now carries a page index which doesn't represent the page number but the overall index of the page within the current rendering run.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@326133 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/pdf')
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFFactory.java | 27 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFPage.java | 44 | ||||
-rw-r--r-- | src/java/org/apache/fop/pdf/PDFPages.java | 22 |
3 files changed, 67 insertions, 26 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFFactory.java b/src/java/org/apache/fop/pdf/PDFFactory.java index 28a14e8ef..bacb3251c 100644 --- a/src/java/org/apache/fop/pdf/PDFFactory.java +++ b/src/java/org/apache/fop/pdf/PDFFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -133,26 +133,43 @@ public class PDFFactory { * PDFDocument later using addObject(). * * @param resources resources object to use - * @param pagewidth width of the page in points - * @param pageheight height of the page in points + * @param pageWidth width of the page in points + * @param pageHeight height of the page in points + * @param pageIndex index of the page (zero-based) * * @return the created /Page object */ public PDFPage makePage(PDFResources resources, - int pagewidth, int pageheight) { + int pageWidth, int pageHeight, int pageIndex) { /* * create a PDFPage with the next object number, the given * resources, contents and dimensions */ PDFPage page = new PDFPage(resources, - pagewidth, pageheight); + pageWidth, pageHeight, pageIndex); getDocument().assignObjectNumber(page); getDocument().getPages().addPage(page); return page; } + /** + * Make a /Page object. The page is assigned an object number immediately + * so references can already be made. The page must be added to the + * PDFDocument later using addObject(). + * + * @param resources resources object to use + * @param pageWidth width of the page in points + * @param pageHeight height of the page in points + * + * @return the created /Page object + */ + public PDFPage makePage(PDFResources resources, + int pageWidth, int pageHeight) { + return makePage(resources, pageWidth, pageHeight, -1); + } + /* ========================= functions ================================= */ /** diff --git a/src/java/org/apache/fop/pdf/PDFPage.java b/src/java/org/apache/fop/pdf/PDFPage.java index 74932403f..bd00cbd2d 100644 --- a/src/java/org/apache/fop/pdf/PDFPage.java +++ b/src/java/org/apache/fop/pdf/PDFPage.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,6 +48,9 @@ public class PDFPage extends PDFResourceContext { */ protected int pageheight; + /** the page index (zero-based) */ + protected int pageIndex; + /** * Duration to display page */ @@ -59,41 +62,38 @@ public class PDFPage extends PDFResourceContext { protected TransitionDictionary trDictionary = null; /** - * create a /Page object + * Create a /Page object * * @param resources the /Resources object * @param contents the content stream - * @param pagewidth the page's width in points - * @param pageheight the page's height in points + * @param pageWidth the page's width in points + * @param pageHeight the page's height in points + * @param pageIndex the page's zero-based index (or -1 if the page number is auto-determined) */ public PDFPage(PDFResources resources, PDFStream contents, - int pagewidth, int pageheight) { + int pageWidth, int pageHeight, int pageIndex) { /* generic creation of object */ super(resources); /* set fields using parameters */ this.contents = contents; - this.pagewidth = pagewidth; - this.pageheight = pageheight; + this.pagewidth = pageWidth; + this.pageheight = pageHeight; + this.pageIndex = pageIndex; } /** - * create a /Page object + * Create a /Page object * * @param resources the /Resources object - * @param pagewidth the page's width in points - * @param pageheight the page's height in points + * @param pageWidth the page's width in points + * @param pageHeight the page's height in points + * @param pageIndex the page's zero-based index (or -1 if the page number is auto-determined) */ public PDFPage(PDFResources resources, - int pagewidth, int pageheight) { - - /* generic creation of object */ - super(resources); - - /* set fields using parameters */ - this.pagewidth = pagewidth; - this.pageheight = pageheight; + int pageWidth, int pageHeight, int pageIndex) { + this(resources, null, pageWidth, pageHeight, pageIndex); } /** @@ -144,6 +144,14 @@ public class PDFPage extends PDFResourceContext { } /** + * @return the page Index of this page (zero-based), -1 if it the page index should + * automatically be determined. + */ + public int getPageIndex() { + return this.pageIndex; + } + + /** * @see org.apache.fop.pdf.PDFObject#toPDFString() */ public String toPDFString() { diff --git a/src/java/org/apache/fop/pdf/PDFPages.java b/src/java/org/apache/fop/pdf/PDFPages.java index aae5c6c90..6ce4830e1 100644 --- a/src/java/org/apache/fop/pdf/PDFPages.java +++ b/src/java/org/apache/fop/pdf/PDFPages.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,7 +72,19 @@ public class PDFPages extends PDFObject { * @param page the child page */ public void notifyKidRegistered(PDFPage page) { - this.kids.add(page.referencePDF()); + int idx = page.getPageIndex(); + if (idx >= 0) { + while (idx > this.kids.size() - 1) { + this.kids.add(null); + } + if (this.kids.get(idx) != null) { + throw new IllegalStateException("A page already exists at index " + + idx + " (zero-based)."); + } + this.kids.set(idx, page.referencePDF()); + } else { + this.kids.add(page.referencePDF()); + } } /** @@ -102,7 +114,11 @@ public class PDFPages extends PDFObject { append(this.getCount()). append("\n/Kids ["); for (int i = 0; i < kids.size(); i++) { - sb.append(kids.get(i)).append(" "); + Object kid = kids.get(i); + if (kid == null) { + throw new IllegalStateException("Gap in the kids list!"); + } + sb.append(kid).append(" "); } sb.append("] >>\nendobj\n"); return sb.toString(); |