From: Keiron Liddle Date: Mon, 12 Nov 2001 13:10:12 +0000 (+0000) Subject: some changes for out of order rendering and rendering to a renderer X-Git-Tag: fop-0_20_4-doc~198 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=364a97a6e14a63a4df36b64d492a26ea59cfa173;p=xmlgraphics-fop.git some changes for out of order rendering and rendering to a renderer git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194565 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/area/AreaTree.java b/src/org/apache/fop/area/AreaTree.java index b8544878c..67b6ecdd6 100644 --- a/src/org/apache/fop/area/AreaTree.java +++ b/src/org/apache/fop/area/AreaTree.java @@ -7,8 +7,9 @@ package org.apache.fop.area; -import java.util.ArrayList; +import org.apache.fop.render.Renderer; +import java.util.ArrayList; /** * Area tree for formatting objects. @@ -32,8 +33,8 @@ public class AreaTree { // in different situations AreaTreeModel model; - public void createRenderPageModel(PageRenderListener listener) { - + public RenderPagesModel createRenderPagesModel(Renderer rend) { + return new RenderPagesModel(rend); } public static StorePagesModel createStorePagesModel() { @@ -44,7 +45,7 @@ public class AreaTree { model = m; } - public void startPageSequence(Area title) { + public void startPageSequence(Title title) { model.startPageSequence(title); } @@ -54,7 +55,7 @@ public class AreaTree { // this is the model for the area tree object public static abstract class AreaTreeModel { - public abstract void startPageSequence(Area title); + public abstract void startPageSequence(Title title); public abstract void addPage(PageViewport page); } @@ -67,7 +68,7 @@ public class AreaTree { public StorePagesModel() {} - public void startPageSequence(Area title) { + public void startPageSequence(Title title) { titles.add(title); if (pageSequence == null) { pageSequence = new ArrayList(); @@ -99,18 +100,31 @@ public class AreaTree { } } - // this queues pages and will call the render listener - // when the page is ready to be rendered - // if the render supports out of order rendering - // then a ready page is rendered immediately + // this uses the store pages model to store the pages + // each page is either rendered if ready or prepared + // for later rendering public static class RenderPagesModel extends StorePagesModel { - public void startPageSequence(Area title) {} - public void addPage(PageViewport page) {} - } + Renderer renderer; + ArrayList prepared = new ArrayList(); + + public RenderPagesModel(Renderer rend) { + renderer = rend; + } + + public void startPageSequence(Title title) { + super.startPageSequence(title); + renderer.startPageSequence(title); + } - public static abstract class PageRenderListener { - public abstract void renderPage(RenderPagesModel model, - int pageseq, int count); + public void addPage(PageViewport page) { + super.addPage(page); + // if page finished + //renderer.renderPage(page); + page.clear(); + // else prepare + //renderer.preparePage(page); + prepared.add(page); + } } } diff --git a/src/org/apache/fop/area/PageViewport.java b/src/org/apache/fop/area/PageViewport.java index b31ce3030..3fdab2b60 100644 --- a/src/org/apache/fop/area/PageViewport.java +++ b/src/org/apache/fop/area/PageViewport.java @@ -54,4 +54,13 @@ public class PageViewport { public void loadPage(ObjectInputStream in) throws Exception { page = (Page) in.readObject(); } + + /** + * Clear the page contents to save memory. + * THis objects is kept for the life of the area tree since + * it holds id information and is used as a key. + */ + public void clear() { + page = null; + } } diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index d24a2129b..06bf33b54 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -21,15 +21,13 @@ import org.apache.fop.render.pdf.CIDFont; import org.apache.fop.render.pdf.fonts.LazyFont; import org.apache.fop.datatypes.IDReferences; -import org.apache.fop.layout.Page; import org.apache.fop.layout.FontMetric; import org.apache.fop.layout.FontDescriptor; // Java import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Enumeration; +import java.util.HashMap; import java.awt.Rectangle; /** @@ -147,7 +145,7 @@ public class PDFDocument { * the XObjects Map. * Should be modified (works only for image subtype) */ - protected Hashtable xObjectsMap = new Hashtable(); + protected HashMap xObjectsMap = new HashMap(); /** * the objects themselves @@ -936,48 +934,27 @@ public class PDFDocument { * * @return the created /Page object */ - public PDFPage makePage(PDFResources resources, PDFStream contents, + public PDFPage makePage(PDFResources resources, int pagewidth, int pageheight) { /* * create a PDFPage with the next object number, the given * resources, contents and dimensions */ - PDFPage page = new PDFPage(++this.objectcount, resources, contents, + PDFPage page = new PDFPage(++this.objectcount, resources, pagewidth, pageheight); - if(pendingLinks != null) { - for(int count = 0; count < pendingLinks.size(); count++) { - PendingLink pl = (PendingLink)pendingLinks.get(count); - PDFGoTo gt = new PDFGoTo(++this.objectcount, - page.referencePDF()); - gt.setDestination(pl.dest); - addTrailerObject(gt); - PDFInternalLink internalLink = - new PDFInternalLink(gt.referencePDF()); - pl.link.setAction(internalLink); - } - pendingLinks = null; - } -/* - if (currentPage != null) { - Enumeration enum = currentPage.getIDList().elements(); - while (enum.hasMoreElements()) { - String id = enum.nextElement().toString(); - idReferences.setInternalGoToPageReference(id, - page.referencePDF()); - } - } -*/ /* add it to the list of objects */ this.objects.add(page); - /* add the page to the Root */ - this.root.addPage(page); - return page; } + public void addPage(PDFPage page) { + /* add it to the list of objects */ + this.objects.add(page); + } + /** * make a link object * diff --git a/src/org/apache/fop/pdf/PDFInfo.java b/src/org/apache/fop/pdf/PDFInfo.java index a8215fcea..bbef7a897 100644 --- a/src/org/apache/fop/pdf/PDFInfo.java +++ b/src/org/apache/fop/pdf/PDFInfo.java @@ -7,9 +7,8 @@ package org.apache.fop.pdf; -// Java -import java.io.IOException; -import java.io.PrintWriter; +import java.util.Date; +import java.text.SimpleDateFormat; /** * class representing an /Info object @@ -21,6 +20,15 @@ public class PDFInfo extends PDFObject { */ protected String producer; + protected String title = null; + protected String author = null; + protected String subject = null; + protected String keywords = null; + + // the name of the application that created the + // original document before converting to PDF + protected String creator; + /** * create an Info object * @@ -39,6 +47,22 @@ public class PDFInfo extends PDFObject { this.producer = producer; } + public void setTitle(String t) { + this.title = t; + } + + public void setAuthor(String a) { + this.author = a; + } + + public void setSubject(String s) { + this.subject = s; + } + + public void setKeywords(String k) { + this.keywords = k; + } + /** * produce the PDF representation of the object * @@ -46,9 +70,29 @@ public class PDFInfo extends PDFObject { */ public byte[] toPDF() { String p = this.number + " " + this.generation - + " obj\n<< /Type /Info\n/Producer (" + this.producer - + ") >>\nendobj\n"; + + " obj\n<< /Type /Info\n"; + if(title != null) { + p += "/Title (" + this.title + ")\n"; + } + if(author != null) { + p += "/Author (" + this.author + ")\n"; + } + if(subject != null) { + p += "/Subject (" + this.subject + ")\n"; + } + if(keywords != null) { + p += "/Keywords (" + this.keywords + ")\n"; + } + + p += "/Producer (" + this.producer + ")\n"; + + // creation date in form (D:YYYYMMDDHHmmSSOHH'mm') + Date date = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss"); + String str = sdf.format(date) + "+00'00'"; + p += "/CreationDate (D:" + str + ")"; + p += " >>\nendobj\n"; return p.getBytes(); } - } + diff --git a/src/org/apache/fop/pdf/PDFPage.java b/src/org/apache/fop/pdf/PDFPage.java index 8fce26098..320a0def7 100644 --- a/src/org/apache/fop/pdf/PDFPage.java +++ b/src/org/apache/fop/pdf/PDFPage.java @@ -77,6 +77,37 @@ public class PDFPage extends PDFObject { this.annotList = null; } + /** + * create a /Page object + * + * @param number the object's number + * @param resources the /Resources object + * @param pagewidth the page's width in points + * @param pageheight the page's height in points + */ + public PDFPage(int number, PDFResources resources, + int pagewidth, int pageheight) { + + /* generic creation of object */ + super(number); + + /* set fields using parameters */ + this.resources = resources; + this.pagewidth = pagewidth; + this.pageheight = pageheight; + + this.annotList = null; + } + + /** + * set this page contents + * + * @param contents the contents of the page + */ + public void setContents(PDFStream contents) { + this.contents = contents; + } + /** * set this page's parent * diff --git a/src/org/apache/fop/pdf/PDFXObject.java b/src/org/apache/fop/pdf/PDFXObject.java index 8d670a574..cefff8a08 100644 --- a/src/org/apache/fop/pdf/PDFXObject.java +++ b/src/org/apache/fop/pdf/PDFXObject.java @@ -119,24 +119,6 @@ public class PDFXObject extends PDFObject { } byte[] toPDF() { - /* - * Not used any more - * String p = this.number + " " + this.generation + " obj\n"; - * p = p + "<