Revision: 12446
http://sourceforge.net/p/foray/code/12446
Author: victormote
Date: 2022-01-21 23:25:28 +0000 (Fri, 21 Jan 2022)
Log Message:
-----------
Refactor page creation logic, part 1.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRoot.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2022-01-21 21:55:56 UTC (rev 12445)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2022-01-21 23:25:28 UTC (rev 12446)
@@ -203,7 +203,7 @@
this.psServer = psServer;
// Create the Root object
- this.root = new PdfRoot();
+ this.root = new PdfRoot(this);
registerIndirectObjectLast(this.root);
registerIndirectObjectLast(this.root.getPages());
@@ -571,7 +571,8 @@
@Override
public PdfPage4a createPdfPage(final int pagewidth, final int pageheight) {
- return new PdfPage4a(this, this.getResources(), pagewidth, pageheight);
+ /* Delegate this entirely to the root. */
+ return this.root.createPage(pagewidth, pageheight);
}
@Override
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java 2022-01-21 21:55:56 UTC (rev 12445)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java 2022-01-21 23:25:28 UTC (rev 12446)
@@ -83,8 +83,6 @@
public PdfPage4a(final PdfDocument4a doc, final PdfResources resources,
final int pagewidth, final int pageheight) {
this.doc = doc;
- /* add the page to the Root */
- doc.getRoot().addPage(this);
this.resources = resources;
this.pagewidth = pagewidth;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRoot.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRoot.java 2022-01-21 21:55:56 UTC (rev 12445)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRoot.java 2022-01-21 23:25:28 UTC (rev 12446)
@@ -38,6 +38,9 @@
*/
public class PdfRoot extends PdfDictionary {
+ /** The parent PDF document. */
+ private PdfDocument4a document;
+
/** The /Pages object that is root of the Pages hierarchy. */
private PdfPages pages;
@@ -56,18 +59,23 @@
/**
* Create a Root (/Catalog) object.
+ * @param document The parent PDF document.
*/
- public PdfRoot() {
- /* Except for "Type", which is handled in the getType() method, */
+ public PdfRoot(final PdfDocument4a document) {
+ this.document = document;
this.pages = new PdfPages();
}
/**
- * Add a /Page object to the root /Pages object.
- * @param page the /Page object to add
+ * Create a /Page object and add it to /Pages.
+ * @param width The width of the new page, in millipoints.
+ * @param height The height of the new page, in millipoints.
+ * @return The new page.
*/
- public void addPage(final PdfPage4a page) {
+ public PdfPage4a createPage(final int width, final int height) {
+ final PdfPage4a page = new PdfPage4a(this.document, this.document.getResources(), width, height);
this.pages.addPage(page);
+ return page;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|