diff options
author | Steve Coffman <gears@apache.org> | 2001-08-01 22:12:54 +0000 |
---|---|---|
committer | Steve Coffman <gears@apache.org> | 2001-08-01 22:12:54 +0000 |
commit | eeb2adff569057e2b6deb089ba9dffb21fb3a00b (patch) | |
tree | c8968573d60b496aa17befb1afbec840ddc1b355 /src/org/apache/fop/render | |
parent | a5bc30d4a3977d60f0e70c2792bc4e3a37913a3d (diff) | |
download | xmlgraphics-fop-eeb2adff569057e2b6deb089ba9dffb21fb3a00b.tar.gz xmlgraphics-fop-eeb2adff569057e2b6deb089ba9dffb21fb3a00b.zip |
Adds Mark Lillywhite's performance and memory patch in all it's glory.
Unfortunately breaks marker support.
(AreaTree getNextPage and getPreviousPage return the current page)
XSL-FO with markers is not a good idea until it is fixed.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194385 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/render')
-rw-r--r-- | src/org/apache/fop/render/PrintRenderer.java | 31 | ||||
-rw-r--r-- | src/org/apache/fop/render/Renderer.java | 11 | ||||
-rw-r--r-- | src/org/apache/fop/render/awt/AWTRenderer.java | 81 | ||||
-rw-r--r-- | src/org/apache/fop/render/mif/MIFRenderer.java | 57 | ||||
-rwxr-xr-x | src/org/apache/fop/render/pcl/PCLRenderer.java | 79 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFRenderer.java | 79 | ||||
-rw-r--r-- | src/org/apache/fop/render/ps/PSRenderer.java | 90 | ||||
-rwxr-xr-x | src/org/apache/fop/render/txt/TXTRenderer.java | 69 | ||||
-rw-r--r-- | src/org/apache/fop/render/xml/XMLRenderer.java | 57 |
9 files changed, 312 insertions, 242 deletions
diff --git a/src/org/apache/fop/render/PrintRenderer.java b/src/org/apache/fop/render/PrintRenderer.java index 10c5eb7d0..6c67420e6 100644 --- a/src/org/apache/fop/render/PrintRenderer.java +++ b/src/org/apache/fop/render/PrintRenderer.java @@ -38,6 +38,13 @@ import java.util.Enumeration; /** * Abstract base class of "Print" type renderers. + * + * Modified by Mark Lillywhite mark-fop@inomial.com. Removed + * the render(AreaTree, OutputStream) method, and added + * no-op concrete implementation of startRenderer() and + * stopRenderer(). The method render(Page, OutputStream) + * is not mentioned in this class but it is inherited from + * the Renderer interface. */ public abstract class PrintRenderer implements Renderer { // vvv These are not currently referenced by the PrintRenderer, but are common to PCL and PDF renderers - so declare here. @@ -122,15 +129,6 @@ public abstract class PrintRenderer implements Renderer { public abstract void setProducer(String producer); /** - * render the areas - * - * @param areaTree the laid-out area tree - * @param stream the OutputStream to write to - */ - public abstract void render(AreaTree areaTree, OutputStream stream) - throws IOException, FOPException; - - /** * add a line to the current stream * * @param x1 the start x location in millipoints @@ -596,5 +594,20 @@ public abstract class PrintRenderer implements Renderer { this.fontInfo = fontInfo; FontSetup.setup(fontInfo); } + + /** + Default start renderer method. This would + normally be overridden. (mark-fop@inomial.com). + */ + public void startRenderer(OutputStream outputStream) + throws IOException + { + } + /** + Default stop renderer method. This would + normally be overridden. (mark-fop@inomial.com). + */ + { + } } diff --git a/src/org/apache/fop/render/Renderer.java b/src/org/apache/fop/render/Renderer.java index 0365a8511..c28ffc923 100644 --- a/src/org/apache/fop/render/Renderer.java +++ b/src/org/apache/fop/render/Renderer.java @@ -89,8 +89,9 @@ public interface Renderer { /** * render the given area tree to the given stream */ - public void render(AreaTree areaTree, - OutputStream stream) throws IOException, FOPException; + //public void render(AreaTree areaTree, OutputStream stream) throws IOException, FOPException; + public void render(Page page, OutputStream stream) + throws IOException, FOPException; /** * render the given area container @@ -157,4 +158,10 @@ public interface Renderer { */ public void renderLeaderArea(LeaderArea area); + public void startRenderer(OutputStream outputStream) + throws IOException; + + public void stopRenderer(OutputStream outputStream) + throws IOException; + } diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java index ef2ef9f63..57595eb47 100644 --- a/src/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/org/apache/fop/render/awt/AWTRenderer.java @@ -52,13 +52,20 @@ import java.text.*; import org.apache.fop.render.Renderer; +/** + Modified by Mark Lillywhite mark-fop@inomial.com. Did lots of + cleaning up and made the class implement the new Renderer + interface. This class could also do with a general audit, + and I suspect it's not swing-thread-safe either. +*/ + public class AWTRenderer implements Renderer, Printable, Pageable { protected int pageWidth = 0; protected int pageHeight = 0; protected double scaleFactor = 100.0; protected int pageNumber = 0; - protected AreaTree tree; + protected Vector pageList = new Vector(); protected ProgressListener progressListener = null; protected Translator res = null; @@ -66,6 +73,8 @@ public class AWTRenderer implements Renderer, Printable, Pageable { protected Hashtable fontStyles = new Hashtable(); protected Color saveColor = null; + protected IDReferences idReferences = null; + /** * Image Object and Graphics Object. The Graphics Object is the Graphics * object that is contained withing the Image Object. @@ -322,35 +331,37 @@ public class AWTRenderer implements Renderer, Printable, Pageable { * @return the number of pages */ public int getPageCount() { - if (tree == null) { - return 0; - } + return pageList.size(); + } - return tree.getPages().size(); + public void removePage(int page) { + pageList.removeElementAt(page); } - public void render(int aPageNumber) { - if (tree != null) { - try { - render(tree, aPageNumber); - } catch (IOException e) { - e.printStackTrace(); - // This exception can't occur because we are not dealing with - // any files. - } - } + public void render(int aPageNumber) + { + if(aPageNumber >= pageList.size()) + return; + + try{ + render((Page) pageList.elementAt(aPageNumber)); + } catch(IOException e){ + e.printStackTrace(); + // This exception can't occur because we are not dealing with + // any files + } } - public void render(AreaTree areaTree, - OutputStream stream) throws IOException { - tree = areaTree; - render(areaTree, 0); + public void render(Page page, OutputStream stream) + throws IOException + { + pageList.addElement(page); } - public void render(AreaTree areaTree, - int aPageNumber) throws IOException { - tree = areaTree; - Page page = (Page)areaTree.getPages().elementAt(aPageNumber); + public void render(Page page) + throws IOException + { + idReferences = page.getIDReferences(); pageWidth = (int)((float)page.getWidth() / 1000f + .5); pageHeight = (int)((float)page.getHeight() / 1000f + .5); @@ -693,7 +704,7 @@ public class AWTRenderer implements Renderer, Printable, Pageable { String s; // = area.getText(); if (area.getPageNumberID() != null) { // this text is a page number, so resolve it - s = tree.getIDReferences().getPageNumber(area.getPageNumberID()); + s = idReferences.getPageNumber(area.getPageNumberID()); if (s == null) { s = ""; } @@ -872,14 +883,14 @@ public class AWTRenderer implements Renderer, Printable, Pageable { public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException { - if (pageIndex >= tree.getPages().size()) + if (pageIndex >= pageList.size()) return NO_SUCH_PAGE; Graphics2D oldGraphics = graphics; int oldPageNumber = pageNumber; graphics = (Graphics2D)g; - Page aPage = (Page)tree.getPages().elementAt(pageIndex); + Page aPage = (Page)pageList.elementAt(pageIndex); renderPage(aPage); graphics = oldGraphics; @@ -887,15 +898,15 @@ public class AWTRenderer implements Renderer, Printable, Pageable { } public int getNumberOfPages() { - return tree.getPages().size(); + return pageList.size(); } public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException { - if (pageIndex >= tree.getPages().size()) + if (pageIndex >= pageList.size()) return null; - Page page = (Page)tree.getPages().elementAt(pageIndex); + Page page = (Page)pageList.elementAt(pageIndex); PageFormat pageFormat = new PageFormat(); Paper paper = new Paper(); @@ -1078,4 +1089,16 @@ public class AWTRenderer implements Renderer, Printable, Pageable { public void registerExtension(BridgeExtension be) {} } + + public void startRenderer(OutputStream outputStream) + throws IOException + { + } + + public void stopRenderer(OutputStream outputStream) + throws IOException + { + render(0); + } + } diff --git a/src/org/apache/fop/render/mif/MIFRenderer.java b/src/org/apache/fop/render/mif/MIFRenderer.java index 778c992d1..567d59359 100644 --- a/src/org/apache/fop/render/mif/MIFRenderer.java +++ b/src/org/apache/fop/render/mif/MIFRenderer.java @@ -40,6 +40,12 @@ import java.util.Hashtable; /** * Renderer that renders areas to MIF + * + * Modified by Mark Lillywhite mark-fop@inomial.com. Updated to + * collect all the Pages and print them out at the end. This means + * that the MIF renderer does not stream, but on the other hand + * it should still work. I don't have an MIF view to test it with, + * you see. */ public class MIFRenderer implements Renderer { @@ -93,31 +99,6 @@ public class MIFRenderer implements Renderer { } /** - * render the areas into MIF - * - * @param areaTree the laid-out area tree - * @param writer the PrintWriter to write the MIF with - */ - - public void render(AreaTree areaTree, - OutputStream stream) throws IOException, FOPException { - - MessageHandler.logln("rendering areas to MIF"); - // idReferences=areaTree.getIDReferences(); - // this.pdfResources = this.pdfDoc.getResources(); - // this.pdfDoc.setIDReferences(idReferences); - Enumeration e = areaTree.getPages().elements(); - while (e.hasMoreElements()) { - this.renderPage((Page)e.nextElement()); - } - - // MessageHandler.logln("writing out MIF"); - - this.mifDoc.output(stream); - stream.close(); - } - - /** * set up the given FontInfo */ public void setupFontInfo(FontInfo fontInfo) { @@ -496,4 +477,30 @@ public class MIFRenderer implements Renderer { */ public void renderLeaderArea(LeaderArea area) {} + /** + Default start renderer method. This would + normally be overridden. (mark-fop@inomial.com). + */ + public void startRenderer(OutputStream outputStream) + throws IOException + { + MessageHandler.logln("rendering areas to MIF"); + } + + /** + Default stop renderer method. This would + normally be overridden. (mark-fop@inomial.com) + */ + public void stopRenderer(OutputStream outputStream) + throws IOException + { + MessageHandler.logln("writing out MIF"); + this.mifDoc.output(outputStream); + outputStream.flush(); + } + + public void render(Page page, OutputStream outputStream) { + this.renderPage(page); + } } + diff --git a/src/org/apache/fop/render/pcl/PCLRenderer.java b/src/org/apache/fop/render/pcl/PCLRenderer.java index d47da9a59..9ccd4f39f 100755 --- a/src/org/apache/fop/render/pcl/PCLRenderer.java +++ b/src/org/apache/fop/render/pcl/PCLRenderer.java @@ -35,6 +35,8 @@ import java.util.Enumeration; * Renderer that renders areas to PCL * Created by Arthur E Welch III while at M&I EastPoint Technology * Donated by EastPoint to the Apache FOP project March 2, 2001. + * Modified by Mark Lillywhite mark-fop@inomial.com to use the + * new Renderer interface. */ public class PCLRenderer extends PrintRenderer { @@ -79,50 +81,7 @@ public class PCLRenderer extends PrintRenderer { * @param producer string indicating application producing PCL */ public void setProducer(String producer) {} - - /** - * render the areas into PCL - * - * @param areaTree the laid-out area tree - * @param stream the Outputstream to write the PCL to - */ - public void render(AreaTree areaTree, - OutputStream stream) throws IOException, FOPException { - MessageHandler.logln("rendering areas to PCL"); - idReferences = areaTree.getIDReferences(); - // this.pdfResources = this.pdfDoc.getResources(); - // this.pdfDoc.setIDReferences(idReferences); - Enumeration e = areaTree.getPages().elements(); - - currentStream = new PCLStream(stream); - - // Set orientation. - if (orientation > -1) - currentStream.add("\033&l" + orientation + "O"); - else - currentStream.add("\033&l0O"); - if (orientation == 1 || orientation == 3) - xoffset = -144; - else - xoffset = -180; - - // Reset the margins. - currentStream.add("\033" + "9\033&l0E"); - - - while (e.hasMoreElements()) { - this.renderPage((Page)e.nextElement()); - } - if (!idReferences.isEveryIdValid()) { - // throw new FOPException("The following id's were referenced but not found: "+idReferences.getInvalidIds()+"\n"); - MessageHandler.errorln("Warning: The following id's were referenced but not found: " - + idReferences.getInvalidIds() + "\n"); - } - - MessageHandler.logln("writing out PCL"); - stream.flush(); - } - + /** * add a line to the current stream * @@ -749,5 +708,37 @@ public class PCLRenderer extends PrintRenderer { * } */ } + public void startRenderer(OutputStream outputStream) + throws IOException + { MessageHandler.logln("rendering areas to PCL"); + currentStream = new PCLStream(outputStream); + + // Set orientation. + if (orientation > -1) + currentStream.add("\033&l" + orientation + "O"); + else + currentStream.add("\033&l0O"); + if (orientation == 1 || orientation == 3) + xoffset = -144; + else + xoffset = -180; + + // Reset the margins. + currentStream.add("\033" + "9\033&l0E"); + } + + public void stopRenderer(OutputStream outputStream) + throws IOException + { + MessageHandler.logln("writing out PCL"); + outputStream.flush(); + } + + public void render(Page page, OutputStream outputStream) + throws IOException + { + idReferences = page.getIDReferences(); + this.renderPage(page); + } } diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 7d9e27381..4554ff7e5 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -51,6 +51,15 @@ import java.awt.Dimension; /** * Renderer that renders areas to PDF + * + * Modified by Mark Lillywhite, mark-fop@inomial.com to use the + * new Renderer interface. The PDF renderer is by far the trickiest + * renderer and the best supported by FOP. It also required some + * reworking in the way that Pages, Catalogs and the Root object + * were written to the stream. The output document should now still + * be a 100% compatible PDF document, but hte order of the document + * writing is significantly different. See also the changes + * to PDFPage, PDFPages and PDFRoot. */ public class PDFRenderer extends PrintRenderer { @@ -103,8 +112,6 @@ public class PDFRenderer extends PrintRenderer { */ int prevWordWidth = 0; - private PDFOutline rootOutline; - /** * reusable word area string buffer to reduce memory usage */ @@ -138,37 +145,18 @@ public class PDFRenderer extends PrintRenderer { this.pdfDoc.setProducer(producer); } - /** - * render the areas into PDF - * - * @param areaTree the laid-out area tree - * @param stream the OutputStream to write the PDF to - */ - public void render(AreaTree areaTree, - OutputStream stream) throws IOException, FOPException { - MessageHandler.logln("rendering areas to PDF"); - idReferences = areaTree.getIDReferences(); - this.pdfResources = this.pdfDoc.getResources(); - this.pdfDoc.setIDReferences(idReferences); - Enumeration e = areaTree.getPages().elements(); - while (e.hasMoreElements()) { - this.renderPage((Page)e.nextElement()); - } - - if (!idReferences.isEveryIdValid()) { - // throw new FOPException("The following id's were referenced but not found: "+idReferences.getInvalidIds()+"\n"); - MessageHandler.errorln("WARNING: The following id's were referenced but not found: " - + idReferences.getInvalidIds() + "\n"); - - } - renderRootExtensions(areaTree); - - FontSetup.addToResources(this.pdfDoc, fontInfo); - - MessageHandler.logln("writing out PDF"); - this.pdfDoc.output(stream); + public void startRenderer(OutputStream stream) + throws IOException + { + pdfDoc.outputHeader(stream); } + public void stopRenderer(OutputStream stream) + throws IOException + { + pdfDoc.outputTrailer(stream); + } + /** * add a line to the current stream * @@ -622,6 +610,7 @@ public class PDFRenderer extends PrintRenderer { } + /** * Convert a char to a multibyte hex representation */ @@ -681,6 +670,24 @@ public class PDFRenderer extends PrintRenderer { } } + public void render(Page page, OutputStream outputStream) + throws FOPException, IOException + { + // MessageHandler.logln("rendering single page to PDF"); + this.idReferences = page.getIDReferences(); + this.pdfResources = this.pdfDoc.getResources(); + this.pdfDoc.setIDReferences(idReferences); + this.renderPage(page); + + FontSetup.addToResources(this.pdfDoc, fontInfo); + + // TODO: this needs to be implemented + renderRootExtensions(page); + + // MessageHandler.logln("writing out PDF"); + this.pdfDoc.output(outputStream); + } + /** * render page into PDF * @@ -778,8 +785,8 @@ public class PDFRenderer extends PrintRenderer { return rs; } - protected void renderRootExtensions(AreaTree areaTree) { - Vector v = areaTree.getExtensions(); + protected void renderRootExtensions(Page page) { + Vector v = page.getExtensions(); if (v != null) { Enumeration e = v.elements(); while (e.hasMoreElements()) { @@ -793,14 +800,12 @@ public class PDFRenderer extends PrintRenderer { } private void renderOutline(Outline outline) { - if (rootOutline == null) { - rootOutline = this.pdfDoc.makeOutlineRoot(); - } + PDFOutline outlineRoot = pdfDoc.getOutlineRoot(); PDFOutline pdfOutline = null; Outline parent = outline.getParentOutline(); if (parent == null) { pdfOutline = - this.pdfDoc.makeOutline(rootOutline, + this.pdfDoc.makeOutline(outlineRoot, outline.getLabel().toString(), outline.getInternalDestination()); } else { diff --git a/src/org/apache/fop/render/ps/PSRenderer.java b/src/org/apache/fop/render/ps/PSRenderer.java index 16ed11fac..bbbe0e748 100644 --- a/src/org/apache/fop/render/ps/PSRenderer.java +++ b/src/org/apache/fop/render/ps/PSRenderer.java @@ -68,7 +68,11 @@ import java.awt.Dimension; * DocumentProcessColors stuff (probably needs to be configurable, then maybe * add a color to grayscale conversion for bitmaps to make output smaller (See * PCLRenderer), font embedding, support different character encodings, try to - * implement image transparency, positioning of images is wrong etc. + * implement image transparency, positioning of images is wrong etc. <P> + * + * Modified by Mark Lillywhite mark-fop@inomial.com, to use the new + * Renderer interface. This PostScript renderer appears to be the + * most efficient at producing output. * * @author Jeremias Märki */ @@ -100,6 +104,8 @@ public class PSRenderer implements Renderer { private float currGreen; private float currBlue; + private FontInfo fontInfo; + protected Hashtable options; @@ -120,45 +126,6 @@ public class PSRenderer implements Renderer { this.options = options; } - - /** - * render the areas into PostScript - * - * @param areaTree the laid-out area tree - * @param stream the OutputStream to give the PostScript to - */ - public void render(AreaTree areaTree, - OutputStream stream) throws IOException { - MessageHandler.logln("rendering areas to PostScript"); - this.out = new PSStream(stream); - write("%!PS-Adobe-3.0"); - write("%%Creator: " + this.producer); - write("%%Pages: " + areaTree.getPages().size()); - write("%%DocumentProcessColors: Black"); - write("%%DocumentSuppliedResources: procset FOPFonts"); - write("%%EndComments"); - write("%%BeginDefaults"); - write("%%EndDefaults"); - write("%%BeginProlog"); - write("%%EndProlog"); - write("%%BeginSetup"); - writeFontDict(areaTree.getFontInfo()); - write("%%EndSetup"); - write("FOPFonts begin"); - - comment("% --- AreaTree begin"); - Enumeration e = areaTree.getPages().elements(); - while (e.hasMoreElements()) { - this.renderPage((Page)e.nextElement()); - } - comment("% --- AreaTree end"); - write("%%Trailer"); - write("%%EOF"); - this.out.flush(); - MessageHandler.logln("written out PostScript"); - } - - /** * write out a command */ @@ -285,6 +252,7 @@ public class PSRenderer implements Renderer { public void setupFontInfo(FontInfo fontInfo) { /* use PDF's font setup to get PDF metrics */ org.apache.fop.render.pdf.FontSetup.setup(fontInfo); + this.fontInfo = fontInfo; } /** @@ -1054,4 +1022,46 @@ public class PSRenderer implements Renderer { public void registerExtension(BridgeExtension be) {} } + + /** + Default start renderer method. This would + normally be overridden. (mark-fop@inomial.com). + */ + public void startRenderer(OutputStream outputStream) + throws IOException + { + MessageHandler.logln("rendering areas to PostScript"); + + this.out = new PSStream(outputStream); + write("%!PS-Adobe-3.0"); + write("%%Creator: "+this.producer); + write("%%DocumentProcessColors: Black"); + write("%%DocumentSuppliedResources: procset FOPFonts"); + write("%%EndComments"); + write("%%BeginDefaults"); + write("%%EndDefaults"); + write("%%BeginProlog"); + write("%%EndProlog"); + write("%%BeginSetup"); + writeFontDict(fontInfo); + write("%%EndSetup"); + write("FOPFonts begin"); + } + + /** + Default stop renderer method. This would + normally be overridden. (mark-fop@inomial.com). + */ + public void stopRenderer(OutputStream outputStream) + throws IOException + { + write("%%Trailer"); + write("%%EOF"); + this.out.flush(); + MessageHandler.logln("written out PostScript"); + } + + public void render(Page page, OutputStream outputStream) { + this.renderPage(page); + } } diff --git a/src/org/apache/fop/render/txt/TXTRenderer.java b/src/org/apache/fop/render/txt/TXTRenderer.java index eaff0eb88..11b9f31f9 100755 --- a/src/org/apache/fop/render/txt/TXTRenderer.java +++ b/src/org/apache/fop/render/txt/TXTRenderer.java @@ -35,6 +35,9 @@ import java.util.Hashtable; /** * Renderer that renders areas to plain text + * + * Modified by Mark Lillywhite mark-fop@inomial.com to use the new + * Renderer interface. */ public class TXTRenderer extends PrintRenderer { @@ -71,7 +74,7 @@ public class TXTRenderer extends PrintRenderer { "\f"; // Every page except the last one will end with this string. public boolean suppressGraphics = false; // If true then graphics/decorations will not be rendered - text only. - + boolean firstPage = false; /** * options */ @@ -93,39 +96,6 @@ public class TXTRenderer extends PrintRenderer { */ public void setProducer(String producer) {} - /** - * render the areas into text - * - * @param areaTree the laid-out area tree - * @param writer the PrintWriter to write the PDF with - */ - public void render(AreaTree areaTree, - OutputStream stream) throws IOException, FOPException { - MessageHandler.logln("rendering areas to TEXT"); - idReferences = areaTree.getIDReferences(); - Enumeration e = areaTree.getPages().elements(); - currentStream = new PCLStream(stream); - - boolean first = true; - - while (e.hasMoreElements()) { - if (first) - first = false; - else - currentStream.add(pageEnding); - this.renderPage((Page)e.nextElement()); - } - currentStream.add(lineEnding); - if (!idReferences.isEveryIdValid()) { - // throw new FOPException("The following id's were referenced but not found: "+idReferences.getInvalidIds()+"\n"); - MessageHandler.errorln("Warning: The following id's were referenced but not found: " - + idReferences.getInvalidIds() + "\n"); - } - - MessageHandler.logln("writing out TEXT"); - stream.flush(); - } - void addStr(int row, int col, String str, boolean ischar) { if (debug) System.out.println("TXTRenderer.addStr(" + row + ", " + col @@ -1702,5 +1672,36 @@ public class TXTRenderer extends PrintRenderer { * } */ } + public void startRenderer(OutputStream outputStream) + throws IOException + { + MessageHandler.logln("rendering areas to TEXT"); + currentStream = new PCLStream(outputStream); + firstPage=true; + } + + /** + * In Mark's patch, this is endRenderer + * However, I couldn't see how it builds that way, so + * i changed it. - Steve gears@apache.org + */ + + public void stopRenderer(OutputStream outputStream) + throws IOException + { + MessageHandler.logln("writing out TEXT"); + outputStream.flush(); + } + public void render(Page page, OutputStream outputStream) + { + idReferences = page.getIDReferences(); + + if ( firstPage ) + firstPage = false; + else + currentStream.add(pageEnding); + this.renderPage(page); + currentStream.add(lineEnding); + } } diff --git a/src/org/apache/fop/render/xml/XMLRenderer.java b/src/org/apache/fop/render/xml/XMLRenderer.java index b249f523f..6aeca10fd 100644 --- a/src/org/apache/fop/render/xml/XMLRenderer.java +++ b/src/org/apache/fop/render/xml/XMLRenderer.java @@ -26,6 +26,9 @@ import java.util.Hashtable; /** * Renderer that renders areas to XML for debugging purposes. + * + * Modified by Mark Lillywhite mark-fop@inomial.com to use the + * new renderer interface. Not 100% certain that this is correct. */ public class XMLRenderer implements Renderer { @@ -67,27 +70,12 @@ public class XMLRenderer implements Renderer { this.producer = producer; } - /** - * render the areas into XML - * - * @param areaTree the laid-out area tree - * @param stream the OutputStream to give the XML to - */ - public void render(AreaTree areaTree, - OutputStream stream) throws IOException { - MessageHandler.logln("rendering areas to XML"); - this.writer = new PrintWriter(stream); - this.writer.write("<?xml version=\"1.0\"?>\n<!-- produced by " - + this.producer + " -->\n"); - writeStartTag("<AreaTree>"); - Enumeration e = areaTree.getPages().elements(); - while (e.hasMoreElements()) { - this.renderPage((Page)e.nextElement()); - } - writeEndTag("</AreaTree>"); - this.writer.flush(); - MessageHandler.errorln("written out XML"); - } + + public void render(Page page, OutputStream outputStream) + throws IOException + { + this.renderPage(page); + } /** * write out spaces to make indent @@ -439,5 +427,30 @@ public class XMLRenderer implements Renderer { private boolean isCoarseXml() { return ((Boolean)options.get("fineDetail")).booleanValue(); } - + + /** + Default start renderer method. This would + normally be overridden. (mark-fop@inomial.com). + */ + public void startRenderer(OutputStream outputStream) + throws IOException + { + MessageHandler.logln("rendering areas to XML"); + this.writer = new PrintWriter(outputStream); + this.writer.write( "<?xml version=\"1.0\"?>\n<!-- produced by " + + this.producer + " -->\n"); + writeStartTag("<AreaTree>"); + } + + /** + Default stop renderer method. This would + normally be overridden. (mark-fop@inomial.com). + */ + public void stopRenderer(OutputStream outputStream) + throws IOException + { + writeEndTag("</AreaTree>"); + this.writer.flush(); + MessageHandler.errorln("written out XML"); + } } |