From: Glen Mazza Date: Tue, 13 Jul 2004 00:16:22 +0000 (+0000) Subject: 1.) Combined the AreaTree and FOTreeHandler into a new AreaTreeHandler X-Git-Tag: Root_Temp_KnuthStylePageBreaking~678 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2562ceb381063ca04af64a23a1e2de683f4332ba;p=xmlgraphics-fop.git 1.) Combined the AreaTree and FOTreeHandler into a new AreaTreeHandler object. FOTreeHandler was primarily acting as an AreaTreeHandler, and AreaTree had a 1-to-1 relationship with it. Comments most welcome. 2.) Created convenience methods in FOInputHandler for those subclasses which do not handle certain signals/events called from the formatting objects (i.e., AreaTreeHandler). git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197784 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 2cfd3447c..c0fa632af 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -34,7 +34,7 @@ import org.apache.fop.fo.Constants; import org.apache.fop.fo.ElementMapping; import org.apache.fop.fo.FOTreeBuilder; import org.apache.fop.fo.FOInputHandler; -import org.apache.fop.fo.FOTreeHandler; +import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.render.awt.AWTRenderer; import org.apache.fop.render.mif.MIFHandler; import org.apache.fop.render.rtf.RTFHandler; @@ -314,7 +314,7 @@ public class Driver implements Constants { "Renderer must be set using setRenderer(int renderType)"); } - foInputHandler = new FOTreeHandler(foUserAgent, rendererType, + foInputHandler = new AreaTreeHandler(foUserAgent, rendererType, stream); } diff --git a/src/java/org/apache/fop/area/AreaTree.java b/src/java/org/apache/fop/area/AreaTree.java deleted file mode 100644 index 26593ceb9..000000000 --- a/src/java/org/apache/fop/area/AreaTree.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ -package org.apache.fop.area; - -// Java -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.HashMap; -import java.util.Set; -import java.util.HashSet; -import java.util.Iterator; - -// XML -import org.xml.sax.SAXException; - -// Apache -import org.apache.fop.apps.FOPException; -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.area.extensions.BookmarkData; -import org.apache.fop.fo.extensions.Outline; -import org.apache.fop.fo.extensions.Bookmarks; -import org.apache.fop.fonts.FontInfo; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Area tree for formatting objects. - * - * Concepts: - * The area tree is to be as small as possible. With minimal classes - * and data to fully represent an area tree for formatting objects. - * The area tree needs to be simple to render and follow the spec - * closely. - * This area tree has the concept of page sequences. - * Where ever possible information is discarded or optimized to - * keep memory use low. The data is also organized to make it - * possible for renderers to minimize their output. - * A page can be saved if not fully resolved and once rendered - * a page contains only size and id reference information. - * The area tree pages are organized in a model that depends on the - * type of renderer. - */ -public class AreaTree { - // allows for different models to deal with adding/rendering - // in different situations - private AreaTreeModel model; - - // hashmap of arraylists containing pages with id area - private Map idLocations = new HashMap(); - - // list of id's yet to be resolved and arraylists of pages - private Map resolve = new HashMap(); - - private List treeExtensions = new ArrayList(); - - private static Log log = LogFactory.getLog(AreaTree.class); - - private FOUserAgent foUserAgent; - - /** - * Constructor. - * @param userAgent FOUserAgent object for process - * @param renderType Desired fo.Constants output type (RENDER_PDF, - * RENDER_PS, etc.) - * @param fontInfo FontInfo object - * @param stream OutputStream - */ - public AreaTree (FOUserAgent userAgent, int renderType, - FontInfo fontInfo, OutputStream stream) throws FOPException { - - foUserAgent = userAgent; - - // model = new CachedRenderPagesModel(userAgent, renderType, - // fontInfo, stream); - model = new RenderPagesModel(userAgent, renderType, fontInfo, - stream); - } - - /** - * Get the area tree model for this area tree. - * - * @return AreaTreeModel the model being used for this area tree - */ - public AreaTreeModel getAreaTreeModel() { - return model; - } - - /** - * Start a new page sequence. - * This signals that a new page sequence has started in the document. - * @param title the title of the new page sequence or null if no title - */ - public void startPageSequence(Title title) { - model.startPageSequence(title); - } - - /** - * Add a new page to the area tree. - * @param page the page to add - */ - public void addPage(PageViewport page) { - model.addPage(page); - } - - /** - * Add an id reference pointing to a page viewport. - * @param id the id of the reference - * @param pv the page viewport that contains the id reference - */ - public void addIDRef(String id, PageViewport pv) { - List list = (List)idLocations.get(id); - if (list == null) { - list = new ArrayList(); - idLocations.put(id, list); - } - list.add(pv); - - Set todo = (Set)resolve.get(id); - if (todo != null) { - for (Iterator iter = todo.iterator(); iter.hasNext();) { - Resolveable res = (Resolveable)iter.next(); - res.resolve(id, list); - } - resolve.remove(id); - } - } - - /** - * Get the list of id references for an id. - * @param id the id to lookup - * @return the list of id references. - */ - public List getIDReferences(String id) { - return (List)idLocations.get(id); - } - - /** - * Add an unresolved object with a given id. - * @param id the id reference that needs resolving - * @param res the Resolveable object to resolve - */ - public void addUnresolvedID(String id, Resolveable res) { - Set todo = (Set)resolve.get(id); - if (todo == null) { - todo = new HashSet(); - resolve.put(id, todo); - } - todo.add(res); - } - - /** - * Add a tree extension. - * This checks if the extension is resolveable and attempts - * to resolve or add the resolveable ids for later resolution. - * @param ext the tree extension to add. - */ - public void addTreeExtension(TreeExt ext) { - treeExtensions.add(ext); - if (ext.isResolveable()) { - Resolveable res = (Resolveable)ext; - String[] ids = res.getIDs(); - for (int count = 0; count < ids.length; count++) { - if (idLocations.containsKey(ids[count])) { - res.resolve(ids[count], (List)idLocations.get(ids[count])); - } else { - Set todo = (Set)resolve.get(ids[count]); - if (todo == null) { - todo = new HashSet(); - resolve.put(ids[count], todo); - } - todo.add(ext); - } - } - } else { - handleTreeExtension(ext, TreeExt.IMMEDIATELY); - } - } - - /** - * Handle a tree extension. - * This sends the extension to the model for handling. - * @param ext the tree extension to handle - * @param when when the extension should be handled by the model - */ - public void handleTreeExtension(TreeExt ext, int when) { - // queue tree extension according to the when - model.addExtension(ext, when); - } - - /** - * Signal end of document. - * This indicates that the document is complete and any unresolved - * reference can be dealt with. - */ - public void endDocument() throws SAXException { - for (Iterator iter = resolve.keySet().iterator(); iter.hasNext();) { - String id = (String)iter.next(); - Set list = (Set)resolve.get(id); - for (Iterator resIter = list.iterator(); resIter.hasNext();) { - Resolveable res = (Resolveable)resIter.next(); - if (!res.isResolved()) { - res.resolve(id, null); - } - } - } - model.endDocument(); - } - - /** - * Create the bookmark data in the area tree. - */ - public void addBookmarksToAreaTree(Bookmarks bookmarks) { - if (bookmarks == null) { - return; - } - - log.debug("adding bookmarks to area tree"); - BookmarkData data = new BookmarkData(); - for (int count = 0; count < bookmarks.getOutlines().size(); count++) { - Outline out = (Outline)(bookmarks.getOutlines()).get(count); - data.addSubData(createBookmarkData(out)); - } - addTreeExtension(data); - data.setAreaTree(this); - } - - /** - * Create and return the bookmark data for this outline. - * This creates a bookmark data with the destination - * and adds all the data from child outlines. - * - * @param outline the Outline object for which a bookmark entry should be - * created - * @return the new bookmark data - */ - public BookmarkData createBookmarkData(Outline outline) { - BookmarkData data = new BookmarkData(outline.getInternalDestination()); - data.setLabel(outline.getLabel()); - for (int count = 0; count < outline.getOutlines().size(); count++) { - Outline out = (Outline)(outline.getOutlines()).get(count); - data.addSubData(createBookmarkData(out)); - } - return data; - } - -} diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java new file mode 100644 index 000000000..59972cc17 --- /dev/null +++ b/src/java/org/apache/fop/area/AreaTreeHandler.java @@ -0,0 +1,467 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ +package org.apache.fop.area; + +// Java +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.Set; +import java.util.HashSet; +import java.util.Iterator; + +// XML +import org.xml.sax.SAXException; + +// Apache +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.area.extensions.BookmarkData; +import org.apache.fop.fo.FOInputHandler; +import org.apache.fop.fo.extensions.Outline; +import org.apache.fop.fo.extensions.Bookmarks; +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.fonts.FontInfo; +import org.apache.fop.layoutmgr.AddLMVisitor; +import org.apache.fop.layoutmgr.ContentLayoutManager; +import org.apache.fop.layoutmgr.InlineStackingLayoutManager; +import org.apache.fop.layoutmgr.LMiter; +import org.apache.fop.layoutmgr.PageLayoutManager; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +// Java +import java.io.OutputStream; +import java.util.HashSet; +import java.util.Iterator; + +/** + * Area tree handler for formatting objects. + * + * Concepts: + * The area tree is to be as small as possible. With minimal classes + * and data to fully represent an area tree for formatting objects. + * The area tree needs to be simple to render and follow the spec + * closely. + * This area tree has the concept of page sequences. + * Where ever possible information is discarded or optimized to + * keep memory use low. The data is also organized to make it + * possible for renderers to minimize their output. + * A page can be saved if not fully resolved and once rendered + * a page contains only size and id reference information. + * The area tree pages are organized in a model that depends on the + * type of renderer. + */ +public class AreaTreeHandler extends FOInputHandler { + + // TODO: Collecting of statistics should be configurable + private final boolean collectStatistics = true; + private static final boolean MEM_PROFILE_WITH_GC = false; + private boolean pageSequenceFound = false; + + // for statistics gathering + private Runtime runtime; + + // heap memory allocated (for statistics) + private long initialMemory; + + // time used in rendering (for statistics) + private long startTime; + + // count of number of pages rendered + private int pageCount; + + /** Useful only for allowing subclasses of AddLMVisitor to be set by those + extending FOP **/ + private AddLMVisitor addLMVisitor = null; + + // AreaTreeModel in use + private AreaTreeModel model; + + // hashmap of arraylists containing pages with id area + private Map idLocations = new HashMap(); + + // list of id's yet to be resolved and arraylists of pages + private Map resolve = new HashMap(); + + private List treeExtensions = new ArrayList(); + + private static Log log = LogFactory.getLog(AreaTreeHandler.class); + + /** + * Constructor. + * @param userAgent FOUserAgent object for process + * @param renderType Desired fo.Constants output type (RENDER_PDF, + * RENDER_PS, etc.) + * @param stream OutputStream + */ + public AreaTreeHandler (FOUserAgent userAgent, int renderType, + OutputStream stream) throws FOPException { + super(userAgent); + + // model = new CachedRenderPagesModel(userAgent, renderType, + // fontInfo, stream); + model = new RenderPagesModel(userAgent, renderType, fontInfo, + stream); + + if (collectStatistics) { + runtime = Runtime.getRuntime(); + } + } + + /** + * Get the area tree model for this area tree. + * + * @return AreaTreeModel the model being used for this area tree + */ + public AreaTreeModel getAreaTreeModel() { + return model; + } + + /** + * Add a new page to the area tree. + * @param page the page to add + */ + public void addPage(PageViewport page) { + model.addPage(page); + } + + /** + * Add an id reference pointing to a page viewport. + * @param id the id of the reference + * @param pv the page viewport that contains the id reference + */ + public void addIDRef(String id, PageViewport pv) { + List list = (List)idLocations.get(id); + if (list == null) { + list = new ArrayList(); + idLocations.put(id, list); + } + list.add(pv); + + Set todo = (Set)resolve.get(id); + if (todo != null) { + for (Iterator iter = todo.iterator(); iter.hasNext();) { + Resolveable res = (Resolveable)iter.next(); + res.resolve(id, list); + } + resolve.remove(id); + } + } + + /** + * Get the list of id references for an id. + * @param id the id to lookup + * @return the list of id references. + */ + public List getIDReferences(String id) { + return (List)idLocations.get(id); + } + + /** + * Add an unresolved object with a given id. + * @param id the id reference that needs resolving + * @param res the Resolveable object to resolve + */ + public void addUnresolvedID(String id, Resolveable res) { + Set todo = (Set)resolve.get(id); + if (todo == null) { + todo = new HashSet(); + resolve.put(id, todo); + } + todo.add(res); + } + + /** + * Add a tree extension. + * This checks if the extension is resolveable and attempts + * to resolve or add the resolveable ids for later resolution. + * @param ext the tree extension to add. + */ + public void addTreeExtension(TreeExt ext) { + treeExtensions.add(ext); + if (ext.isResolveable()) { + Resolveable res = (Resolveable)ext; + String[] ids = res.getIDs(); + for (int count = 0; count < ids.length; count++) { + if (idLocations.containsKey(ids[count])) { + res.resolve(ids[count], (List)idLocations.get(ids[count])); + } else { + Set todo = (Set)resolve.get(ids[count]); + if (todo == null) { + todo = new HashSet(); + resolve.put(ids[count], todo); + } + todo.add(ext); + } + } + } else { + handleTreeExtension(ext, TreeExt.IMMEDIATELY); + } + } + + /** + * Handle a tree extension. + * This sends the extension to the model for handling. + * @param ext the tree extension to handle + * @param when when the extension should be handled by the model + */ + public void handleTreeExtension(TreeExt ext, int when) { + // queue tree extension according to the when + model.addExtension(ext, when); + } + + /** + * Prepare AreaTreeHandler for document processing + * This is called from FOTreeBuilder.startDocument() + * + * @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(); + } + } + + /** + * End the document. + * + * @throws SAXException if there is some error + */ + public void endDocument() throws SAXException { + if (pageSequenceFound == false) { + throw new SAXException("Error: No fo:page-sequence child " + + "found within fo:root element."); + } + + // deal with unresolved references + for (Iterator iter = resolve.keySet().iterator(); iter.hasNext();) { + String id = (String)iter.next(); + Set list = (Set)resolve.get(id); + for (Iterator resIter = list.iterator(); resIter.hasNext();) { + Resolveable res = (Resolveable)resIter.next(); + if (!res.isResolved()) { + res.resolve(id, null); + } + } + } + model.endDocument(); + + 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 (logger != null && logger.isDebugEnabled()) { + logger.debug("Initial heap size: " + (initialMemory / 1024L) + "Kb"); + logger.debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); + logger.debug("Total memory used: " + memoryUsed + "Kb"); + if (!MEM_PROFILE_WITH_GC) { + logger.debug(" Memory use is indicative; no GC was performed"); + logger.debug(" These figures should not be used comparatively"); + } + logger.debug("Total time used: " + timeUsed + "ms"); + logger.debug("Pages rendered: " + pageCount); + if (pageCount > 0) { + logger.debug("Avg render time: " + (timeUsed / pageCount) + "ms/page"); + } + } + } + } + + /** + * Create the bookmark data in the area tree. + */ + public void addBookmarks(Bookmarks bookmarks) { + if (bookmarks == null) { + return; + } + + log.debug("adding bookmarks to area tree"); + BookmarkData data = new BookmarkData(); + for (int count = 0; count < bookmarks.getOutlines().size(); count++) { + Outline out = (Outline)(bookmarks.getOutlines()).get(count); + data.addSubData(createBookmarkData(out)); + } + addTreeExtension(data); + data.setAreaTreeHandler(this); + } + + /** + * Create and return the bookmark data for this outline. + * This creates a bookmark data with the destination + * and adds all the data from child outlines. + * + * @param outline the Outline object for which a bookmark entry should be + * created + * @return the new bookmark data + */ + public BookmarkData createBookmarkData(Outline outline) { + BookmarkData data = new BookmarkData(outline.getInternalDestination()); + data.setLabel(outline.getLabel()); + for (int count = 0; count < outline.getOutlines().size(); count++) { + Outline out = (Outline)(outline.getOutlines()).get(count); + data.addSubData(createBookmarkData(out)); + } + return data; + } + + /** + * 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) { + pageSequenceFound = true; + } + + /** + * 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 (logger != null) { + logger.debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); + } + } + + addBookmarks(pageSequence.getRoot().getBookmarks()); + formatPageSequence(pageSequence); + } + + /** + * Runs the formatting of this page sequence into the given area tree + * + * @param pageSeq the PageSequence to be formatted + * @param areaTree the area tree to format this page sequence into + * @throws FOPException if there is an error formatting the contents + */ + private void formatPageSequence(PageSequence pageSeq) + throws FOPException { + Title title = null; + if (pageSeq.getTitleFO() != null) { + title = getTitleArea(pageSeq.getTitleFO()); + } + + model.startPageSequence(title); + + // Make a new PageLayoutManager and a FlowLayoutManager + // Run the PLM in a thread + // Wait for them to finish. + + // If no main flow, nothing to layout! + if (pageSeq.getMainFlow() == null) { + return; + } + + // Initialize if already used? + // this.layoutMasterSet.resetPageMasters(); + if (pageSeq.getPageSequenceMaster() != null) { + pageSeq.getPageSequenceMaster().reset(); + } + + pageSeq.initPageNumber(); + + // This will layout pages and add them to the area tree + PageLayoutManager pageLM = new PageLayoutManager(this, pageSeq); + pageLM.setPageCounting(pageSeq.getCurrentPageNumber(), + pageSeq.getPageNumberGenerator()); + + // For now, skip the threading and just call run directly. + pageLM.run(); + + // Thread layoutThread = new Thread(pageLM); + // layoutThread.start(); + // log.debug("Layout thread started"); + + // // wait on both managers + // try { + // layoutThread.join(); + // log.debug("Layout thread done"); + // } catch (InterruptedException ie) { + // log.error("PageSequence.format() interrupted waiting on layout"); + // } + + pageSeq.setCurrentPageNumber(pageLM.getPageCount()); + // Tell the root the last page number we created. + pageSeq.getRoot().setRunningPageNumberCounter(pageSeq.getCurrentPageNumber()); + } + + /** + * @return the Title area + */ + private org.apache.fop.area.Title getTitleArea(org.apache.fop.fo.pagination.Title foTitle) { + // use special layout manager to add the inline areas + // to the Title. + InlineStackingLayoutManager lm; + lm = new InlineStackingLayoutManager(foTitle); + lm.setLMiter(new LMiter(lm, foTitle.children.listIterator())); + lm.initialize(); + + // get breaks then add areas to title + org.apache.fop.area.Title title = + new org.apache.fop.area.Title(); + + ContentLayoutManager clm = new ContentLayoutManager(title); + clm.setUserAgent(foTitle.getUserAgent()); + lm.setParent(clm); + + clm.fillArea(lm); + + return title; + } + + /** + * Public accessor to get the AddLMVisitor object that should be used. + * @return the AddLMVisitor object that should be used. + */ + public AddLMVisitor getAddLMVisitor() { + if (this.addLMVisitor == null) { + this.addLMVisitor = new AddLMVisitor(); + } + return this.addLMVisitor; + } + +} diff --git a/src/java/org/apache/fop/area/extensions/BookmarkData.java b/src/java/org/apache/fop/area/extensions/BookmarkData.java index 28a15d975..4fa77565e 100644 --- a/src/java/org/apache/fop/area/extensions/BookmarkData.java +++ b/src/java/org/apache/fop/area/extensions/BookmarkData.java @@ -21,7 +21,7 @@ package org.apache.fop.area.extensions; import org.apache.fop.area.PageViewport; import org.apache.fop.area.Resolveable; import org.apache.fop.area.TreeExt; -import org.apache.fop.area.AreaTree; +import org.apache.fop.area.AreaTreeHandler; import java.util.ArrayList; import java.util.List; @@ -36,8 +36,8 @@ public class BookmarkData implements Resolveable, TreeExt { private ArrayList subData = new ArrayList(); private HashMap idRefs = new HashMap(); - // area tree for the top level object to notify when resolved - private AreaTree areaTree = null; + // area tree handler for the top level object to notify when resolved + private AreaTreeHandler areaTreeHandler = null; private String idRef; private PageViewport pageRef = null; @@ -69,10 +69,10 @@ public class BookmarkData implements Resolveable, TreeExt { * This should only be called for the top level element. * The area tree is used once resolving is complete. * - * @param at the area tree for the current document + * @param at the area tree handler for the current document */ - public void setAreaTree(AreaTree at) { - areaTree = at; + public void setAreaTreeHandler(AreaTreeHandler ath) { + areaTreeHandler = ath; } /** @@ -229,8 +229,8 @@ public class BookmarkData implements Resolveable, TreeExt { private void checkFinish() { if (idRefs.size() == 0) { idRefs = null; - if (areaTree != null) { - areaTree.handleTreeExtension(this, TreeExt.AFTER_PAGE); + if (areaTreeHandler != null) { + areaTreeHandler.handleTreeExtension(this, TreeExt.AFTER_PAGE); } } } diff --git a/src/java/org/apache/fop/fo/FOInputHandler.java b/src/java/org/apache/fop/fo/FOInputHandler.java index 1f3e81b34..629eaea06 100644 --- a/src/java/org/apache/fop/fo/FOInputHandler.java +++ b/src/java/org/apache/fop/fo/FOInputHandler.java @@ -26,7 +26,6 @@ import org.xml.sax.SAXException; // Apache import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FOPException; -import org.apache.fop.area.AreaTree; import org.apache.fop.fo.flow.BasicLink; import org.apache.fop.fo.flow.Block; import org.apache.fop.fo.flow.ExternalGraphic; @@ -127,38 +126,44 @@ public abstract class FOInputHandler { * 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; + public 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; + public void endDocument() throws SAXException { + } /** * * @param pageSeq PageSequence that is starting. */ - public abstract void startPageSequence(PageSequence pageSeq); + public void startPageSequence(PageSequence pageSeq) { + } /** * * @param pageSeq PageSequence that is ending. * @throws FOPException For errors encountered. */ - public abstract void endPageSequence(PageSequence pageSeq) throws FOPException; + public void endPageSequence(PageSequence pageSeq) throws FOPException { + } /** * * @param pagenum PageNumber that is starting. */ - public abstract void startPageNumber(PageNumber pagenum); + public void startPageNumber(PageNumber pagenum) { + } /** * * @param pagenum PageNumber that is ending. */ - public abstract void endPageNumber(PageNumber pagenum); + public void endPageNumber(PageNumber pagenum) { + } /** * This method is called to indicate the start of a new fo:flow or fo:static-content. @@ -167,122 +172,142 @@ public abstract class FOInputHandler { * * @param fl Flow that is starting. */ - public abstract void startFlow(Flow fl); + public void startFlow(Flow fl) { + } /** * * @param fl Flow that is ending. */ - public abstract void endFlow(Flow fl); + public void endFlow(Flow fl) { + } /** * * @param bl Block that is starting. */ - public abstract void startBlock(Block bl); + public void startBlock(Block bl) { + } /** * * @param bl Block that is ending. */ - public abstract void endBlock(Block bl); + public void endBlock(Block bl) { + } /** * * @param inl Inline that is starting. */ - public abstract void startInline(Inline inl); + public void startInline(Inline inl) { + } /** * * @param inl Inline that is ending. */ - public abstract void endInline(Inline inl); + public void endInline(Inline inl) { + } // Tables /** * * @param tbl Table that is starting. */ - public abstract void startTable(Table tbl); + public void startTable(Table tbl) { + } /** * * @param tbl Table that is ending. */ - public abstract void endTable(Table tbl); + public void endTable(Table tbl) { + } /** * * @param tc TableColumn that is starting; */ - public abstract void startColumn(TableColumn tc); + public void startColumn(TableColumn tc) { + } /** * * @param tc TableColumn that is ending; */ - public abstract void endColumn(TableColumn tc); + public void endColumn(TableColumn tc) { + } /** * * @param th TableBody that is starting; */ - public abstract void startHeader(TableBody th); + public void startHeader(TableBody th) { + } /** * * @param th TableBody that is ending. */ - public abstract void endHeader(TableBody th); + public void endHeader(TableBody th) { + } /** * * @param tf TableFooter that is starting. */ - public abstract void startFooter(TableBody tf); + public void startFooter(TableBody tf) { + } /** * * @param tf TableFooter that is ending. */ - public abstract void endFooter(TableBody tf); + public void endFooter(TableBody tf) { + } /** * * @param tb TableBody that is starting. */ - public abstract void startBody(TableBody tb); + public void startBody(TableBody tb) { + } /** * * @param tb TableBody that is ending. */ - public abstract void endBody(TableBody tb); + public void endBody(TableBody tb) { + } /** * * @param tr TableRow that is starting. */ - public abstract void startRow(TableRow tr); + public void startRow(TableRow tr) { + } /** * * @param tr TableRow that is ending. */ - public abstract void endRow(TableRow tr); + public void endRow(TableRow tr) { + } /** * * @param tc TableCell that is starting. */ - public abstract void startCell(TableCell tc); + public void startCell(TableCell tc) { + } /** * * @param tc TableCell that is ending. */ - public abstract void endCell(TableCell tc); + public void endCell(TableCell tc) { + } // Lists @@ -290,124 +315,147 @@ public abstract class FOInputHandler { * * @param lb ListBlock that is starting. */ - public abstract void startList(ListBlock lb); + public void startList(ListBlock lb) { + } /** * * @param lb ListBlock that is ending. */ - public abstract void endList(ListBlock lb); + public void endList(ListBlock lb) { + } /** * * @param li ListItem that is starting. */ - public abstract void startListItem(ListItem li); + public void startListItem(ListItem li) { + } /** * * @param li ListItem that is ending. */ - public abstract void endListItem(ListItem li); + public void endListItem(ListItem li) { + } /** * Process start of a ListLabel. */ - public abstract void startListLabel(); + public void startListLabel() { + } /** * Process end of a ListLabel. */ - public abstract void endListLabel(); + public void endListLabel() { + } /** * Process start of a ListBody. */ - public abstract void startListBody(); + public void startListBody() { + } /** * Process end of a ListBody. */ - public abstract void endListBody(); + public void endListBody() { + } // Static Regions /** * Process start of a Static. */ - public abstract void startStatic(); + public void startStatic() { + } /** * Process end of a Static. */ - public abstract void endStatic(); + public void endStatic() { + } + /** * Process start of a Markup. */ - public abstract void startMarkup(); + public void startMarkup() { + } /** * Process end of a Markup. */ - public abstract void endMarkup(); + public void endMarkup() { + } /** * Process start of a Link. * @param basicLink BasicLink that is ending */ - public abstract void startLink(BasicLink basicLink); + public void startLink(BasicLink basicLink) { + } /** * Process end of a Link. */ - public abstract void endLink(); + public void endLink() { + } /** * Process an ExternalGraphic. * @param eg ExternalGraphic to process. */ - public abstract void image(ExternalGraphic eg); + public void image(ExternalGraphic eg) { + } /** * Process a pageRef. */ - public abstract void pageRef(); + public void pageRef() { + } /** * Process an InstreamForeignObject. * @param ifo InstreamForeignObject to process. */ - public abstract void foreignObject(InstreamForeignObject ifo); + public void foreignObject(InstreamForeignObject ifo) { + } /** * Process the start of a footnote. * @param footnote Footnote that is starting */ - public abstract void startFootnote(Footnote footnote); + public void startFootnote(Footnote footnote) { + } /** * Process the ending of a footnote. * @param footnote Footnote that is ending */ - public abstract void endFootnote(Footnote footnote); + public void endFootnote(Footnote footnote) { + } /** * Process the start of a footnote body. * @param body FootnoteBody that is starting */ - public abstract void startFootnoteBody(FootnoteBody body); + public void startFootnoteBody(FootnoteBody body) { + } /** * Process the ending of a footnote body. * @param body FootnoteBody that is ending */ - public abstract void endFootnoteBody(FootnoteBody body); + public void endFootnoteBody(FootnoteBody body) { + } /** * Process a Leader. * @param l Leader to process. */ - public abstract void leader(Leader l); + public void leader(Leader l) { + } /** * Process character data. @@ -415,7 +463,8 @@ public abstract class FOInputHandler { * @param start Offset for characters to process. * @param length Portion of array to process. */ - public abstract void characters(char data[], int start, int length); + public void characters(char data[], int start, int length) { + } } diff --git a/src/java/org/apache/fop/fo/FOTreeHandler.java b/src/java/org/apache/fop/fo/FOTreeHandler.java deleted file mode 100644 index c8b0449be..000000000 --- a/src/java/org/apache/fop/fo/FOTreeHandler.java +++ /dev/null @@ -1,598 +0,0 @@ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.fo; - -// Java -import java.io.OutputStream; -import java.util.HashSet; -import java.util.Iterator; - -// SAX -import org.xml.sax.SAXException; - -// FOP -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.apps.FOPException; -import org.apache.fop.area.AreaTree; -import org.apache.fop.area.Title; -import org.apache.fop.fo.extensions.Bookmarks; -import org.apache.fop.fo.flow.BasicLink; -import org.apache.fop.fo.flow.Block; -import org.apache.fop.fo.flow.ExternalGraphic; -import org.apache.fop.fo.flow.Footnote; -import org.apache.fop.fo.flow.FootnoteBody; -import org.apache.fop.fo.flow.InstreamForeignObject; -import org.apache.fop.fo.flow.Inline; -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.PageNumber; -import org.apache.fop.fo.flow.Table; -import org.apache.fop.fo.flow.TableColumn; -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.Flow; -import org.apache.fop.fo.pagination.PageSequence; -import org.apache.fop.layoutmgr.AddLMVisitor; -import org.apache.fop.layoutmgr.ContentLayoutManager; -import org.apache.fop.layoutmgr.InlineStackingLayoutManager; -import org.apache.fop.layoutmgr.LMiter; -import org.apache.fop.layoutmgr.PageLayoutManager; - - -/** - * Defines how SAX events specific to XSL-FO input should be handled when - * an FO Tree needs to be built. - * This initiates layout processes and corresponding - * rendering processes such as start/end. - * @see FOInputHandler - */ -public class FOTreeHandler extends FOInputHandler { - - // TODO: Collecting of statistics should be configurable - private final boolean collectStatistics = true; - private static final boolean MEM_PROFILE_WITH_GC = false; - private boolean pageSequenceFound = false; - - /** - * Somewhere to get our stats from. - */ - private Runtime runtime; - - /** The current AreaTree for the FOTreeHandler. */ - public AreaTree areaTree; - - /** - * 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 in rendering - */ - private long startTime; - - /** Useful only for allowing subclasses of AddLMVisitor to be set by those - extending FOP **/ - private AddLMVisitor addLMVisitor = null; - - /** - * Main constructor - * @param userAgent the apps.userAgent implementation that governs - * this FO Tree - * @param renderType the fo.Constants value indicating desired - * output type (RENDER_PDF, RENDER_PS, etc.) - * @param OutputStream stream to use to output results of rendering - * - */ - public FOTreeHandler(FOUserAgent userAgent, int renderType, - OutputStream stream) throws FOPException { - super(userAgent); - - areaTree = new AreaTree(userAgent, renderType, fontInfo, stream); - - if (collectStatistics) { - runtime = Runtime.getRuntime(); - } - } - - /** - * Prepare FOTreeHandler for FO Tree building. - * This is called from FOTreeBuilder.startDocument() - * - * @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(); - } - } - - /** - * End the document. - * - * @throws SAXException if there is some error - */ - public void endDocument() throws SAXException { - - if (pageSequenceFound == false) { - throw new SAXException("Error: No fo:page-sequence child " + - "found within fo:root element."); - } - - areaTree.endDocument(); - - 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 (logger != null && logger.isDebugEnabled()) { - logger.debug("Initial heap size: " + (initialMemory / 1024L) + "Kb"); - logger.debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); - logger.debug("Total memory used: " + memoryUsed + "Kb"); - if (!MEM_PROFILE_WITH_GC) { - logger.debug(" Memory use is indicative; no GC was performed"); - logger.debug(" These figures should not be used comparatively"); - } - logger.debug("Total time used: " + timeUsed + "ms"); - logger.debug("Pages rendered: " + pageCount); - if (pageCount > 0) { - logger.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) { - pageSequenceFound = true; - } - - /** - * 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 (logger != null) { - logger.debug("Current heap size: " + (memoryNow / 1024L) + "Kb"); - } - } - - areaTree.addBookmarksToAreaTree(pageSequence.getRoot().getBookmarks()); - formatPageSequence(pageSequence, areaTree); - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startFlow(Flow) - */ - public void startFlow(Flow fl) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endFlow(Flow) - */ - public void endFlow(Flow fl) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startBlock(Block) - */ - public void startBlock(Block bl) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endBlock(Block) - */ - public void endBlock(Block bl) { - } - - /** - * - * @param inl Inline that is starting. - */ - public void startInline(Inline inl){ - } - - /** - * - * @param inl Inline that is ending. - */ - public void endInline(Inline inl){ - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startTable(Table) - */ - public void startTable(Table tbl) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endTable(Table) - */ - public void endTable(Table tbl) { - } - - /** - * - * @param tc TableColumn that is starting; - */ - public void startColumn(TableColumn tc) { - } - - /** - * - * @param tc TableColumn that is ending; - */ - public void endColumn(TableColumn tc) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startHeader(TableBody) - */ - public void startHeader(TableBody th) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endHeader(TableBody) - */ - public void endHeader(TableBody th) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startFooter(TableBody) - */ - public void startFooter(TableBody tf) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endFooter(TableBody) - */ - public void endFooter(TableBody tf) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startBody(TableBody) - */ - public void startBody(TableBody tb) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endBody(TableBody) - */ - public void endBody(TableBody tb) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startRow(TableRow) - */ - public void startRow(TableRow tr) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endRow(TableRow) - */ - public void endRow(TableRow tr) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startCell(TableCell) - */ - public void startCell(TableCell tc) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endCell(TableCell) - */ - public void endCell(TableCell tc) { - } - - // Lists - /** - * @see org.apache.fop.fo.FOInputHandler#startList(ListBlock) - */ - public void startList(ListBlock lb) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endList(ListBlock) - */ - public void endList(ListBlock lb) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startListItem(ListItem) - */ - public void startListItem(ListItem li) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endListItem(ListItem) - */ - public void endListItem(ListItem li) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startListLabel() - */ - public void startListLabel() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endListLabel() - */ - public void endListLabel() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startListBody() - */ - public void startListBody() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endListBody() - */ - public void endListBody() { - } - - // Static Regions - /** - * @see org.apache.fop.fo.FOInputHandler#startStatic() - */ - public void startStatic() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endStatic() - */ - public void endStatic() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startMarkup() - */ - public void startMarkup() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endMarkup() - */ - public void endMarkup() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startLink(BasicLink basicLink) - */ - public void startLink(BasicLink basicLink) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endLink() - */ - public void endLink() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#image(ExternalGraphic) - */ - public void image(ExternalGraphic eg) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#pageRef() - */ - public void pageRef() { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#foreignObject(InstreamForeignObject) - */ - public void foreignObject(InstreamForeignObject ifo) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startFootnote(Footnote) - */ - public void startFootnote(Footnote footnote) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endFootnote(Footnote) - */ - public void endFootnote(Footnote footnote) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#startFootnoteBody(FootnoteBody) - */ - public void startFootnoteBody(FootnoteBody body) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#endFootnoteBody(FootnoteBody) - */ - public void endFootnoteBody(FootnoteBody body) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#leader(Leader) - */ - public void leader(Leader l) { - } - - /** - * @see org.apache.fop.fo.FOInputHandler#characters(char[], int, int) - */ - public void characters(char[] data, int start, int length) { - } - - /** - * Runs the formatting of this page sequence into the given area tree - * - * @param pageSeq the PageSequence to be formatted - * @param areaTree the area tree to format this page sequence into - * @throws FOPException if there is an error formatting the contents - */ - private void formatPageSequence(PageSequence pageSeq, AreaTree areaTree) - throws FOPException { - Title title = null; - if (pageSeq.getTitleFO() != null) { - title = getTitleArea(pageSeq.getTitleFO()); - } - areaTree.startPageSequence(title); - // Make a new PageLayoutManager and a FlowLayoutManager - // Run the PLM in a thread - // Wait for them to finish. - - // If no main flow, nothing to layout! - if (pageSeq.getMainFlow() == null) { - return; - } - - // Initialize if already used? - // this.layoutMasterSet.resetPageMasters(); - if (pageSeq.getPageSequenceMaster() != null) { - pageSeq.getPageSequenceMaster().reset(); - } - - pageSeq.initPageNumber(); - - // This will layout pages and add them to the area tree - PageLayoutManager pageLM = new PageLayoutManager(areaTree, pageSeq, - this); - pageLM.setPageCounting(pageSeq.getCurrentPageNumber(), - pageSeq.getPageNumberGenerator()); - - // For now, skip the threading and just call run directly. - pageLM.run(); - - // Thread layoutThread = new Thread(pageLM); - // layoutThread.start(); - // log.debug("Layout thread started"); - - // // wait on both managers - // try { - // layoutThread.join(); - // log.debug("Layout thread done"); - // } catch (InterruptedException ie) { - // log.error("PageSequence.format() interrupted waiting on layout"); - // } - - pageSeq.setCurrentPageNumber(pageLM.getPageCount()); - // Tell the root the last page number we created. - pageSeq.getRoot().setRunningPageNumberCounter(pageSeq.getCurrentPageNumber()); - } - - /** - * @return the Title area - */ - private org.apache.fop.area.Title getTitleArea(org.apache.fop.fo.pagination.Title foTitle) { - // use special layout manager to add the inline areas - // to the Title. - InlineStackingLayoutManager lm; - lm = new InlineStackingLayoutManager(foTitle); - lm.setLMiter(new LMiter(lm, foTitle.children.listIterator())); - lm.initialize(); - - // get breaks then add areas to title - org.apache.fop.area.Title title = - new org.apache.fop.area.Title(); - - ContentLayoutManager clm = new ContentLayoutManager(title); - clm.setUserAgent(foTitle.getUserAgent()); - lm.setParent(clm); - - clm.fillArea(lm); - - return title; - } - - /** - * Public accessor to set the AddLMVisitor object that should be used. - * This allows subclasses of AddLMVisitor to be used, which can be useful - * for extensions to the FO Tree. - * @param addLMVisitor the AddLMVisitor object that should be used. - */ - public void setAddLMVisitor(AddLMVisitor addLMVisitor) { - this.addLMVisitor = addLMVisitor; - } - - /** - * Public accessor to get the AddLMVisitor object that should be used. - * @return the AddLMVisitor object that should be used. - */ - public AddLMVisitor getAddLMVisitor() { - if (this.addLMVisitor == null) { - this.addLMVisitor = new AddLMVisitor(); - } - return this.addLMVisitor; - } - - /** - * - * @param pagenum PageNumber that is starting. - */ - public void startPageNumber(PageNumber pagenum) { - } - - /** - * - * @param pagenum PageNumber that is ending. - */ - public void endPageNumber(PageNumber pagenum) { - } - -} diff --git a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java index 575c2df8c..468b5bbf9 100644 --- a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -21,11 +21,11 @@ package org.apache.fop.layoutmgr; import org.apache.fop.fo.FObj; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.area.Area; +import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.area.Resolveable; import org.apache.fop.area.PageViewport; import org.apache.fop.fo.Constants; import org.apache.fop.fo.flow.Marker; -import org.apache.fop.fo.FOTreeHandler; import org.apache.fop.fo.PropertyManager; import org.apache.commons.logging.Log; @@ -108,8 +108,8 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants return this.parentLM; } - public FOTreeHandler getFOTreeHandler() { - return getParent().getFOTreeHandler(); + public AreaTreeHandler getAreaTreeHandler() { + return getParent().getAreaTreeHandler(); } // /** diff --git a/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java index bad20c2fe..73e023be0 100644 --- a/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java @@ -19,10 +19,10 @@ package org.apache.fop.layoutmgr; import org.apache.fop.fo.FObj; -import org.apache.fop.fo.FOTreeHandler; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fo.flow.Marker; import org.apache.fop.area.Area; +import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.area.Resolveable; import org.apache.fop.area.PageViewport; @@ -171,8 +171,8 @@ public class ContentLayoutManager implements LayoutManager { return this.parentLM; } - public FOTreeHandler getFOTreeHandler() { - return getParent().getFOTreeHandler(); + public AreaTreeHandler getAreaTreeHandler() { + return getParent().getAreaTreeHandler(); } /** @see org.apache.fop.layoutmgr.LayoutManager */ diff --git a/src/java/org/apache/fop/layoutmgr/LMiter.java b/src/java/org/apache/fop/layoutmgr/LMiter.java index 6243faf41..e7d64719d 100644 --- a/src/java/org/apache/fop/layoutmgr/LMiter.java +++ b/src/java/org/apache/fop/layoutmgr/LMiter.java @@ -46,7 +46,7 @@ public class LMiter implements ListIterator { } protected boolean preLoadNext() { - AddLMVisitor addLMVisitor = lp.getFOTreeHandler().getAddLMVisitor(); + AddLMVisitor addLMVisitor = lp.getAreaTreeHandler().getAddLMVisitor(); // skip over child FObj's that don't add lms while (baseIter != null && baseIter.hasNext()) { Object theobj = baseIter.next(); diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManager.java b/src/java/org/apache/fop/layoutmgr/LayoutManager.java index f11491067..1ab43ed28 100644 --- a/src/java/org/apache/fop/layoutmgr/LayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/LayoutManager.java @@ -27,7 +27,7 @@ import org.apache.fop.area.Resolveable; import org.apache.fop.area.PageViewport; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fo.FObj; -import org.apache.fop.fo.FOTreeHandler; +import org.apache.fop.area.AreaTreeHandler; /** * The interface for all LayoutManagers. @@ -58,10 +58,10 @@ public interface LayoutManager { LayoutManager getParent(); /** - * Get the FOTreeHandler object that is activating the LM Tree - * @return the FOTreeHandler object + * Get the AreaTreeHandler object that is activating the LM Tree + * @return the AreaTreeHandler object */ - FOTreeHandler getFOTreeHandler(); + AreaTreeHandler getAreaTreeHandler(); /** * Initialize this layout manager. diff --git a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java index 2bd133353..5397b57dd 100644 --- a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -21,7 +21,7 @@ package org.apache.fop.layoutmgr; import org.apache.fop.apps.FOPException; import org.apache.fop.area.CTM; -import org.apache.fop.area.AreaTree; +import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.area.AreaTreeModel; import org.apache.fop.area.Area; import org.apache.fop.area.PageViewport; @@ -41,7 +41,6 @@ import org.apache.fop.datatypes.PercentBase; import org.apache.fop.datatypes.FODimension; import org.apache.fop.fo.FObj; -import org.apache.fop.fo.FOTreeHandler; import org.apache.fop.fo.Constants; import org.apache.fop.fo.flow.Marker; import org.apache.fop.fo.pagination.PageNumberGenerator; @@ -108,9 +107,8 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable * laid out and ready for rendering, except for resolution of ID * references? */ - private AreaTree areaTree; + private AreaTreeHandler areaTreeHandler; private PageSequence pageSequence; - private FOTreeHandler foTreeHandler; /** * This is the SimplePageMaster that should be used to create the page. It @@ -133,12 +131,10 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable * @param areaTree the area tree to add pages to * @param pageseq the page sequence fo */ - public PageLayoutManager(AreaTree areaTree, PageSequence pageseq, - FOTreeHandler foTreeHandler) { + public PageLayoutManager(AreaTreeHandler areaTreeHandler, PageSequence pageseq) { super(pageseq); - this.areaTree = areaTree; + this.areaTreeHandler = areaTreeHandler; pageSequence = pageseq; - this.foTreeHandler = foTreeHandler; } /** @@ -262,7 +258,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable * @return the first page viewport that contains the reference */ public PageViewport resolveRefID(String ref) { - List list = areaTree.getIDReferences(ref); + List list = areaTreeHandler.getIDReferences(ref); if (list != null && list.size() > 0) { return (PageViewport)list.get(0); } @@ -292,7 +288,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable * @param id the ID reference to add */ public void addIDToPage(String id) { - areaTree.addIDRef(id, curPage); + areaTreeHandler.addIDRef(id, curPage); } /** @@ -310,7 +306,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable // add unresolved to tree // adds to the page viewport so it can serialize curPage.addUnresolvedID(id, res); - areaTree.addUnresolvedID(id, curPage); + areaTreeHandler.addUnresolvedID(id, curPage); } /** @@ -345,7 +341,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable // go back over pages until mark found // if document boundary then keep going boolean doc = boundary == RetrieveBoundary.DOCUMENT; - AreaTreeModel atm = areaTree.getAreaTreeModel(); + AreaTreeModel atm = areaTreeHandler.getAreaTreeModel(); int seq = atm.getPageSequenceCount(); int page = atm.getPageCount(seq) - 1; while (page >= 0) { @@ -503,7 +499,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable layoutStaticContent(currentSimplePageMaster.getRegion(Region.END_CODE), Region.END_CODE); // Queue for ID resolution and rendering - areaTree.addPage(curPage); + areaTreeHandler.addPage(curPage); curPage = null; curBody = null; curSpan = null; @@ -903,7 +899,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable /** * @return the apps.FOTreeHandler object controlling this generation */ - public FOTreeHandler getFOTreeHandler() { - return foTreeHandler; + public AreaTreeHandler getAreaTreeHandler() { + return areaTreeHandler; } }