diff options
author | Glen Mazza <gmazza@apache.org> | 2004-09-26 13:51:01 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-09-26 13:51:01 +0000 |
commit | 5e243adb550e11cf9d8c55c4d9c93cb68c6a9b97 (patch) | |
tree | 7f23e7a71ebdbb31bb859b7a4888c9fd47600843 | |
parent | 115af1f4e90475c45f3cfdaaa3fa382eb6c15c87 (diff) | |
download | xmlgraphics-fop-5e243adb550e11cf9d8c55c4d9c93cb68c6a9b97.tar.gz xmlgraphics-fop-5e243adb550e11cf9d8c55c4d9c93cb68c6a9b97.zip |
PR:
Obtained from:
Submitted by:
Reviewed by:
1.) Renamed PageLayoutManager to somewhat more intuitive PageSequenceLayoutManager.
2.) Moved layout logic for the fo:title of an fo:page-sequence from AreaTreeHandler
to PSLM. Also moved page number initialization logic there.
Comments most welcome.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197976 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/java/org/apache/fop/area/AreaTreeHandler.java | 103 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/pagination/PageSequence.java | 3 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java | 45 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java | 2 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java (renamed from src/java/org/apache/fop/layoutmgr/PageLayoutManager.java) | 64 | ||||
-rw-r--r-- | src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java | 2 |
6 files changed, 93 insertions, 126 deletions
diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java index 4ef9e0272..aac70908b 100644 --- a/src/java/org/apache/fop/area/AreaTreeHandler.java +++ b/src/java/org/apache/fop/area/AreaTreeHandler.java @@ -39,10 +39,7 @@ import org.apache.fop.fo.FObj; 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.fo.pagination.Title; -import org.apache.fop.layoutmgr.ContentLayoutManager; -import org.apache.fop.layoutmgr.InlineStackingLayoutManager; -import org.apache.fop.layoutmgr.PageLayoutManager; +import org.apache.fop.layoutmgr.PageSequenceLayoutManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -129,14 +126,6 @@ public class AreaTreeHandler extends FOEventHandler { } /** - * 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 @@ -343,10 +332,8 @@ public class AreaTreeHandler extends FOEventHandler { * 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) { - //areaTree.setFontInfo(fontInfo); if (collectStatistics) { if (MEM_PROFILE_WITH_GC) { @@ -359,88 +346,32 @@ public class AreaTreeHandler extends FOEventHandler { } } - addBookmarks(pageSequence.getRoot().getBookmarks()); - formatPageSequence(pageSequence); + // If no main flow, nothing to layout! + if (pageSequence.getMainFlow() != null) { + addBookmarks(pageSequence.getRoot().getBookmarks()); + PageSequenceLayoutManager pageSLM + = new PageSequenceLayoutManager(this, pageSequence); + pageSLM.run(); + pageSequence.setCurrentPageNumber(pageSLM.getPageCount()); + } } /** - * 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 + * Add a new page to the area tree. + * @param page the page to add */ - private void formatPageSequence(PageSequence pageSeq) { - LineArea title = null; - if (pageSeq.getTitleFO() != null) { - title = getTitleArea(pageSeq.getTitleFO()); - } - + public void startPageSequence(LineArea title) { 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 + * Add a new page to the area tree. + * @param page the page to add */ - private LineArea getTitleArea(Title foTitle) { - // get breaks then add areas to title - LineArea title = new LineArea(); - - ContentLayoutManager clm = new ContentLayoutManager(title); - clm.setUserAgent(foTitle.getUserAgent()); - - // use special layout manager to add the inline areas - // to the Title. - InlineStackingLayoutManager lm; - lm = new InlineStackingLayoutManager(foTitle); - clm.addChildLM(lm); - - clm.fillArea(lm); - - return title; + public void addPage(PageViewport page) { + model.addPage(page); } - + /** * Accessor for the currentLMList. * @return the currentLMList. diff --git a/src/java/org/apache/fop/fo/pagination/PageSequence.java b/src/java/org/apache/fop/fo/pagination/PageSequence.java index 2c82affc8..2f70ab498 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequence.java @@ -673,6 +673,9 @@ public class PageSequence extends FObj { */ public void setCurrentPageNumber(int currentPageNumber) { this.currentPageNumber = currentPageNumber; + + // Tell the root the last page number we created. + root.setRunningPageNumberCounter(currentPageNumber); } /** diff --git a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java index c3f5afc05..4bc92fafb 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java @@ -58,7 +58,27 @@ public class PageSequenceMaster extends FObj { super(parent); } - + /** + * @see org.apache.fop.fo.FObj#addProperties + */ + protected void addProperties(Attributes attlist) throws SAXParseException { + super.addProperties(attlist); + subSequenceSpecifiers = new java.util.ArrayList(); + if (parent.getName().equals("fo:layout-master-set")) { + this.layoutMasterSet = (LayoutMasterSet)parent; + masterName = getPropString(PR_MASTER_NAME); + if (masterName == null) { + getLogger().warn("page-sequence-master does not have " + + "a master-name and so is being ignored"); + } else { + this.layoutMasterSet.addPageSequenceMaster(masterName, this); + } + } else { + throw new SAXParseException("fo:page-sequence-master must be child " + + "of fo:layout-master-set, not " + + parent.getName(), locator); + } + } /** * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) @@ -85,29 +105,6 @@ public class PageSequenceMaster extends FObj { } } - - /** - * @see org.apache.fop.fo.FObj#addProperties - */ - protected void addProperties(Attributes attlist) throws SAXParseException { - super.addProperties(attlist); - subSequenceSpecifiers = new java.util.ArrayList(); - if (parent.getName().equals("fo:layout-master-set")) { - this.layoutMasterSet = (LayoutMasterSet)parent; - masterName = getPropString(PR_MASTER_NAME); - if (masterName == null) { - getLogger().warn("page-sequence-master does not have " - + "a master-name and so is being ignored"); - } else { - this.layoutMasterSet.addPageSequenceMaster(masterName, this); - } - } else { - throw new SAXParseException("fo:page-sequence-master must be child " - + "of fo:layout-master-set, not " - + parent.getName(), locator); - } - } - /** * Adds a new suqsequence specifier to the page sequence master. * @param pageMasterReference the subsequence to add diff --git a/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java b/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java index c78bed7f5..15ee8b873 100644 --- a/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java @@ -29,7 +29,7 @@ import org.apache.fop.traits.MinOptMax; /** * LayoutManager for an fo:flow object. - * Its parent LM is the PageLayoutManager. + * Its parent LM is the PageSequenceLayoutManager. * This LM is responsible for getting columns of the appropriate size * and filling them with block-level areas generated by its children. */ diff --git a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index f42be768b..e115f3f35 100644 --- a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -14,7 +14,7 @@ * limitations under the License. */ -/* $Id: PageLayoutManager.java,v 1.38 2004/05/22 21:44:38 gmazza Exp $ */ +/* $Id$ */ package org.apache.fop.layoutmgr; @@ -26,6 +26,7 @@ import org.apache.fop.area.AreaTreeModel; import org.apache.fop.area.Area; import org.apache.fop.area.PageViewport; import org.apache.fop.area.Flow; +import org.apache.fop.area.LineArea; import org.apache.fop.area.Page; import org.apache.fop.area.RegionViewport; import org.apache.fop.area.RegionReference; @@ -48,6 +49,7 @@ import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.pagination.Region; import org.apache.fop.fo.pagination.SimplePageMaster; import org.apache.fop.fo.pagination.StaticContent; +import org.apache.fop.fo.pagination.Title; import org.apache.fop.fo.properties.CommonBackground; import org.apache.fop.fo.properties.CommonBorderAndPadding; import org.apache.fop.fo.properties.CommonMarginBlock; @@ -65,7 +67,7 @@ import org.apache.fop.traits.MinOptMax; * LayoutManager for a PageSequence and its flow. * It manages all page-related layout. */ -public class PageLayoutManager extends AbstractLayoutManager implements Runnable { +public class PageSequenceLayoutManager extends AbstractLayoutManager implements Runnable { private static class BlockBreakPosition extends LeafPosition { protected BreakPoss breakps; @@ -129,10 +131,13 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable * @param areaTree the area tree to add pages to * @param pageseq the page sequence fo */ - public PageLayoutManager(AreaTreeHandler areaTreeHandler, PageSequence pageseq) { + public PageSequenceLayoutManager(AreaTreeHandler areaTreeHandler, PageSequence pageseq) { super(pageseq); this.areaTreeHandler = areaTreeHandler; pageSequence = pageseq; + if (pageSequence.getPageSequenceMaster() != null) { + pageSequence.getPageSequenceMaster().reset(); + } } /** @@ -142,13 +147,37 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable * @param pc the starting page number * @param generator the page number generator */ - public void setPageCounting(int pc, PageNumberGenerator generator) { + private void setPageCounting(int pc, PageNumberGenerator generator) { + pageSequence.initPageNumber(); pageCount = pc; pageNumberGenerator = generator; pageNumberString = pageNumberGenerator.makeFormattedPageNumber(pageCount); } /** + * The layout process is designed to be able to be run in a thread. + * In theory it can run at the same + * time as FO tree generation, once the layout-master-set has been read. + * We can arrange it so that the iterator over the fobj children waits + * until the next child is available. + * As it produces pages, it adds them to the AreaTree, where the + * rendering process can also run in a parallel thread. + */ + public void run() { + setPageCounting(pageSequence.getCurrentPageNumber(), + pageSequence.getPageNumberGenerator()); + + LineArea title = null; + if (pageSequence.getTitleFO() != null) { + title = getTitleArea(pageSequence.getTitleFO()); + } + + areaTreeHandler.startPageSequence(title); + doLayout(); + flush(); + } + + /** * Get the page count. * Used to get the last page number for reference for * the next page sequence. @@ -160,17 +189,24 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable } /** - * The layout process is designed to be able to be run in a thread. - * In theory it can run at the same - * time as FO tree generation, once the layout-master-set has been read. - * We can arrange it so that the iterator over the fobj children waits - * until the next child is available. - * As it produces pages, it adds them to the AreaTree, where the - * rendering process can also run in a parallel thread. + * @return the Title area */ - public void run() { - doLayout(); - flush(); + private LineArea getTitleArea(Title foTitle) { + // get breaks then add areas to title + LineArea title = new LineArea(); + + ContentLayoutManager clm = new ContentLayoutManager(title); + clm.setUserAgent(foTitle.getUserAgent()); + + // use special layout manager to add the inline areas + // to the Title. + InlineStackingLayoutManager lm; + lm = new InlineStackingLayoutManager(foTitle); + clm.addChildLM(lm); + + clm.fillArea(lm); + + return title; } /** diff --git a/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java index 424231276..bb706fbea 100644 --- a/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java @@ -28,7 +28,7 @@ import java.util.Map; /** * LayoutManager for an fo:flow object. - * Its parent LM is the PageLayoutManager. + * Its parent LM is the PageSequenceLayoutManager. * This LM is responsible for getting columns of the appropriate size * and filling them with block-level areas generated by its children. */ |