keiron 01/11/12 05:10:12 Modified: src/org/apache/fop/area AreaTree.java PageViewport.java src/org/apache/fop/pdf PDFDocument.java PDFInfo.java PDFPage.java PDFXObject.java src/org/apache/fop/render AbstractRenderer.java Renderer.java src/org/apache/fop/render/pdf PDFRenderer.java src/org/apache/fop/svg PDFDocumentGraphics2D.java Log: some changes for out of order rendering and rendering to a renderer Revision Changes Path 1.3 +31 -17 xml-fop/src/org/apache/fop/area/AreaTree.java Index: AreaTree.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/area/AreaTree.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AreaTree.java 2001/10/26 09:26:59 1.2 +++ AreaTree.java 2001/11/12 13:10:11 1.3 @@ -1,5 +1,5 @@ /* - * $Id: AreaTree.java,v 1.2 2001/10/26 09:26:59 keiron Exp $ + * $Id: AreaTree.java,v 1.3 2001/11/12 13:10:11 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -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. @@ -31,9 +32,9 @@ // allows for different models to deal with adding/rendering // 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 @@ model = m; } - public void startPageSequence(Area title) { + public void startPageSequence(Title title) { model.startPageSequence(title); } @@ -54,7 +55,7 @@ // 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 StorePagesModel() {} - public void startPageSequence(Area title) { + public void startPageSequence(Title title) { titles.add(title); if (pageSequence == null) { pageSequence = new ArrayList(); @@ -99,18 +100,31 @@ } } - // 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); + } } } 1.4 +10 -1 xml-fop/src/org/apache/fop/area/PageViewport.java Index: PageViewport.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/area/PageViewport.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PageViewport.java 2001/11/09 11:32:36 1.3 +++ PageViewport.java 2001/11/12 13:10:11 1.4 @@ -1,5 +1,5 @@ /* - * $Id: PageViewport.java,v 1.3 2001/11/09 11:32:36 keiron Exp $ + * $Id: PageViewport.java,v 1.4 2001/11/12 13:10:11 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -53,5 +53,14 @@ 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; } } 1.33 +10 -33 xml-fop/src/org/apache/fop/pdf/PDFDocument.java Index: PDFDocument.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFDocument.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- PDFDocument.java 2001/11/02 11:06:07 1.32 +++ PDFDocument.java 2001/11/12 13:10:11 1.33 @@ -1,5 +1,5 @@ /* - * $Id: PDFDocument.java,v 1.32 2001/11/02 11:06:07 keiron Exp $ + * $Id: PDFDocument.java,v 1.33 2001/11/12 13:10:11 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -21,15 +21,13 @@ 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 @@ * 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,46 +934,25 @@ * * @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); } /** 1.8 +51 -7 xml-fop/src/org/apache/fop/pdf/PDFInfo.java Index: PDFInfo.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFInfo.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- PDFInfo.java 2001/07/30 20:29:30 1.7 +++ PDFInfo.java 2001/11/12 13:10:11 1.8 @@ -1,5 +1,5 @@ /* - * $Id: PDFInfo.java,v 1.7 2001/07/30 20:29:30 tore Exp $ + * $Id: PDFInfo.java,v 1.8 2001/11/12 13:10:11 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -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 @@ */ 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 @@ 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 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(); } - } + 1.13 +32 -1 xml-fop/src/org/apache/fop/pdf/PDFPage.java Index: PDFPage.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFPage.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- PDFPage.java 2001/08/01 22:12:52 1.12 +++ PDFPage.java 2001/11/12 13:10:11 1.13 @@ -1,5 +1,5 @@ /* - * $Id: PDFPage.java,v 1.12 2001/08/01 22:12:52 gears Exp $ + * $Id: PDFPage.java,v 1.13 2001/11/12 13:10:11 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -75,6 +75,37 @@ this.pageheight = pageheight; 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; } /** 1.15 +1 -19 xml-fop/src/org/apache/fop/pdf/PDFXObject.java Index: PDFXObject.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/pdf/PDFXObject.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- PDFXObject.java 2001/09/18 08:17:08 1.14 +++ PDFXObject.java 2001/11/12 13:10:11 1.15 @@ -1,5 +1,5 @@ /* - * $Id: PDFXObject.java,v 1.14 2001/09/18 08:17:08 keiron Exp $ + * $Id: PDFXObject.java,v 1.15 2001/11/12 13:10:11 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -119,24 +119,6 @@ } byte[] toPDF() { - /* - * Not used any more - * String p = this.number + " " + this.generation + " obj\n"; - * p = p + "<</Type /XObject\n"; - * p = p + "/Subtype /Image\n"; - * p = p + "/Name /Im"+Xnum+"\n"; - * p = p + "/Width "+fopimage.getpixelwidth()+"\n"; - * p = p + "/Height "+fopimage.getpixelheight()+"\n"; - * p = p + "/BitsPerComponent 8\n"; - * if (fopimage.getcolor()) - * p = p + "/ColorSpace /DeviceRGB\n"; - * else - * p = p + "/ColorSpace /DeviceGray\n"; - * p = p + "/Filter /ASCIIHexDecode\n"; - * p = p + "/Length "; - * return p; - */ return null; } - } 1.9 +22 -1 xml-fop/src/org/apache/fop/render/AbstractRenderer.java Index: AbstractRenderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/AbstractRenderer.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- AbstractRenderer.java 2001/11/09 22:16:26 1.8 +++ AbstractRenderer.java 2001/11/12 13:10:11 1.9 @@ -1,5 +1,5 @@ /* - * $Id: AbstractRenderer.java,v 1.8 2001/11/09 22:16:26 klease Exp $ + * $Id: AbstractRenderer.java,v 1.9 2001/11/12 13:10:11 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -56,6 +56,27 @@ public void setOptions(HashMap opt) { options = opt; + } + + /** + * Check if this renderer supports out of order rendering. + * If this renderer supports out of order rendering then it + * means that the pages that are not ready will be prepared + * and a future page will be rendered. + */ + public boolean supportsOutOfOrder() { + return false; + } + + /** + * Prepare a page for rendering. + * This is called if the renderer supports out of order rendering. + * The renderer should prepare the page so that a page further on + * in the set of pages can be rendered. The body of the page should + * not be rendered. The page will be rendered at a later time + * by the call to render page. + */ + public void preparePage(PageViewport page) { } /** 1.22 +5 -1 xml-fop/src/org/apache/fop/render/Renderer.java Index: Renderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/Renderer.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- Renderer.java 2001/10/26 09:27:00 1.21 +++ Renderer.java 2001/11/12 13:10:11 1.22 @@ -1,5 +1,5 @@ /* - * $Id: Renderer.java,v 1.21 2001/10/26 09:27:00 keiron Exp $ + * $Id: Renderer.java,v 1.22 2001/11/12 13:10:11 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -60,6 +60,10 @@ * set the producer of the rendering */ public void setProducer(String producer); + + public boolean supportsOutOfOrder(); + + public void preparePage(PageViewport page); public void startPageSequence(Title seqTitle); 1.94 +53 -15 xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java Index: PDFRenderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v retrieving revision 1.93 retrieving revision 1.94 diff -u -r1.93 -r1.94 --- PDFRenderer.java 2001/10/26 09:27:00 1.93 +++ PDFRenderer.java 2001/11/12 13:10:12 1.94 @@ -1,5 +1,5 @@ /* - * $Id: PDFRenderer.java,v 1.93 2001/10/26 09:27:00 keiron Exp $ + * $Id: PDFRenderer.java,v 1.94 2001/11/12 13:10:12 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -28,15 +28,15 @@ // Java import java.io.IOException; import java.io.OutputStream; - import java.awt.geom.Rectangle2D; +import java.util.HashMap; /* TODO: viewport clipping word rendering and optimistion -pdf state optimistation +pdf state optimisation line and border leader background pattern @@ -58,6 +58,16 @@ */ protected PDFDocument pdfDoc; + // map of pages using the PageViewport as the key + // this is used for prepared pages that cannot be immediately + // rendered + protected HashMap pages = null; + + // page references are stored using the PageViewport as the key + // when a reference is made the PageViewport is used + // for pdf this means we need the pdf page reference + protected HashMap pageReferences = new HashMap(); + protected String producer; protected OutputStream ostream; @@ -141,16 +151,50 @@ ostream = null; } + public boolean supportsOutOfOrder() { + return true; + } + + /** + * The pdf page is prepared by making the page. + * The page is made in the pdf document without any contents + * and then stored to add the contents later. + * The page objects is stored using the area tree PageViewport + * as a key. + */ + public void preparePage(PageViewport page) { + this.pdfResources = this.pdfDoc.getResources(); + + Rectangle2D bounds = page.getViewArea(); + double w = bounds.getWidth(); + double h = bounds.getHeight(); + currentPage = this.pdfDoc.makePage(this.pdfResources, + (int) Math.round(w / 1000), (int) Math.round(h / 1000)); + if(pages == null) { + pages = new HashMap(); + } + pages.put(page, currentPage); + pageReferences.put(page, currentPage.referencePDF()); + } + /** * This method creates a pdf stream for the current page - * uses it as the contents of a new page. The page is wriiten + * uses it as the contents of a new page. The page is written * immediately to the output stream. */ public void renderPage(PageViewport page) throws IOException, FOPException { - - this.pdfResources = this.pdfDoc.getResources(); - + if(pages != null && (currentPage = (PDFPage)pages.get(page)) != null) { + pages.remove(page); + } else { + this.pdfResources = this.pdfDoc.getResources(); + Rectangle2D bounds = page.getViewArea(); + double w = bounds.getWidth(); + double h = bounds.getHeight(); + currentPage = this.pdfDoc.makePage(this.pdfResources, + (int) Math.round(w / 1000), (int) Math.round(h / 1000)); + pageReferences.put(page, currentPage.referencePDF()); + } currentStream = this.pdfDoc.makeStream(); currentStream.add("BT\n"); @@ -158,16 +202,10 @@ renderPageAreas(p); currentStream.add("ET\n"); - - Rectangle2D bounds = page.getViewArea(); - double w = bounds.getWidth(); - double h = bounds.getHeight(); - currentPage = this.pdfDoc.makePage(this.pdfResources, currentStream, - (int) Math.round(w / 1000), (int) Math.round(h / 1000)); + currentPage.setContents(currentStream); + this.pdfDoc.addPage(currentPage); this.pdfDoc.output(ostream); - } - } 1.14 +9 -4 xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java Index: PDFDocumentGraphics2D.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFDocumentGraphics2D.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- PDFDocumentGraphics2D.java 2001/11/09 11:32:42 1.13 +++ PDFDocumentGraphics2D.java 2001/11/12 13:10:12 1.14 @@ -1,5 +1,5 @@ /* - * $Id: PDFDocumentGraphics2D.java,v 1.13 2001/11/09 11:32:42 keiron Exp $ + * $Id: PDFDocumentGraphics2D.java,v 1.14 2001/11/12 13:10:12 keiron Exp $ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -31,12 +31,13 @@ * <tt>PDFGraphics2D</tt>. * * @author <a href="mailto:[EMAIL PROTECTED]">Keiron Liddle</a> - * @version $Id: PDFDocumentGraphics2D.java,v 1.13 2001/11/09 11:32:42 keiron Exp $ + * @version $Id: PDFDocumentGraphics2D.java,v 1.14 2001/11/12 13:10:12 keiron Exp $ * @see org.apache.fop.svg.PDFGraphics2D */ public class PDFDocumentGraphics2D extends PDFGraphics2D { OutputStream stream; + PDFPage currentPage; PDFStream pdfStream; int width; int height; @@ -77,6 +78,10 @@ currentFontSize = 0; currentYPosition = 0; currentXPosition = 0; + + PDFResources pdfResources = this.pdfDoc.getResources(); + currentPage = this.pdfDoc.makePage(pdfResources, + width, height); } void setupDocument(OutputStream stream, int width, int height) { @@ -149,8 +154,8 @@ public void finish() throws IOException { pdfStream.add(getString()); PDFResources pdfResources = this.pdfDoc.getResources(); - PDFPage currentPage = this.pdfDoc.makePage(pdfResources, pdfStream, - width, height); + currentPage.setContents(pdfStream); + this.pdfDoc.addPage(currentPage); if(currentAnnotList != null) { currentPage.setAnnotList(currentAnnotList); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]