From: Glen Mazza Date: Sat, 12 Feb 2005 22:32:36 +0000 (+0000) Subject: Some cleanup -- moved getSimplePageMasterToUse() to PageSequence (logic X-Git-Tag: Root_Temp_KnuthStylePageBreaking~79 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=da94c4f54fea92c5615def50c1c9ba2ce2f9b960;p=xmlgraphics-fop.git Some cleanup -- moved getSimplePageMasterToUse() to PageSequence (logic is useful with other implementations of PSLM.) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198428 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fo/pagination/PageSequence.java b/src/java/org/apache/fop/fo/pagination/PageSequence.java index 18678bf0c..2dce9b1b9 100644 --- a/src/java/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/java/org/apache/fop/fo/pagination/PageSequence.java @@ -176,6 +176,8 @@ public class PageSequence extends FObj { throw new ValidationException("master-reference '" + masterReference + "' for fo:page-sequence matches no" + " simple-page-master or page-sequence-master", locator); + } else { + pageSequenceMaster.reset(); } } @@ -658,23 +660,23 @@ public class PageSequence extends FObj { } /** - * Public accessor for getting the PageSequenceMaster (if any) to which this - * PageSequence is attached. - * @return the PageSequenceMaster to which this PageSequence is attached, or - * null if there is none. + * Public accessor for determining the page master to use for any given + * page within this page sequence + * @param pageCount = the page number of the page to be created + * @param bIsFirstPage = indicator whether this page is the first page of the + * page sequence + * @param bIsBlank = indicator whether the page will be blank + * @return the SimplePageMaster to use for this page */ - public PageSequenceMaster getPageSequenceMaster() { - return pageSequenceMaster; - } + public SimplePageMaster getSimplePageMasterToUse(int pageCount, boolean bIsFirstPage, + boolean bIsBlank) throws FOPException { - /** - * Public accessor for getting the SimplePageMaster (if any) to which this - * PageSequence is attached. - * @return the SimplePageeMaster to which this PageSequence is attached or - * null if there is none. - */ - public SimplePageMaster getSimplePageMaster() { - return simplePageMaster; + if (pageSequenceMaster == null) { + return simplePageMaster; + } + boolean isOddPage = ((pageCount % 2) == 1); + return pageSequenceMaster.getNextSimplePageMaster(isOddPage, + bIsFirstPage, bIsBlank); } /** diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index 0321c8235..ce86164e9 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -81,6 +81,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { /** True if haven't yet laid out any pages.*/ private boolean bFirstPage; + /** Current page being worked on. */ private PageViewport curPage; @@ -129,9 +130,6 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { public PageSequenceLayoutManager(PageSequence pageSeq) { super(pageSeq); this.pageSeq = pageSeq; - if (pageSeq.getPageSequenceMaster() != null) { - pageSeq.getPageSequenceMaster().reset(); - } } /** @@ -151,17 +149,6 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { return areaTreeHandler; } - /** - * Get the page count. - * Used to get the last page number for reference for - * the next page sequence. - * - * @return the page number - */ - public int getPageCount() { - return pageCount; - } - /** * @return the Title area */ @@ -223,7 +210,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { pageCount--; log.debug("Ending layout"); finishPage(); - pageSeq.setCurrentPageNumber(getPageCount()); + pageSeq.setCurrentPageNumber(pageCount); } /** @see org.apache.fop.layoutmgr.LayoutManager#isBogus() */ @@ -473,12 +460,21 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { private PageViewport makeNewPage(boolean bIsBlank, boolean bIsLast) { finishPage(); + try { - curPage = createPage(bIsBlank, bIsLast); + // create a new page + currentSimplePageMaster = pageSeq.getSimplePageMasterToUse( + pageCount, isFirstPage, bIsBlank); + Region body = currentSimplePageMaster.getRegion(FO_REGION_BODY); + if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName())) { + throw new FOPException("Flow '" + pageSeq.getMainFlow().getFlowName() + + "' does not map to the region-body in page-master '" + + currentSimplePageMaster.getMasterName() + "'"); + } + curPage = createPageAreas(currentSimplePageMaster); isFirstPage = false; } catch (FOPException fopex) { - //TODO this exception is fatal, isn't it? - log.error("Cannot create page", fopex); + throw new IllegalArgumentException("Cannot create page: " + fopex.getMessage()); } curPage.setPageNumberString(getCurrentPageNumber()); @@ -747,47 +743,6 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { createFlow(); } - /** - * Called when a new page is needed. - * - * @param bIsBlank If true, use a master for a blank page. - * @param bIsLast If true, use the master for the last page in the sequence. - * @return the page viewport created for the page number - * @throws FOPException if there is an error creating page - */ - private PageViewport createPage(boolean bIsBlank, boolean bIsLast) - throws FOPException { - currentSimplePageMaster = getSimplePageMasterToUse(bIsBlank); - Region body = currentSimplePageMaster.getRegion(FO_REGION_BODY); - if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName())) { - throw new FOPException("Flow '" + pageSeq.getMainFlow().getFlowName() - + "' does not map to the region-body in page-master '" - + currentSimplePageMaster.getMasterName() + "'"); - } - PageViewport p = createPageAreas(currentSimplePageMaster); - return p; - // The page will have a viewport/reference area pair defined - // for each region in the master. - // Set up the page itself -// SKIP ALL THIS FOR NOW!!! -// //pageSequence.root.setRunningPageNumberCounter(pageSequence.currentPageNumber); - -// pageSequence.pageCount++; // used for 'force-page-count' calculations - - // handle the 'force-page-count' - //forcePage(areaTree, firstAvailPageNumber); - } - - private SimplePageMaster getSimplePageMasterToUse(boolean bIsBlank) - throws FOPException { - if (pageSeq.getPageSequenceMaster() == null) { - return pageSeq.getSimplePageMaster(); - } - boolean isOddPage = ((pageCount % 2) == 1); - return pageSeq.getPageSequenceMaster() - .getNextSimplePageMaster(isOddPage, isFirstPage, bIsBlank); - } - private PageViewport createPageAreas(SimplePageMaster spm) { int pageWidth = spm.getPageWidth().getValue(); int pageHeight = spm.getPageHeight().getValue();