From: Glen Mazza Date: Sun, 29 Jun 2003 19:34:34 +0000 (+0000) Subject: Bug #20397: Move StructureHandler.java to fo package and LayoutHandler.java to layou... X-Git-Tag: Root_Temp_KnuthStylePageBreaking~1384 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=76d6774a7c50a756450c5b8bc8491b773c01b8cc;p=xmlgraphics-fop.git Bug #20397: Move StructureHandler.java to fo package and LayoutHandler.java to layoutmgr package. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196538 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index 7f97f0d97..514bfe436 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -54,11 +54,14 @@ package org.apache.fop.apps; import org.apache.fop.fo.ElementMapping; import org.apache.fop.fo.FOTreeBuilder; import org.apache.fop.fo.FOUserAgent; +import org.apache.fop.fo.StructureHandler; +import org.apache.fop.layoutmgr.LayoutHandler; +import org.apache.fop.mif.MIFHandler; import org.apache.fop.render.Renderer; +import org.apache.fop.rtf.renderer.RTFHandler; import org.apache.fop.tools.DocumentInputSource; import org.apache.fop.tools.DocumentReader; - // Avalon import org.apache.avalon.framework.logger.ConsoleLogger; import org.apache.avalon.framework.logger.LogEnabled; @@ -582,9 +585,9 @@ public class Driver implements LogEnabled { // TODO: - do this stuff in a better way // PIJ: I guess the structure handler should be created by the renderer. if (rendererType == RENDER_MIF) { - structHandler = new org.apache.fop.mif.MIFHandler(stream); + structHandler = new MIFHandler(stream); } else if (rendererType == RENDER_RTF) { - structHandler = new org.apache.fop.rtf.renderer.RTFHandler(stream); + structHandler = new RTFHandler(stream); } else { if (renderer == null) { throw new IllegalStateException( diff --git a/src/java/org/apache/fop/apps/LayoutHandler.java b/src/java/org/apache/fop/apps/LayoutHandler.java deleted file mode 100644 index 8acad12b4..000000000 --- a/src/java/org/apache/fop/apps/LayoutHandler.java +++ /dev/null @@ -1,536 +0,0 @@ -/* - * $Id: LayoutHandler.java,v 1.12 2003/02/27 10:13:06 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modifica- - * tion, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The end-user documentation included with the redistribution, if any, must - * include the following acknowledgment: "This product includes software - * developed by the Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, if - * and wherever such third-party acknowledgments normally appear. - * - * 4. The names "FOP" and "Apache Software Foundation" must not be used to - * endorse or promote products derived from this software without prior - * written permission. For written permission, please contact - * apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", nor may - * "Apache" appear in their name, without prior written permission of the - * Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ============================================================================ - * - * This software consists of voluntary contributions made by many individuals - * on behalf of the Apache Software Foundation and was originally created by - * James Tauber . For more information on the Apache - * Software Foundation, please see . - */ -package org.apache.fop.apps; - -// Java -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; - -// SAX -import org.xml.sax.SAXException; - -// FOP -import org.apache.fop.area.AreaTree; -import org.apache.fop.area.AreaTreeModel; -import org.apache.fop.area.StorePagesModel; -import org.apache.fop.area.Title; -import org.apache.fop.area.TreeExt; -import org.apache.fop.fo.pagination.PageSequence; -import org.apache.fop.layout.FontInfo; -import org.apache.fop.render.Renderer; -import org.apache.fop.fo.flow.Block; -import org.apache.fop.fo.flow.Flow; -import org.apache.fop.fo.flow.ExternalGraphic; -import org.apache.fop.fo.flow.InstreamForeignObject; -import org.apache.fop.fo.flow.Leader; -import org.apache.fop.fo.flow.ListBlock; -import org.apache.fop.fo.flow.ListItem; -import org.apache.fop.fo.flow.Table; -import org.apache.fop.fo.flow.TableBody; -import org.apache.fop.fo.flow.TableCell; -import org.apache.fop.fo.flow.TableRow; - -/** - * Layout handler that receives the structure events. - * This initiates layout processes and corresponding - * rendering processes such as start/end. - */ -public class LayoutHandler extends StructureHandler { - - // TODO: Collecting of statistics should be configurable - private final boolean collectStatistics = true; - private static final boolean MEM_PROFILE_WITH_GC = false; - - /** - * Somewhere to get our stats from. - */ - private Runtime runtime; - - /** - * Keep track of the number of pages rendered. - */ - private int pageCount; - - /** - * Keep track of heap memory allocated, - * for statistical purposes. - */ - private long initialMemory; - - /** - * Keep track of time used by renderer. - */ - private long startTime; - - /** - * The stream to which this rendering is to be - * written to. Note that some renderers - * do not render to a stream, and that this - * member can therefore be null. - */ - private OutputStream outputStream; - - /** - * The renderer being used. - */ - private Renderer renderer; - - /** - * The FontInfo for this renderer. - */ - private FontInfo fontInfo = new FontInfo(); - - /** - * The current AreaTree for the PageSequence being rendered. - */ - private AreaTree areaTree; - private AreaTreeModel atModel; - - /** - * Main constructor - * @param outputStream the stream that the result is rendered to - * @param renderer the renderer to call - * @param store if true then use the store pages model and keep the - * area tree in memory - */ - public LayoutHandler(OutputStream outputStream, Renderer renderer, - boolean store) { - if (collectStatistics) { - runtime = Runtime.getRuntime(); - } - this.outputStream = outputStream; - this.renderer = renderer; - - this.areaTree = new AreaTree(); - this.atModel = AreaTree.createRenderPagesModel(renderer); - //this.atModel = new CachedRenderPagesModel(renderer); - areaTree.setTreeModel(atModel); - } - - /** - * Get the area tree for this layout handler. - * - * @return the area tree for this document - */ - public AreaTree getAreaTree() { - return areaTree; - } - - /** - * Start the document. - * This starts the document in the renderer. - * - * @throws SAXException if there is an error - */ - public void startDocument() throws SAXException { - //Initialize statistics - if (collectStatistics) { - pageCount = 0; - if (MEM_PROFILE_WITH_GC) { - System.gc(); // This takes time but gives better results - } - - initialMemory = runtime.totalMemory() - runtime.freeMemory(); - startTime = System.currentTimeMillis(); - } - try { - renderer.setupFontInfo(fontInfo); - // check that the "any,normal,400" font exists - if (!fontInfo.isSetupValid()) { - throw new SAXException(new FOPException( - "No default font defined by OutputConverter")); - } - renderer.startRenderer(outputStream); - } catch (IOException e) { - throw new SAXException(e); - } - } - - /** - * End the document. - * - * @throws SAXException if there is some error - */ - public void endDocument() throws SAXException { - try { - //processAreaTree(atModel); - areaTree.endDocument(); - renderer.stopRenderer(); - } catch (Exception e) { - throw new SAXException(e); - } - - if (collectStatistics) { - if (MEM_PROFILE_WITH_GC) { - // This takes time but gives better results - System.gc(); - } - long memoryNow = runtime.totalMemory() - runtime.freeMemory(); - long memoryUsed = (memoryNow - initialMemory) / 1024L; - long timeUsed = System.currentTimeMillis() - startTime; - if (getLogger().isDebugEnabled()) { - getLogger().debug("Initial heap size: " + (initialMemory / 1024L) + "Kb"); - getLogger().debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); - getLogger().debug("Total memory used: " + memoryUsed + "Kb"); - if (!MEM_PROFILE_WITH_GC) { - getLogger().debug(" Memory use is indicative; no GC was performed"); - getLogger().debug(" These figures should not be used comparatively"); - } - getLogger().debug("Total time used: " + timeUsed + "ms"); - getLogger().debug("Pages rendered: " + pageCount); - if (pageCount > 0) { - getLogger().debug("Avg render time: " + (timeUsed / pageCount) + "ms/page"); - } - } - } - } - - /** - * Start a page sequence. - * At the start of a page sequence it can start the page sequence - * on the area tree with the page sequence title. - * - * @param pageSeq the page sequence starting - */ - public void startPageSequence(PageSequence pageSeq) { - Title title = null; - if (pageSeq.getTitleFO() != null) { - title = pageSeq.getTitleFO().getTitleArea(); - } - areaTree.startPageSequence(title); - } - - /** - * End the PageSequence. - * The PageSequence formats Pages and adds them to the AreaTree. - * The area tree then handles what happens with the pages. - * - * @param pageSequence the page sequence ending - * @throws FOPException if there is an error formatting the pages - */ - public void endPageSequence(PageSequence pageSequence) - throws FOPException { - //areaTree.setFontInfo(fontInfo); - - if (collectStatistics) { - if (MEM_PROFILE_WITH_GC) { - // This takes time but gives better results - System.gc(); - } - long memoryNow = runtime.totalMemory() - runtime.freeMemory(); - if (getLogger().isDebugEnabled()) { - getLogger().debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); - } - } - pageSequence.format(areaTree); - } - - /** - * @see org.apache.fop.apps.StructureHandler#startFlow(Flow) - */ - public void startFlow(Flow fl) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endFlow(Flow) - */ - public void endFlow(Flow fl) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startBlock(Block) - */ - public void startBlock(Block bl) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endBlock(Block) - */ - public void endBlock(Block bl) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startTable(Table) - */ - public void startTable(Table tbl) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endTable(Table) - */ - public void endTable(Table tbl) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startHeader(TableBody) - */ - public void startHeader(TableBody th) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endHeader(TableBody) - */ - public void endHeader(TableBody th) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startFooter(TableBody) - */ - public void startFooter(TableBody tf) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endFooter(TableBody) - */ - public void endFooter(TableBody tf) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startBody(TableBody) - */ - public void startBody(TableBody tb) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endBody(TableBody) - */ - public void endBody(TableBody tb) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startRow(TableRow) - */ - public void startRow(TableRow tr) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endRow(TableRow) - */ - public void endRow(TableRow tr) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startCell(TableCell) - */ - public void startCell(TableCell tc) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endCell(TableCell) - */ - public void endCell(TableCell tc) { - } - - // Lists - /** - * @see org.apache.fop.apps.StructureHandler#startList(ListBlock) - */ - public void startList(ListBlock lb) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endList(ListBlock) - */ - public void endList(ListBlock lb) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startListItem(ListItem) - */ - public void startListItem(ListItem li) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endListItem(ListItem) - */ - public void endListItem(ListItem li) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startListLabel() - */ - public void startListLabel() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endListLabel() - */ - public void endListLabel() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startListBody() - */ - public void startListBody() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endListBody() - */ - public void endListBody() { - } - - // Static Regions - /** - * @see org.apache.fop.apps.StructureHandler#startStatic() - */ - public void startStatic() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endStatic() - */ - public void endStatic() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startMarkup() - */ - public void startMarkup() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endMarkup() - */ - public void endMarkup() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#startLink() - */ - public void startLink() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#endLink() - */ - public void endLink() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#image(ExternalGraphic) - */ - public void image(ExternalGraphic eg) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#pageRef() - */ - public void pageRef() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#foreignObject(InstreamForeignObject) - */ - public void foreignObject(InstreamForeignObject ifo) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#footnote() - */ - public void footnote() { - } - - /** - * @see org.apache.fop.apps.StructureHandler#leader(Leader) - */ - public void leader(Leader l) { - } - - /** - * @see org.apache.fop.apps.StructureHandler#characters(char[], int, int) - */ - public void characters(char[] data, int start, int length) { - } - - /** - * Process an area tree. - * If a store pages model is used this can read and send all the - * pages to the renderer. - * - * @param model the store pages model - * @throws FOPException if there is an error - */ - private void processAreaTree(StorePagesModel model) throws FOPException { - int count = 0; - int seqc = model.getPageSequenceCount(); - while (count < seqc) { - Title title = model.getTitle(count); - renderer.startPageSequence(title); - int pagec = model.getPageCount(count); - for (int c = 0; c < pagec; c++) { - try { - renderer.renderPage(model.getPage(count, c)); - } catch (IOException ioex) { - throw new FOPException("I/O Error rendering page", - ioex); - } - } - count++; - } - List list = model.getEndExtensions(); - for (count = 0; count < list.size(); count++) { - TreeExt ext = (TreeExt)list.get(count); - renderer.renderExtension(ext); - } - } - - /** - * Get the font information for the layout handler. - * - * @return the font information - */ - public FontInfo getFontInfo() { - return this.fontInfo; - } -} - diff --git a/src/java/org/apache/fop/apps/StructureHandler.java b/src/java/org/apache/fop/apps/StructureHandler.java deleted file mode 100644 index 274bb70e2..000000000 --- a/src/java/org/apache/fop/apps/StructureHandler.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * $Id: StructureHandler.java,v 1.7 2003/02/27 10:13:07 jeremias Exp $ - * ============================================================================ - * The Apache Software License, Version 1.1 - * ============================================================================ - * - * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modifica- - * tion, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. The end-user documentation included with the redistribution, if any, must - * include the following acknowledgment: "This product includes software - * developed by the Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, if - * and wherever such third-party acknowledgments normally appear. - * - * 4. The names "FOP" and "Apache Software Foundation" must not be used to - * endorse or promote products derived from this software without prior - * written permission. For written permission, please contact - * apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", nor may - * "Apache" appear in their name, without prior written permission of the - * Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ============================================================================ - * - * This software consists of voluntary contributions made by many individuals - * on behalf of the Apache Software Foundation and was originally created by - * James Tauber . For more information on the Apache - * Software Foundation, please see . - */ -package org.apache.fop.apps; - -// Java -import java.util.Set; -import java.util.HashSet; - -// Avalon -import org.apache.avalon.framework.logger.AbstractLogEnabled; - -// FOP -import org.apache.fop.fo.flow.Block; -import org.apache.fop.fo.flow.ExternalGraphic; -import org.apache.fop.fo.flow.Flow; -import org.apache.fop.fo.flow.InstreamForeignObject; -import org.apache.fop.fo.flow.Leader; -import org.apache.fop.fo.flow.ListBlock; -import org.apache.fop.fo.flow.ListItem; -import org.apache.fop.fo.flow.Table; -import org.apache.fop.fo.flow.TableBody; -import org.apache.fop.fo.flow.TableCell; -import org.apache.fop.fo.flow.TableRow; -import org.apache.fop.fo.pagination.PageSequence; -import org.apache.fop.layout.FontInfo; - -import org.xml.sax.SAXException; - -/** - * This class receives structure events from the FO Tree. - * Sub-classes can then implement various methods to handle - * the FO Tree when the SAX events occur. - */ -public abstract class StructureHandler extends AbstractLogEnabled { - /** - * The current set of id's in the FO tree. - * This is used so we know if the FO tree contains duplicates. - */ - private Set idReferences = new HashSet(); - - /** - * Main constructor - */ - public StructureHandler() { - } - - /** - * Retuns the set of ID references. - * @return the ID references - */ - public Set getIDReferences() { - return idReferences; - } - - /** - * Returns the FontInfo object associated with this StructureHandler. - * @return the FontInof object - */ - public FontInfo getFontInfo() { - return null; - } - - /** - * This method is called to indicate the start of a new document run. - * @throws SAXException In case of a problem - */ - public abstract void startDocument() throws SAXException; - - /** - * This method is called to indicate the end of a document run. - * @throws SAXException In case of a problem - */ - public abstract void endDocument() throws SAXException; - - /** - * - * @param pageSeq PageSequence that is starting. - */ - public abstract void startPageSequence(PageSequence pageSeq); - - /** - * - * @param pageSeq PageSequence that is ending. - * @throws FOPException For errors encountered. - */ - public abstract void endPageSequence(PageSequence pageSeq) throws FOPException; - - /** - * - * @param fl Flow that is starting. - */ - public abstract void startFlow(Flow fl); - - /** - * - * @param fl Flow that is ending. - */ - public abstract void endFlow(Flow fl); - - /** - * - * @param bl Block that is starting. - */ - public abstract void startBlock(Block bl); - - /** - * - * @param bl Block that is ending. - */ - public abstract void endBlock(Block bl); - - - // Tables - /** - * - * @param tbl Table that is starting. - */ - public abstract void startTable(Table tbl); - - /** - * - * @param tbl Table that is ending. - */ - public abstract void endTable(Table tbl); - - /** - * - * @param th TableBody that is starting; - */ - public abstract void startHeader(TableBody th); - - /** - * - * @param th TableBody that is ending. - */ - public abstract void endHeader(TableBody th); - - /** - * - * @param tf TableFooter that is starting. - */ - public abstract void startFooter(TableBody tf); - - /** - * - * @param tf TableFooter that is ending. - */ - public abstract void endFooter(TableBody tf); - - /** - * - * @param tb TableBody that is starting. - */ - public abstract void startBody(TableBody tb); - - /** - * - * @param tb TableBody that is ending. - */ - public abstract void endBody(TableBody tb); - - /** - * - * @param tr TableRow that is starting. - */ - public abstract void startRow(TableRow tr); - - /** - * - * @param tr TableRow that is ending. - */ - public abstract void endRow(TableRow tr); - - /** - * - * @param tc TableCell that is starting. - */ - public abstract void startCell(TableCell tc); - - /** - * - * @param tc TableCell that is ending. - */ - public abstract void endCell(TableCell tc); - - - // Lists - /** - * - * @param lb ListBlock that is starting. - */ - public abstract void startList(ListBlock lb); - - /** - * - * @param lb ListBlock that is ending. - */ - public abstract void endList(ListBlock lb); - - /** - * - * @param li ListItem that is starting. - */ - public abstract void startListItem(ListItem li); - - /** - * - * @param li ListItem that is ending. - */ - public abstract void endListItem(ListItem li); - - /** - * Process start of a ListLabel. - */ - public abstract void startListLabel(); - - /** - * Process end of a ListLabel. - */ - public abstract void endListLabel(); - - /** - * Process start of a ListBody. - */ - public abstract void startListBody(); - - /** - * Process end of a ListBody. - */ - public abstract void endListBody(); - - // Static Regions - /** - * Process start of a Static. - */ - public abstract void startStatic(); - - /** - * Process end of a Static. - */ - public abstract void endStatic(); - - /** - * Process start of a Markup. - */ - public abstract void startMarkup(); - - /** - * Process end of a Markup. - */ - public abstract void endMarkup(); - - /** - * Process start of a Link. - */ - public abstract void startLink(); - - /** - * Process end of a Link. - */ - public abstract void endLink(); - - /** - * Process an ExternalGraphic. - * @param eg ExternalGraphic to process. - */ - public abstract void image(ExternalGraphic eg); - - /** - * Process a pageRef. - */ - public abstract void pageRef(); - - /** - * Process an InstreamForeignObject. - * @param ifo InstreamForeignObject to process. - */ - public abstract void foreignObject(InstreamForeignObject ifo); - - /** - * Process a footnote. - */ - public abstract void footnote(); - - /** - * Process a Leader. - * @param l Leader to process. - */ - public abstract void leader(Leader l); - - /** - * Process character data. - * @param data Array of characters to process. - * @param start Offset for characters to process. - * @param length Portion of array to process. - */ - public abstract void characters(char data[], int start, int length); - -} - diff --git a/src/java/org/apache/fop/extensions/Bookmarks.java b/src/java/org/apache/fop/extensions/Bookmarks.java index da2ef1840..6189c469a 100644 --- a/src/java/org/apache/fop/extensions/Bookmarks.java +++ b/src/java/org/apache/fop/extensions/Bookmarks.java @@ -50,7 +50,7 @@ */ package org.apache.fop.extensions; -import org.apache.fop.apps.LayoutHandler; +import org.apache.fop.layoutmgr.LayoutHandler; import org.apache.fop.fo.FONode; import org.apache.fop.area.AreaTree; diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 240efac8e..aac600ba6 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -61,7 +61,6 @@ import org.apache.avalon.framework.logger.Logger; // FOP import org.apache.fop.apps.FOPException; -import org.apache.fop.apps.StructureHandler; import org.apache.fop.util.CharUtilities; /** diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java index 734e09114..5567c9fd1 100644 --- a/src/java/org/apache/fop/fo/FOText.java +++ b/src/java/org/apache/fop/fo/FOText.java @@ -58,7 +58,6 @@ import java.util.List; import org.apache.fop.layout.TextState; import org.apache.fop.layoutmgr.LayoutManager; import org.apache.fop.layoutmgr.TextLayoutManager; -import org.apache.fop.apps.StructureHandler; import org.apache.fop.fo.properties.WhiteSpaceCollapse; import org.apache.fop.fo.flow.Block; import org.apache.fop.fo.pagination.Root; diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index ddc2d1417..b9462feed 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -52,7 +52,6 @@ package org.apache.fop.fo; // FOP import org.apache.fop.apps.FOPException; -import org.apache.fop.apps.StructureHandler; // Java import java.util.HashMap; diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index ca33fdcc8..3fd142ce8 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -62,7 +62,6 @@ import org.xml.sax.Attributes; // FOP import org.apache.fop.apps.FOPException; -import org.apache.fop.apps.StructureHandler; import org.apache.fop.fo.properties.FOPropertyMapping; import org.apache.fop.fo.flow.Marker; diff --git a/src/java/org/apache/fop/fo/FObjMixed.java b/src/java/org/apache/fop/fo/FObjMixed.java index 5a09a7e80..072b0a609 100644 --- a/src/java/org/apache/fop/fo/FObjMixed.java +++ b/src/java/org/apache/fop/fo/FObjMixed.java @@ -51,7 +51,6 @@ package org.apache.fop.fo; import org.apache.fop.layout.FontInfo; -import org.apache.fop.apps.StructureHandler; import org.apache.fop.layoutmgr.InlineStackingLayoutManager; import org.apache.fop.layoutmgr.LMiter; diff --git a/src/java/org/apache/fop/fo/StructureHandler.java b/src/java/org/apache/fop/fo/StructureHandler.java new file mode 100644 index 000000000..89d6f6f7a --- /dev/null +++ b/src/java/org/apache/fop/fo/StructureHandler.java @@ -0,0 +1,349 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop.fo; + +// Java +import java.util.Set; +import java.util.HashSet; + +// Avalon +import org.apache.avalon.framework.logger.AbstractLogEnabled; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.Flow; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.flow.TableBody; +import org.apache.fop.fo.flow.TableCell; +import org.apache.fop.fo.flow.TableRow; +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.layout.FontInfo; + +import org.xml.sax.SAXException; + +/** + * This class receives structure events from the FO Tree. + * Sub-classes can then implement various methods to handle + * the FO Tree when the SAX events occur. + */ +public abstract class StructureHandler extends AbstractLogEnabled { + /** + * The current set of id's in the FO tree. + * This is used so we know if the FO tree contains duplicates. + */ + private Set idReferences = new HashSet(); + + /** + * Main constructor + */ + public StructureHandler() { + } + + /** + * Retuns the set of ID references. + * @return the ID references + */ + public Set getIDReferences() { + return idReferences; + } + + /** + * Returns the FontInfo object associated with this StructureHandler. + * @return the FontInof object + */ + public FontInfo getFontInfo() { + return null; + } + + /** + * This method is called to indicate the start of a new document run. + * @throws SAXException In case of a problem + */ + public abstract void startDocument() throws SAXException; + + /** + * This method is called to indicate the end of a document run. + * @throws SAXException In case of a problem + */ + public abstract void endDocument() throws SAXException; + + /** + * + * @param pageSeq PageSequence that is starting. + */ + public abstract void startPageSequence(PageSequence pageSeq); + + /** + * + * @param pageSeq PageSequence that is ending. + * @throws FOPException For errors encountered. + */ + public abstract void endPageSequence(PageSequence pageSeq) throws FOPException; + + /** + * + * @param fl Flow that is starting. + */ + public abstract void startFlow(Flow fl); + + /** + * + * @param fl Flow that is ending. + */ + public abstract void endFlow(Flow fl); + + /** + * + * @param bl Block that is starting. + */ + public abstract void startBlock(Block bl); + + /** + * + * @param bl Block that is ending. + */ + public abstract void endBlock(Block bl); + + + // Tables + /** + * + * @param tbl Table that is starting. + */ + public abstract void startTable(Table tbl); + + /** + * + * @param tbl Table that is ending. + */ + public abstract void endTable(Table tbl); + + /** + * + * @param th TableBody that is starting; + */ + public abstract void startHeader(TableBody th); + + /** + * + * @param th TableBody that is ending. + */ + public abstract void endHeader(TableBody th); + + /** + * + * @param tf TableFooter that is starting. + */ + public abstract void startFooter(TableBody tf); + + /** + * + * @param tf TableFooter that is ending. + */ + public abstract void endFooter(TableBody tf); + + /** + * + * @param tb TableBody that is starting. + */ + public abstract void startBody(TableBody tb); + + /** + * + * @param tb TableBody that is ending. + */ + public abstract void endBody(TableBody tb); + + /** + * + * @param tr TableRow that is starting. + */ + public abstract void startRow(TableRow tr); + + /** + * + * @param tr TableRow that is ending. + */ + public abstract void endRow(TableRow tr); + + /** + * + * @param tc TableCell that is starting. + */ + public abstract void startCell(TableCell tc); + + /** + * + * @param tc TableCell that is ending. + */ + public abstract void endCell(TableCell tc); + + + // Lists + /** + * + * @param lb ListBlock that is starting. + */ + public abstract void startList(ListBlock lb); + + /** + * + * @param lb ListBlock that is ending. + */ + public abstract void endList(ListBlock lb); + + /** + * + * @param li ListItem that is starting. + */ + public abstract void startListItem(ListItem li); + + /** + * + * @param li ListItem that is ending. + */ + public abstract void endListItem(ListItem li); + + /** + * Process start of a ListLabel. + */ + public abstract void startListLabel(); + + /** + * Process end of a ListLabel. + */ + public abstract void endListLabel(); + + /** + * Process start of a ListBody. + */ + public abstract void startListBody(); + + /** + * Process end of a ListBody. + */ + public abstract void endListBody(); + + // Static Regions + /** + * Process start of a Static. + */ + public abstract void startStatic(); + + /** + * Process end of a Static. + */ + public abstract void endStatic(); + + /** + * Process start of a Markup. + */ + public abstract void startMarkup(); + + /** + * Process end of a Markup. + */ + public abstract void endMarkup(); + + /** + * Process start of a Link. + */ + public abstract void startLink(); + + /** + * Process end of a Link. + */ + public abstract void endLink(); + + /** + * Process an ExternalGraphic. + * @param eg ExternalGraphic to process. + */ + public abstract void image(ExternalGraphic eg); + + /** + * Process a pageRef. + */ + public abstract void pageRef(); + + /** + * Process an InstreamForeignObject. + * @param ifo InstreamForeignObject to process. + */ + public abstract void foreignObject(InstreamForeignObject ifo); + + /** + * Process a footnote. + */ + public abstract void footnote(); + + /** + * Process a Leader. + * @param l Leader to process. + */ + public abstract void leader(Leader l); + + /** + * Process character data. + * @param data Array of characters to process. + * @param start Offset for characters to process. + * @param length Portion of array to process. + */ + public abstract void characters(char data[], int start, int length); + +} + diff --git a/src/java/org/apache/fop/fo/flow/Leader.java b/src/java/org/apache/fop/fo/flow/Leader.java index e4958f4bb..23eaf5c04 100644 --- a/src/java/org/apache/fop/fo/flow/Leader.java +++ b/src/java/org/apache/fop/fo/flow/Leader.java @@ -54,7 +54,6 @@ package org.apache.fop.fo.flow; import java.util.List; // FOP -import org.apache.fop.apps.StructureHandler; import org.apache.fop.area.Trait; import org.apache.fop.area.inline.FilledArea; import org.apache.fop.area.inline.InlineArea; @@ -65,6 +64,7 @@ import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.PercentLength; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObjMixed; +import org.apache.fop.fo.StructureHandler; import org.apache.fop.fo.properties.LeaderPattern; import org.apache.fop.layout.AccessibilityProps; import org.apache.fop.layout.AuralProps; diff --git a/src/java/org/apache/fop/fo/flow/PageNumber.java b/src/java/org/apache/fop/fo/flow/PageNumber.java index 6de17c989..1f3385310 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumber.java +++ b/src/java/org/apache/fop/fo/flow/PageNumber.java @@ -65,7 +65,6 @@ import org.apache.fop.layout.RelativePositionProps; import org.apache.fop.layout.TextState; import org.apache.fop.util.CharUtilities; -import org.apache.fop.apps.StructureHandler; import org.apache.fop.layoutmgr.LayoutManager; import org.apache.fop.layoutmgr.LeafNodeLayoutManager; import org.apache.fop.layoutmgr.LayoutContext; @@ -74,6 +73,7 @@ import org.apache.fop.area.inline.Word; import org.apache.fop.datatypes.ColorType; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; +import org.apache.fop.fo.StructureHandler; import org.apache.fop.area.Trait; public class PageNumber extends FObj { diff --git a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java index 3aa394272..5e7627a9f 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumberCitation.java +++ b/src/java/org/apache/fop/fo/flow/PageNumberCitation.java @@ -54,7 +54,6 @@ package org.apache.fop.fo.flow; import java.util.List; // FOP -import org.apache.fop.apps.StructureHandler; import org.apache.fop.area.PageViewport; import org.apache.fop.area.Resolveable; import org.apache.fop.area.Trait; @@ -64,6 +63,7 @@ import org.apache.fop.area.inline.Word; import org.apache.fop.datatypes.ColorType; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; +import org.apache.fop.fo.StructureHandler; import org.apache.fop.layout.AccessibilityProps; import org.apache.fop.layout.AuralProps; import org.apache.fop.layout.BackgroundProps; diff --git a/src/java/org/apache/fop/layoutmgr/LayoutHandler.java b/src/java/org/apache/fop/layoutmgr/LayoutHandler.java new file mode 100644 index 000000000..42805fc7e --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/LayoutHandler.java @@ -0,0 +1,538 @@ +/* + * $Id$ + * ============================================================================ + * The Apache Software License, Version 1.1 + * ============================================================================ + * + * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The end-user documentation included with the redistribution, if any, must + * include the following acknowledgment: "This product includes software + * developed by the Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, if + * and wherever such third-party acknowledgments normally appear. + * + * 4. The names "FOP" and "Apache Software Foundation" must not be used to + * endorse or promote products derived from this software without prior + * written permission. For written permission, please contact + * apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", nor may + * "Apache" appear in their name, without prior written permission of the + * Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- + * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ============================================================================ + * + * This software consists of voluntary contributions made by many individuals + * on behalf of the Apache Software Foundation and was originally created by + * James Tauber . For more information on the Apache + * Software Foundation, please see . + */ +package org.apache.fop.layoutmgr; + +// Java +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; + +// SAX +import org.xml.sax.SAXException; + +// FOP +import org.apache.fop.apps.FOPException; +import org.apache.fop.area.AreaTree; +import org.apache.fop.area.AreaTreeModel; +import org.apache.fop.area.StorePagesModel; +import org.apache.fop.area.Title; +import org.apache.fop.area.TreeExt; +import org.apache.fop.fo.StructureHandler; +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.layout.FontInfo; +import org.apache.fop.render.Renderer; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.Flow; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.flow.TableBody; +import org.apache.fop.fo.flow.TableCell; +import org.apache.fop.fo.flow.TableRow; + +/** + * Layout handler that receives the structure events. + * This initiates layout processes and corresponding + * rendering processes such as start/end. + */ +public class LayoutHandler extends StructureHandler { + + // TODO: Collecting of statistics should be configurable + private final boolean collectStatistics = true; + private static final boolean MEM_PROFILE_WITH_GC = false; + + /** + * Somewhere to get our stats from. + */ + private Runtime runtime; + + /** + * Keep track of the number of pages rendered. + */ + private int pageCount; + + /** + * Keep track of heap memory allocated, + * for statistical purposes. + */ + private long initialMemory; + + /** + * Keep track of time used by renderer. + */ + private long startTime; + + /** + * The stream to which this rendering is to be + * written to. Note that some renderers + * do not render to a stream, and that this + * member can therefore be null. + */ + private OutputStream outputStream; + + /** + * The renderer being used. + */ + private Renderer renderer; + + /** + * The FontInfo for this renderer. + */ + private FontInfo fontInfo = new FontInfo(); + + /** + * The current AreaTree for the PageSequence being rendered. + */ + private AreaTree areaTree; + private AreaTreeModel atModel; + + /** + * Main constructor + * @param outputStream the stream that the result is rendered to + * @param renderer the renderer to call + * @param store if true then use the store pages model and keep the + * area tree in memory + */ + public LayoutHandler(OutputStream outputStream, Renderer renderer, + boolean store) { + if (collectStatistics) { + runtime = Runtime.getRuntime(); + } + this.outputStream = outputStream; + this.renderer = renderer; + + this.areaTree = new AreaTree(); + this.atModel = AreaTree.createRenderPagesModel(renderer); + //this.atModel = new CachedRenderPagesModel(renderer); + areaTree.setTreeModel(atModel); + } + + /** + * Get the area tree for this layout handler. + * + * @return the area tree for this document + */ + public AreaTree getAreaTree() { + return areaTree; + } + + /** + * Start the document. + * This starts the document in the renderer. + * + * @throws SAXException if there is an error + */ + public void startDocument() throws SAXException { + //Initialize statistics + if (collectStatistics) { + pageCount = 0; + if (MEM_PROFILE_WITH_GC) { + System.gc(); // This takes time but gives better results + } + + initialMemory = runtime.totalMemory() - runtime.freeMemory(); + startTime = System.currentTimeMillis(); + } + try { + renderer.setupFontInfo(fontInfo); + // check that the "any,normal,400" font exists + if (!fontInfo.isSetupValid()) { + throw new SAXException(new FOPException( + "No default font defined by OutputConverter")); + } + renderer.startRenderer(outputStream); + } catch (IOException e) { + throw new SAXException(e); + } + } + + /** + * End the document. + * + * @throws SAXException if there is some error + */ + public void endDocument() throws SAXException { + try { + //processAreaTree(atModel); + areaTree.endDocument(); + renderer.stopRenderer(); + } catch (Exception e) { + throw new SAXException(e); + } + + if (collectStatistics) { + if (MEM_PROFILE_WITH_GC) { + // This takes time but gives better results + System.gc(); + } + long memoryNow = runtime.totalMemory() - runtime.freeMemory(); + long memoryUsed = (memoryNow - initialMemory) / 1024L; + long timeUsed = System.currentTimeMillis() - startTime; + if (getLogger().isDebugEnabled()) { + getLogger().debug("Initial heap size: " + (initialMemory / 1024L) + "Kb"); + getLogger().debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); + getLogger().debug("Total memory used: " + memoryUsed + "Kb"); + if (!MEM_PROFILE_WITH_GC) { + getLogger().debug(" Memory use is indicative; no GC was performed"); + getLogger().debug(" These figures should not be used comparatively"); + } + getLogger().debug("Total time used: " + timeUsed + "ms"); + getLogger().debug("Pages rendered: " + pageCount); + if (pageCount > 0) { + getLogger().debug("Avg render time: " + (timeUsed / pageCount) + "ms/page"); + } + } + } + } + + /** + * Start a page sequence. + * At the start of a page sequence it can start the page sequence + * on the area tree with the page sequence title. + * + * @param pageSeq the page sequence starting + */ + public void startPageSequence(PageSequence pageSeq) { + Title title = null; + if (pageSeq.getTitleFO() != null) { + title = pageSeq.getTitleFO().getTitleArea(); + } + areaTree.startPageSequence(title); + } + + /** + * End the PageSequence. + * The PageSequence formats Pages and adds them to the AreaTree. + * The area tree then handles what happens with the pages. + * + * @param pageSequence the page sequence ending + * @throws FOPException if there is an error formatting the pages + */ + public void endPageSequence(PageSequence pageSequence) + throws FOPException { + //areaTree.setFontInfo(fontInfo); + + if (collectStatistics) { + if (MEM_PROFILE_WITH_GC) { + // This takes time but gives better results + System.gc(); + } + long memoryNow = runtime.totalMemory() - runtime.freeMemory(); + if (getLogger().isDebugEnabled()) { + getLogger().debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); + } + } + pageSequence.format(areaTree); + } + + /** + * @see org.apache.fop.apps.StructureHandler#startFlow(Flow) + */ + public void startFlow(Flow fl) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endFlow(Flow) + */ + public void endFlow(Flow fl) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startBlock(Block) + */ + public void startBlock(Block bl) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endBlock(Block) + */ + public void endBlock(Block bl) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startTable(Table) + */ + public void startTable(Table tbl) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endTable(Table) + */ + public void endTable(Table tbl) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startHeader(TableBody) + */ + public void startHeader(TableBody th) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endHeader(TableBody) + */ + public void endHeader(TableBody th) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startFooter(TableBody) + */ + public void startFooter(TableBody tf) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endFooter(TableBody) + */ + public void endFooter(TableBody tf) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startBody(TableBody) + */ + public void startBody(TableBody tb) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endBody(TableBody) + */ + public void endBody(TableBody tb) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startRow(TableRow) + */ + public void startRow(TableRow tr) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endRow(TableRow) + */ + public void endRow(TableRow tr) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startCell(TableCell) + */ + public void startCell(TableCell tc) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endCell(TableCell) + */ + public void endCell(TableCell tc) { + } + + // Lists + /** + * @see org.apache.fop.apps.StructureHandler#startList(ListBlock) + */ + public void startList(ListBlock lb) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endList(ListBlock) + */ + public void endList(ListBlock lb) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startListItem(ListItem) + */ + public void startListItem(ListItem li) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endListItem(ListItem) + */ + public void endListItem(ListItem li) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startListLabel() + */ + public void startListLabel() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endListLabel() + */ + public void endListLabel() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startListBody() + */ + public void startListBody() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endListBody() + */ + public void endListBody() { + } + + // Static Regions + /** + * @see org.apache.fop.apps.StructureHandler#startStatic() + */ + public void startStatic() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endStatic() + */ + public void endStatic() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startMarkup() + */ + public void startMarkup() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endMarkup() + */ + public void endMarkup() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#startLink() + */ + public void startLink() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#endLink() + */ + public void endLink() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#image(ExternalGraphic) + */ + public void image(ExternalGraphic eg) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#pageRef() + */ + public void pageRef() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#foreignObject(InstreamForeignObject) + */ + public void foreignObject(InstreamForeignObject ifo) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#footnote() + */ + public void footnote() { + } + + /** + * @see org.apache.fop.apps.StructureHandler#leader(Leader) + */ + public void leader(Leader l) { + } + + /** + * @see org.apache.fop.apps.StructureHandler#characters(char[], int, int) + */ + public void characters(char[] data, int start, int length) { + } + + /** + * Process an area tree. + * If a store pages model is used this can read and send all the + * pages to the renderer. + * + * @param model the store pages model + * @throws FOPException if there is an error + */ + private void processAreaTree(StorePagesModel model) throws FOPException { + int count = 0; + int seqc = model.getPageSequenceCount(); + while (count < seqc) { + Title title = model.getTitle(count); + renderer.startPageSequence(title); + int pagec = model.getPageCount(count); + for (int c = 0; c < pagec; c++) { + try { + renderer.renderPage(model.getPage(count, c)); + } catch (IOException ioex) { + throw new FOPException("I/O Error rendering page", + ioex); + } + } + count++; + } + List list = model.getEndExtensions(); + for (count = 0; count < list.size(); count++) { + TreeExt ext = (TreeExt)list.get(count); + renderer.renderExtension(ext); + } + } + + /** + * Get the font information for the layout handler. + * + * @return the font information + */ + public FontInfo getFontInfo() { + return this.fontInfo; + } +} + diff --git a/src/java/org/apache/fop/mif/MIFHandler.java b/src/java/org/apache/fop/mif/MIFHandler.java index 402d97919..5685dcf08 100644 --- a/src/java/org/apache/fop/mif/MIFHandler.java +++ b/src/java/org/apache/fop/mif/MIFHandler.java @@ -58,7 +58,7 @@ import java.io.OutputStream; import org.xml.sax.SAXException; // FOP -import org.apache.fop.apps.StructureHandler; +import org.apache.fop.fo.StructureHandler; import org.apache.fop.fo.flow.Block; import org.apache.fop.fo.flow.Flow; import org.apache.fop.fo.pagination.PageSequence; @@ -107,14 +107,14 @@ public class MIFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler#getFontInfo() + * @see org.apache.fop.fo.StructureHandler#getFontInfo() */ public FontInfo getFontInfo() { return fontInfo; } /** - * @see org.apache.fop.apps.StructureHandler#startDocument() + * @see org.apache.fop.fo.StructureHandler#startDocument() */ public void startDocument() throws SAXException { mifFile = new MIFFile(); @@ -126,7 +126,7 @@ public class MIFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler#endDocument() + * @see org.apache.fop.fo.StructureHandler#endDocument() */ public void endDocument() throws SAXException { // finish all open elements @@ -143,7 +143,7 @@ public class MIFHandler extends StructureHandler { * Start the page sequence. * This creates the pages in the MIF document that will be used * by the following flows and static areas. - * @see org.apache.fop.apps.StructureHandler + * @see org.apache.fop.fo.StructureHandler */ public void startPageSequence(PageSequence pageSeq) { // get the layout master set @@ -190,14 +190,14 @@ public class MIFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler#endPageSequence(PageSequence) + * @see org.apache.fop.fo.StructureHandler#endPageSequence(PageSequence) */ public void endPageSequence(PageSequence pageSeq) throws FOPException { } /** - * @see org.apache.fop.apps.StructureHandler#startFlow(Flow) + * @see org.apache.fop.fo.StructureHandler#startFlow(Flow) */ public void startFlow(Flow fl) { // start text flow in body region @@ -205,7 +205,7 @@ public class MIFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler#endFlow(Flow) + * @see org.apache.fop.fo.StructureHandler#endFlow(Flow) */ public void endFlow(Flow fl) { textFlow.finish(true); @@ -214,7 +214,7 @@ public class MIFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler#startBlock(Block) + * @see org.apache.fop.fo.StructureHandler#startBlock(Block) */ public void startBlock(Block bl) { para = new MIFElement("Para"); @@ -223,7 +223,7 @@ public class MIFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler#endBlock(Block) + * @see org.apache.fop.fo.StructureHandler#endBlock(Block) */ public void endBlock(Block bl) { para.finish(true); @@ -231,195 +231,195 @@ public class MIFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler#startTable(Table) + * @see org.apache.fop.fo.StructureHandler#startTable(Table) */ public void startTable(Table tbl) { } /** - * @see org.apache.fop.apps.StructureHandler#endTable(Table) + * @see org.apache.fop.fo.StructureHandler#endTable(Table) */ public void endTable(Table tbl) { } /** - * @see org.apache.fop.apps.StructureHandler#startHeader(TableBody) + * @see org.apache.fop.fo.StructureHandler#startHeader(TableBody) */ public void startHeader(TableBody th) { } /** - * @see org.apache.fop.apps.StructureHandler#endHeader(TableBody) + * @see org.apache.fop.fo.StructureHandler#endHeader(TableBody) */ public void endHeader(TableBody th) { } /** - * @see org.apache.fop.apps.StructureHandler#startFooter(TableBody) + * @see org.apache.fop.fo.StructureHandler#startFooter(TableBody) */ public void startFooter(TableBody tf) { } /** - * @see org.apache.fop.apps.StructureHandler#endFooter(TableBody) + * @see org.apache.fop.fo.StructureHandler#endFooter(TableBody) */ public void endFooter(TableBody tf) { } /** - * @see org.apache.fop.apps.StructureHandler#startBody(TableBody) + * @see org.apache.fop.fo.StructureHandler#startBody(TableBody) */ public void startBody(TableBody tb) { } /** - * @see org.apache.fop.apps.StructureHandler#endBody(TableBody) + * @see org.apache.fop.fo.StructureHandler#endBody(TableBody) */ public void endBody(TableBody tb) { } /** - * @see org.apache.fop.apps.StructureHandler#startRow(TableRow) + * @see org.apache.fop.fo.StructureHandler#startRow(TableRow) */ public void startRow(TableRow tr) { } /** - * @see org.apache.fop.apps.StructureHandler#endRow(TableRow) + * @see org.apache.fop.fo.StructureHandler#endRow(TableRow) */ public void endRow(TableRow tr) { } /** - * @see org.apache.fop.apps.StructureHandler#startCell(TableCell) + * @see org.apache.fop.fo.StructureHandler#startCell(TableCell) */ public void startCell(TableCell tc) { } /** - * @see org.apache.fop.apps.StructureHandler#endCell(TableCell) + * @see org.apache.fop.fo.StructureHandler#endCell(TableCell) */ public void endCell(TableCell tc) { } // Lists /** - * @see org.apache.fop.apps.StructureHandler#startList(ListBlock) + * @see org.apache.fop.fo.StructureHandler#startList(ListBlock) */ public void startList(ListBlock lb) { } /** - * @see org.apache.fop.apps.StructureHandler#endList(ListBlock) + * @see org.apache.fop.fo.StructureHandler#endList(ListBlock) */ public void endList(ListBlock lb) { } /** - * @see org.apache.fop.apps.StructureHandler#startListItem(ListItem) + * @see org.apache.fop.fo.StructureHandler#startListItem(ListItem) */ public void startListItem(ListItem li) { } /** - * @see org.apache.fop.apps.StructureHandler#endListItem(ListItem) + * @see org.apache.fop.fo.StructureHandler#endListItem(ListItem) */ public void endListItem(ListItem li) { } /** - * @see org.apache.fop.apps.StructureHandler#startListLabel() + * @see org.apache.fop.fo.StructureHandler#startListLabel() */ public void startListLabel() { } /** - * @see org.apache.fop.apps.StructureHandler#endListLabel() + * @see org.apache.fop.fo.StructureHandler#endListLabel() */ public void endListLabel() { } /** - * @see org.apache.fop.apps.StructureHandler#startListBody() + * @see org.apache.fop.fo.StructureHandler#startListBody() */ public void startListBody() { } /** - * @see org.apache.fop.apps.StructureHandler#endListBody() + * @see org.apache.fop.fo.StructureHandler#endListBody() */ public void endListBody() { } // Static Regions /** - * @see org.apache.fop.apps.StructureHandler#startStatic() + * @see org.apache.fop.fo.StructureHandler#startStatic() */ public void startStatic() { } /** - * @see org.apache.fop.apps.StructureHandler#endStatic() + * @see org.apache.fop.fo.StructureHandler#endStatic() */ public void endStatic() { } /** - * @see org.apache.fop.apps.StructureHandler#startMarkup() + * @see org.apache.fop.fo.StructureHandler#startMarkup() */ public void startMarkup() { } /** - * @see org.apache.fop.apps.StructureHandler#endMarkup() + * @see org.apache.fop.fo.StructureHandler#endMarkup() */ public void endMarkup() { } /** - * @see org.apache.fop.apps.StructureHandler#startLink() + * @see org.apache.fop.fo.StructureHandler#startLink() */ public void startLink() { } /** - * @see org.apache.fop.apps.StructureHandler#endLink() + * @see org.apache.fop.fo.StructureHandler#endLink() */ public void endLink() { } /** - * @see org.apache.fop.apps.StructureHandler#image(ExternalGraphic) + * @see org.apache.fop.fo.StructureHandler#image(ExternalGraphic) */ public void image(ExternalGraphic eg) { } /** - * @see org.apache.fop.apps.StructureHandler#pageRef() + * @see org.apache.fop.fo.StructureHandler#pageRef() */ public void pageRef() { } /** - * @see org.apache.fop.apps.StructureHandler#foreignObject(InstreamForeignObject) + * @see org.apache.fop.fo.StructureHandler#foreignObject(InstreamForeignObject) */ public void foreignObject(InstreamForeignObject ifo) { } /** - * @see org.apache.fop.apps.StructureHandler#footnote() + * @see org.apache.fop.fo.StructureHandler#footnote() */ public void footnote() { } /** - * @see org.apache.fop.apps.StructureHandler#leader(Leader) + * @see org.apache.fop.fo.StructureHandler#leader(Leader) */ public void leader(Leader l) { } /** - * @see org.apache.fop.apps.StructureHandler#characters(char[], int, int) + * @see org.apache.fop.fo.StructureHandler#characters(char[], int, int) */ public void characters(char data[], int start, int length) { if (para != null) { diff --git a/src/java/org/apache/fop/rtf/renderer/RTFHandler.java b/src/java/org/apache/fop/rtf/renderer/RTFHandler.java index 105efd91c..91814e97d 100644 --- a/src/java/org/apache/fop/rtf/renderer/RTFHandler.java +++ b/src/java/org/apache/fop/rtf/renderer/RTFHandler.java @@ -59,11 +59,10 @@ import java.io.IOException; import org.xml.sax.SAXException; // FOP -import org.apache.fop.apps.StructureHandler; import org.apache.fop.layout.FontInfo; import org.apache.fop.apps.FOPException; - import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.StructureHandler; import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.properties.Constants; import org.apache.fop.fo.flow.Block; @@ -117,14 +116,14 @@ public class RTFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler#getFontInfo() + * @see org.apache.fop.fo.StructureHandler#getFontInfo() */ public FontInfo getFontInfo() { return this.fontInfo; } /** - * @see org.apache.fop.apps.StructureHandler#startDocument() + * @see org.apache.fop.fo.StructureHandler#startDocument() */ public void startDocument() throws SAXException { // FIXME sections should be created @@ -138,7 +137,7 @@ public class RTFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler#endDocument() + * @see org.apache.fop.fo.StructureHandler#endDocument() */ public void endDocument() throws SAXException { try { @@ -150,7 +149,7 @@ public class RTFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler + * @see org.apache.fop.fo.StructureHandler */ public void startPageSequence(PageSequence pageSeq) { try { @@ -166,25 +165,25 @@ public class RTFHandler extends StructureHandler { } /** - * @see org.apache.fop.apps.StructureHandler#endPageSequence(PageSequence) + * @see org.apache.fop.fo.StructureHandler#endPageSequence(PageSequence) */ public void endPageSequence(PageSequence pageSeq) throws FOPException { } /** - * @see org.apache.fop.apps.StructureHandler#startFlow(Flow) + * @see org.apache.fop.fo.StructureHandler#startFlow(Flow) */ public void startFlow(Flow fl) { } /** - * @see org.apache.fop.apps.StructureHandler#endFlow(Flow) + * @see org.apache.fop.fo.StructureHandler#endFlow(Flow) */ public void endFlow(Flow fl) { } /** - * @see org.apache.fop.apps.StructureHandler#startBlock(Block) + * @see org.apache.fop.fo.StructureHandler#startBlock(Block) */ public void startBlock(Block bl) { try { @@ -199,201 +198,201 @@ public class RTFHandler extends StructureHandler { /** - * @see org.apache.fop.apps.StructureHandler#endBlock(Block) + * @see org.apache.fop.fo.StructureHandler#endBlock(Block) */ public void endBlock(Block bl) { } /** - * @see org.apache.fop.apps.StructureHandler#startTable(Table) + * @see org.apache.fop.fo.StructureHandler#startTable(Table) */ public void startTable(Table tbl) { } /** - * @see org.apache.fop.apps.StructureHandler#endTable(Table) + * @see org.apache.fop.fo.StructureHandler#endTable(Table) */ public void endTable(Table tbl) { } /** - * @see org.apache.fop.apps.StructureHandler#startHeader(TableBody) + * @see org.apache.fop.fo.StructureHandler#startHeader(TableBody) */ public void startHeader(TableBody th) { } /** - * @see org.apache.fop.apps.StructureHandler#endHeader(TableBody) + * @see org.apache.fop.fo.StructureHandler#endHeader(TableBody) */ public void endHeader(TableBody th) { } /** - * @see org.apache.fop.apps.StructureHandler#startFooter(TableBody) + * @see org.apache.fop.fo.StructureHandler#startFooter(TableBody) */ public void startFooter(TableBody tf) { } /** - * @see org.apache.fop.apps.StructureHandler#endFooter(TableBody) + * @see org.apache.fop.fo.StructureHandler#endFooter(TableBody) */ public void endFooter(TableBody tf) { } /** - * @see org.apache.fop.apps.StructureHandler#startBody(TableBody) + * @see org.apache.fop.fo.StructureHandler#startBody(TableBody) */ public void startBody(TableBody tb) { } /** - * @see org.apache.fop.apps.StructureHandler#endBody(TableBody) + * @see org.apache.fop.fo.StructureHandler#endBody(TableBody) */ public void endBody(TableBody tb) { } /** - * @see org.apache.fop.apps.StructureHandler#startRow(TableRow) + * @see org.apache.fop.fo.StructureHandler#startRow(TableRow) */ public void startRow(TableRow tr) { } /** - * @see org.apache.fop.apps.StructureHandler#endRow(TableRow) + * @see org.apache.fop.fo.StructureHandler#endRow(TableRow) */ public void endRow(TableRow tr) { } /** - * @see org.apache.fop.apps.StructureHandler#startCell(TableCell) + * @see org.apache.fop.fo.StructureHandler#startCell(TableCell) */ public void startCell(TableCell tc) { } /** - * @see org.apache.fop.apps.StructureHandler#endCell(TableCell) + * @see org.apache.fop.fo.StructureHandler#endCell(TableCell) */ public void endCell(TableCell tc) { } // Lists /** - * @see org.apache.fop.apps.StructureHandler#startList(ListBlock) + * @see org.apache.fop.fo.StructureHandler#startList(ListBlock) */ public void startList(ListBlock lb) { } /** - * @see org.apache.fop.apps.StructureHandler#endList(ListBlock) + * @see org.apache.fop.fo.StructureHandler#endList(ListBlock) */ public void endList(ListBlock lb) { } /** - * @see org.apache.fop.apps.StructureHandler#startListItem(ListItem) + * @see org.apache.fop.fo.StructureHandler#startListItem(ListItem) */ public void startListItem(ListItem li) { } /** - * @see org.apache.fop.apps.StructureHandler#endListItem(ListItem) + * @see org.apache.fop.fo.StructureHandler#endListItem(ListItem) */ public void endListItem(ListItem li) { } /** - * @see org.apache.fop.apps.StructureHandler#startListLabel() + * @see org.apache.fop.fo.StructureHandler#startListLabel() */ public void startListLabel() { } /** - * @see org.apache.fop.apps.StructureHandler#endListLabel() + * @see org.apache.fop.fo.StructureHandler#endListLabel() */ public void endListLabel() { } /** - * @see org.apache.fop.apps.StructureHandler#startListBody() + * @see org.apache.fop.fo.StructureHandler#startListBody() */ public void startListBody() { } /** - * @see org.apache.fop.apps.StructureHandler#endListBody() + * @see org.apache.fop.fo.StructureHandler#endListBody() */ public void endListBody() { } // Static Regions /** - * @see org.apache.fop.apps.StructureHandler#startStatic() + * @see org.apache.fop.fo.StructureHandler#startStatic() */ public void startStatic() { } /** - * @see org.apache.fop.apps.StructureHandler#endStatic() + * @see org.apache.fop.fo.StructureHandler#endStatic() */ public void endStatic() { } /** - * @see org.apache.fop.apps.StructureHandler#startMarkup() + * @see org.apache.fop.fo.StructureHandler#startMarkup() */ public void startMarkup() { } /** - * @see org.apache.fop.apps.StructureHandler#endMarkup() + * @see org.apache.fop.fo.StructureHandler#endMarkup() */ public void endMarkup() { } /** - * @see org.apache.fop.apps.StructureHandler#startLink() + * @see org.apache.fop.fo.StructureHandler#startLink() */ public void startLink() { } /** - * @see org.apache.fop.apps.StructureHandler#endLink() + * @see org.apache.fop.fo.StructureHandler#endLink() */ public void endLink() { } /** - * @see org.apache.fop.apps.StructureHandler#image(ExternalGraphic) + * @see org.apache.fop.fo.StructureHandler#image(ExternalGraphic) */ public void image(ExternalGraphic eg) { } /** - * @see org.apache.fop.apps.StructureHandler#pageRef() + * @see org.apache.fop.fo.StructureHandler#pageRef() */ public void pageRef() { } /** - * @see org.apache.fop.apps.StructureHandler#foreignObject(InstreamForeignObject) + * @see org.apache.fop.fo.StructureHandler#foreignObject(InstreamForeignObject) */ public void foreignObject(InstreamForeignObject ifo) { } /** - * @see org.apache.fop.apps.StructureHandler#footnote() + * @see org.apache.fop.fo.StructureHandler#footnote() */ public void footnote() { } /** - * @see org.apache.fop.apps.StructureHandler#leader(Leader) + * @see org.apache.fop.fo.StructureHandler#leader(Leader) */ public void leader(Leader l) { } /** - * @see org.apache.fop.apps.StructureHandler#characters(char[], int, int) + * @see org.apache.fop.fo.StructureHandler#characters(char[], int, int) */ public void characters(char data[], int start, int length) { try {