throw new ValidationException("master-reference '" + masterReference
+ "' for fo:page-sequence matches no"
+ " simple-page-master or page-sequence-master", locator);
+ } else {
+ pageSequenceMaster.reset();
}
}
}
/**
- * 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);
}
/**
/** True if haven't yet laid out any pages.*/
private boolean bFirstPage;
+
/** Current page being worked on. */
private PageViewport curPage;
public PageSequenceLayoutManager(PageSequence pageSeq) {
super(pageSeq);
this.pageSeq = pageSeq;
- if (pageSeq.getPageSequenceMaster() != null) {
- pageSeq.getPageSequenceMaster().reset();
- }
}
/**
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
*/
pageCount--;
log.debug("Ending layout");
finishPage();
- pageSeq.setCurrentPageNumber(getPageCount());
+ pageSeq.setCurrentPageNumber(pageCount);
}
/** @see org.apache.fop.layoutmgr.LayoutManager#isBogus() */
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());
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();