From ea3eecb3912a99ded8f3de76bf2e15cc2f4e58cf Mon Sep 17 00:00:00 2001 From: William Victor Mote Date: Wed, 20 Aug 2003 17:25:44 +0000 Subject: [PATCH] move startup of laying out a PageSequence from PageSequence.format() and Document.foPageSequenceComplete to the LayoutStrategy implementation (layoutmgr/LayoutManagerLS) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196815 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/control/Document.java | 14 ++-- .../fop/fo/pagination/PageSequence.java | 72 ++++++------------- .../org/apache/fop/fo/pagination/Root.java | 2 +- .../org/apache/fop/layout/LayoutStrategy.java | 6 ++ .../apache/fop/layoutmgr/LayoutManagerLS.java | 60 ++++++++++++++++ 5 files changed, 91 insertions(+), 63 deletions(-) diff --git a/src/java/org/apache/fop/control/Document.java b/src/java/org/apache/fop/control/Document.java index 279dc49b3..f30bde00d 100644 --- a/src/java/org/apache/fop/control/Document.java +++ b/src/java/org/apache/fop/control/Document.java @@ -63,7 +63,6 @@ import org.apache.fop.fo.FOTreeControl; import org.apache.fop.fo.FOTreeEvent; import org.apache.fop.fo.FOTreeListener; import org.apache.fop.fo.pagination.PageSequence; -import org.apache.fop.area.Title; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontMetrics; import org.apache.fop.layout.LayoutStrategy; @@ -94,7 +93,7 @@ public class Document implements FOTreeControl, FOTreeListener { * TODO: this actually belongs in the RenderContext class, when it is * created */ - private LayoutStrategy ls = null; + private LayoutStrategy layoutStrategy = null; /** * The current AreaTree for the PageSequence being rendered. @@ -294,14 +293,14 @@ public class Document implements FOTreeControl, FOTreeListener { * @param ls the LayoutStrategy object to be used to process this Document */ public void setLayoutStrategy(LayoutStrategy ls) { - this.ls = ls; + this.layoutStrategy = ls; } /** * @return this Document's LayoutStrategy object */ public LayoutStrategy getLayoutStrategy () { - return ls; + return layoutStrategy; } public Driver getDriver() { @@ -316,12 +315,7 @@ public class Document implements FOTreeControl, FOTreeListener { */ public void foPageSequenceComplete (FOTreeEvent event) throws FOPException { PageSequence pageSeq = event.getPageSequence(); - Title title = null; - if (pageSeq.getTitleFO() != null) { - title = pageSeq.getTitleFO().getTitleArea(); - } - areaTree.startPageSequence(title); - pageSeq.format(areaTree); + layoutStrategy.format(pageSeq, areaTree); } /** diff --git a/src/java/org/apache/fop/fo/pagination/PageSequence.java b/src/java/org/apache/fop/fo/pagination/PageSequence.java index 8ee2a86c5..6de86c768 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequence.java @@ -357,60 +357,10 @@ public class PageSequence extends FObj { } } - /** - * Runs the formatting of this page sequence into the given area tree - * - * @param areaTree the area tree to format this page sequence into - * @throws FOPException if there is an error formatting the contents - */ - public void format(AreaTree areaTree) throws FOPException { - // 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 (this.mainFlow == null) { - return; - } - - // Initialize if already used? - // this.layoutMasterSet.resetPageMasters(); - if (pageSequenceMaster != null) { - pageSequenceMaster.reset(); - } - - int firstAvailPageNumber = 0; - initPageNumber(); - - // This will layout pages and add them to the area tree - PageLayoutManager pageLM = new PageLayoutManager(areaTree, this); - pageLM.setUserAgent(getUserAgent()); - pageLM.setFObj(this); - pageLM.setPageCounting(currentPageNumber, pageNumberGenerator); - - // 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"); -// } - this.currentPageNumber = pageLM.getPageCount(); - // Tell the root the last page number we created. - this.root.setRunningPageNumberCounter(this.currentPageNumber); - } - /** * Initialize the current page number for the start of the page sequence. */ - private void initPageNumber() { + public void initPageNumber() { this.currentPageNumber = this.root.getRunningPageNumberCounter() + 1; if (this.pageNumberType == AUTO_ODD) { @@ -826,5 +776,23 @@ public class PageSequence extends FObj { fotv.serveVisitor(this); } -} + public Flow getMainFlow() { + return mainFlow; + } + + public PageSequenceMaster getPageSequenceMaster() { + return pageSequenceMaster; + } + + public PageNumberGenerator getPageNumberGenerator() { + return pageNumberGenerator; + } + public void setCurrentPageNumber(int currentPageNumber) { + this.currentPageNumber = currentPageNumber; + } + + public Root getRoot() { + return root; + } +} diff --git a/src/java/org/apache/fop/fo/pagination/Root.java b/src/java/org/apache/fop/fo/pagination/Root.java index 139cbd414..415c3de4e 100644 --- a/src/java/org/apache/fop/fo/pagination/Root.java +++ b/src/java/org/apache/fop/fo/pagination/Root.java @@ -97,7 +97,7 @@ public class Root extends FObj { * Sets the overall page number counter. * @param count the new page count */ - protected void setRunningPageNumberCounter(int count) { + public void setRunningPageNumberCounter(int count) { this.runningPageNumberCounter = count; } diff --git a/src/java/org/apache/fop/layout/LayoutStrategy.java b/src/java/org/apache/fop/layout/LayoutStrategy.java index 1d31cd300..aa522a3a8 100644 --- a/src/java/org/apache/fop/layout/LayoutStrategy.java +++ b/src/java/org/apache/fop/layout/LayoutStrategy.java @@ -51,6 +51,10 @@ package org.apache.fop.layout; +import org.apache.fop.apps.FOPException; +import org.apache.fop.area.AreaTree; +import org.apache.fop.fo.pagination.PageSequence; + /** * Abstract class defining the highest-level information for a layout strategy. * Subclasses implement a layout strategy that converts an FO Tree into an @@ -68,4 +72,6 @@ public abstract class LayoutStrategy { return name; } + public abstract void format (PageSequence pageSeq, AreaTree areaTree) + throws FOPException; } diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManagerLS.java b/src/java/org/apache/fop/layoutmgr/LayoutManagerLS.java index 9f177a4c5..9b59bab88 100644 --- a/src/java/org/apache/fop/layoutmgr/LayoutManagerLS.java +++ b/src/java/org/apache/fop/layoutmgr/LayoutManagerLS.java @@ -50,7 +50,11 @@ */ package org.apache.fop.layoutmgr; +import org.apache.fop.apps.FOPException; import org.apache.fop.layout.LayoutStrategy; +import org.apache.fop.area.AreaTree; +import org.apache.fop.area.Title; +import org.apache.fop.fo.pagination.PageSequence; /** * The implementation of LayoutStrategy for the "redesign" or second generation @@ -60,4 +64,60 @@ public class LayoutManagerLS extends LayoutStrategy { private static String name = "layoutmgr"; + /** + * Runs the formatting of this page sequence into the given area tree + * + * @param areaTree the area tree to format this page sequence into + * @throws FOPException if there is an error formatting the contents + */ + public void format(PageSequence pageSeq, AreaTree areaTree) throws FOPException { + Title title = null; + if (pageSeq.getTitleFO() != null) { + title = pageSeq.getTitleFO().getTitleArea(); + } + 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(); + } + + int firstAvailPageNumber = 0; + pageSeq.initPageNumber(); + + // This will layout pages and add them to the area tree + PageLayoutManager pageLM = new PageLayoutManager(areaTree, pageSeq); + pageLM.setUserAgent(pageSeq.getUserAgent()); + pageLM.setFObj(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()); + } + } -- 2.39.5