private String masterReference;
// End of property values
- //
- // initial-page-number types
- //
- public static final int EXPLICIT = 0;
-
/**
* The parent root object
*/
// private boolean isFlowSet = false;
- // for structure handler
- private boolean sequenceStarted = false;
-
- //
- // state attributes used during layout
- //
-
// page number and related formatting variables
- public int currentPageNumber = 0;
+ public int startingPageNumber = 0;
private int explicitFirstNumber = 0; // explicitly specified
- public int firstPageNumber = 0; // actual
private PageNumberGenerator pageNumberGenerator;
-
- private int pageCount = 0;
private boolean isForcing = false;
- /**
- * specifies page numbering type (auto|auto-even|auto-odd|explicit)
- */
- public int pageNumberType;
-
- /**
- * used to determine whether to calculate auto, auto-even, auto-odd
- */
- private boolean thisIsFirstPage;
-
/**
* The currentSimplePageMaster is either the page master for the
* whole page sequence if master-reference refers to a simple-page-master,
layoutMasterSet = root.getLayoutMasterSet();
flowMap = new HashMap();
- // we are now on the first page of the page sequence
- thisIsFirstPage = true;
-
- if (initialPageNumber.getEnum() != 0) {
- // auto | auto-odd | auto-even.
- pageNumberType = initialPageNumber.getEnum();
- } else {
- pageNumberType = EXPLICIT;
- int pageStart = initialPageNumber.getValue();
- this.explicitFirstNumber = (pageStart > 0) ? pageStart : 1;
- }
-
this.simplePageMaster =
this.layoutMasterSet.getSimplePageMaster(masterReference);
if (this.simplePageMaster == null) {
new PageNumberGenerator(format, groupingSeparator, groupingSize, letterValue);
checkId(id);
- //call startStructuredPageSequence to ensure, that startPageSequence is called
- //before startFlow.
- startStructuredPageSequence();
+ initPageNumber();
+ getFOEventHandler().startPageSequence(this);
}
/**
} else if (childId == FO_FLOW) {
this.mainFlow = (Flow) child;
addFlow(mainFlow);
- startStructuredPageSequence();
super.addChildNode(child); // For getChildren
} else if (childId == FO_STATIC_CONTENT) {
addFlow((StaticContent) child);
String flowName = ((StaticContent) child).getFlowName();
flowMap.put(flowName, child);
- startStructuredPageSequence();
}
}
}
}
- /**
- * Start the page-sequence logic in the Structured Handler
- */
- private void startStructuredPageSequence() {
- if (!sequenceStarted) {
- getFOEventHandler().startPageSequence(this);
- sequenceStarted = true;
- }
- }
-
/**
* Initialize the current page number for the start of the page sequence.
*/
- public void initPageNumber() {
- this.currentPageNumber = this.root.getRunningPageNumberCounter() + 1;
-
- if (this.pageNumberType == EN_AUTO_ODD) {
- // Next page but force odd. May force empty page creation!
- // Whose master is used for this??? Assume no.
- // Use force-page-count = auto
- // on preceding page-sequence to make sure that there is no gap!
- if (currentPageNumber % 2 == 0) {
- this.currentPageNumber++;
- }
- } else if (pageNumberType == EN_AUTO_EVEN) {
- if (currentPageNumber % 2 == 1) {
- this.currentPageNumber++;
+ private void initPageNumber() {
+ int pageNumberType = 0;
+
+ if (initialPageNumber.getEnum() != 0) {
+ // auto | auto-odd | auto-even.
+ startingPageNumber = root.getEndingPageNumberOfPreviousSequence() + 1;
+ pageNumberType = initialPageNumber.getEnum();
+ if (pageNumberType == EN_AUTO_ODD) {
+ // Next page but force odd. May force empty page creation!
+ // Whose master is used for this??? Assume no.
+ // Use force-page-count = auto
+ // on preceding page-sequence to make sure that there is no gap!
+ if (startingPageNumber % 2 == 0) {
+ startingPageNumber++;
+ }
+ } else if (pageNumberType == EN_AUTO_EVEN) {
+ if (startingPageNumber % 2 == 1) {
+ startingPageNumber++;
+ }
}
- } else if (pageNumberType == EXPLICIT) {
- this.currentPageNumber = this.explicitFirstNumber;
+ } else { // <integer> for explicit page number
+ int pageStart = initialPageNumber.getValue();
+ startingPageNumber = (pageStart > 0) ? pageStart : 1; // spec rule
}
- this.firstPageNumber = this.currentPageNumber;
}
- /**
- * Creates a new page area for the given parameters
- * @param areaTree the area tree the page should be contained in
- * @param firstAvailPageNumber the page number for this page
- * @param isFirstPage true when this is the first page in the sequence
- * @param isEmptyPage true if this page will be empty
- * (e.g. forced even or odd break)
- * @return a Page layout object based on the page master selected
- * from the params
- * @todo modify the other methods to use even/odd flag and bIsLast
- */
-// private PageViewport makePage(int firstAvailPageNumber,
-// boolean isFirstPage, boolean bIsLast,
-// boolean isEmptyPage) throws FOPException {
-// // layout this page sequence
-
-// // while there is still stuff in the flow, ask the
-// // layoutMasterSet for a new page
-
-// // page number is 0-indexed
-// PageMaster pageMaster = getNextPageMaster(masterName,
-// firstAvailPageNumber,
-// isFirstPage, isEmptyPage);
-
-// // a legal alternative is to use the last sub-sequence
-// // specification which should be handled in getNextSubsequence.
-// // That's not done here.
-// if (pageMaster == null) {
-// throw new FOPException("page masters exhausted. Cannot recover.");
-// }
-// PageViewport p = pageMaster.makePage();
-// return p;
-// }
-
- /**
- * Returns the next SubSequenceSpecifier for the given page sequence master.
- * The result is bassed on the current state of this page sequence.
- */
-// private SubSequenceSpecifier getNextSubsequence(PageSequenceMaster master) {
-// if (master.getSubSequenceSpecifierCount()
-// > currentSubsequenceNumber + 1) {
-
-// currentSubsequence =
-// master.getSubSequenceSpecifier(currentSubsequenceNumber + 1);
-// currentSubsequenceNumber++;
-// return currentSubsequence;
-// } else {
-// return null;
-// }
-// }
-
- /**
- * Returns the next simple page master for the given sequence master, page number and
- * other state information
- */
-// private SimplePageMaster getNextSimplePageMaster(PageSequenceMaster sequenceMaster,
-// int pageNumber, boolean thisIsFirstPage,
-// boolean isEmptyPage) {
-// // handle forcing
-// if (isForcing) {
-// String nextPageMaster = getNextPageMasterName(sequenceMaster,
-// pageNumber, false, true);
-// return this.layoutMasterSet.getSimplePageMaster(nextPageMaster);
-// }
-// String nextPageMaster = getNextPageMasterName(sequenceMaster,
-// pageNumber, thisIsFirstPage, isEmptyPage);
-// return this.layoutMasterSet.getSimplePageMaster(nextPageMaster);
-
-// }
-
- /**
- * Get the next page master name.
- * This gets the name of the next page master. If the sequence
- * is exhausted then an error is indicated and the last page
- * master name is used.
- */
-// private String getNextPageMasterName(PageSequenceMaster sequenceMaster,
-// int pageNumber,
-// boolean thisIsFirstPage,
-// boolean isEmptyPage) {
-
-// if (null == currentSubsequence) {
-// currentSubsequence = getNextSubsequence(sequenceMaster);
-// }
-
-// String nextPageMaster =
-// currentSubsequence.getNextPageMaster(pageNumber,
-// thisIsFirstPage,
-// isEmptyPage);
-
-
-// if (null == nextPageMaster
-// || isFlowForMasterNameDone(currentPageMasterName)) {
-// SubSequenceSpecifier nextSubsequence =
-// getNextSubsequence(sequenceMaster);
-// if (nextSubsequence == null) {
-// getLogger().error("Page subsequences exhausted. Using previous subsequence.");
-// thisIsFirstPage =
-// true; // this becomes the first page in the new (old really) page master
-// currentSubsequence.reset();
-
-// // we leave currentSubsequence alone
-// }
-// else {
-// currentSubsequence = nextSubsequence;
-// }
-
-// nextPageMaster =
-// currentSubsequence.getNextPageMaster(pageNumber,
-// thisIsFirstPage,
-// isEmptyPage);
-// }
-// currentPageMasterName = nextPageMaster;
-
-// return nextPageMaster;
-
-// }
-
-// private SimplePageMaster getCurrentSimplePageMaster() {
-// return this.layoutMasterSet.getSimplePageMaster(currentPageMasterName);
-// }
-
-// private String getCurrentPageMasterName() {
-// return currentPageMasterName;
-// }
-
- // refactored from LayoutMasterSet
-// private PageMaster getNextPageMaster(String pageSequenceName,
-// int pageNumber,
-// boolean thisIsFirstPage,
-// boolean isEmptyPage) throws FOPException {
-// PageMaster pageMaster = null;
-
-// // see if there is a page master sequence for this master name
-// PageSequenceMaster sequenceMaster =
-// this.layoutMasterSet.getPageSequenceMaster(pageSequenceName);
-
-// if (sequenceMaster != null) {
-// pageMaster = getNextSimplePageMaster(sequenceMaster,
-// pageNumber,
-// thisIsFirstPage,
-// isEmptyPage).getPageMaster();
-
-// } else { // otherwise see if there's a simple master by the given name
-// SimplePageMaster simpleMaster =
-// this.layoutMasterSet.getSimplePageMaster(pageSequenceName);
-// if (simpleMaster == null) {
-// throw new FOPException("'master-reference' for 'fo:page-sequence'"
-// + "matches no 'simple-page-master'"
-// + " or 'page-sequence-master'");
-// }
-// currentPageMasterName = pageSequenceName;
-
-// pageMaster = simpleMaster.getNextPageMaster();
-// }
-// return pageMaster;
-// }
-
-
// /**
// * Returns true when there is more flow elements left to lay out.
// */
// }
/**
- * Get the current page number for this page sequence.
+ * Get the starting page number for this page sequence.
*
- * @return the current page number
+ * @return the starting page number
*/
- public int getCurrentPageNumber() {
- return currentPageNumber;
+ public int getStartingPageNumber() {
+ return startingPageNumber;
}
// private void forcePage(AreaTree areaTree, int firstAvailPageNumber) {
return pageNumberGenerator.makeFormattedPageNumber(pageNumber);
}
- /**
- * Public accessor for setting the currentPageNumber.
- * @param currentPageNumber the value to which currentPageNumber should be
- * set.
- */
- public void setCurrentPageNumber(int currentPageNumber) {
- this.currentPageNumber = currentPageNumber;
-
- // Tell the root the last page number we created.
- root.setRunningPageNumberCounter(currentPageNumber);
- }
-
/**
* Public accessor for the ancestor Root.
* @return the ancestor Root
}
}
- private int pageCount = 1;
+ private int startPageNum = 0;
+ private int currentPageNum = 0;
private String pageNumberString;
private boolean isFirstPage = true;
* which creates and adds all the pages to the area tree.
*/
public void activateLayout() {
- pageSeq.initPageNumber();
- pageCount = pageSeq.getCurrentPageNumber();
- pageNumberString = pageSeq.makeFormattedPageNumber(pageCount);
+ startPageNum = pageSeq.getStartingPageNumber();
+ currentPageNum = startPageNum;
+ pageNumberString = pageSeq.makeFormattedPageNumber(currentPageNum);
LineArea title = null;
if (pageSeq.getTitleFO() != null) {
// finish page and add to area tree
finishPage();
- pageCount++;
- pageNumberString = pageSeq.makeFormattedPageNumber(pageCount);
+ currentPageNum++;
+ pageNumberString = pageSeq.makeFormattedPageNumber(currentPageNum);
}
}
- pageCount--;
+ // TODO: Don't decrement currentPageNum when no pages are generated
+ currentPageNum--;
log.debug("Ending layout");
finishPage();
- pageSeq.setCurrentPageNumber(pageCount);
+ pageSeq.getRoot().reportAdditionalPagesGenerated((currentPageNum - startPageNum) + 1);
}
/** @see org.apache.fop.layoutmgr.LayoutManager#isBogus() */
*
* @return the formatted page number string
*/
- public String getCurrentPageNumber() {
+ public String getCurrentPageNumberString() {
return pageNumberString;
}
try {
// create a new page
currentSimplePageMaster = pageSeq.getSimplePageMasterToUse(
- pageCount, isFirstPage, bIsBlank);
+ currentPageNum, isFirstPage, bIsBlank);
Region body = currentSimplePageMaster.getRegion(FO_REGION_BODY);
if (!pageSeq.getMainFlow().getFlowName().equals(body.getRegionName())) {
throw new FOPException("Flow '" + pageSeq.getMainFlow().getFlowName()
throw new IllegalArgumentException("Cannot create page: " + fopex.getMessage());
}
- curPage.setPageNumberString(getCurrentPageNumber());
+ curPage.setPageNumberString(pageNumberString);
if (log.isDebugEnabled()) {
log.debug("[" + curPage.getPageNumberString() + "]");
}
}
else {
/* IF we are on the kind of page we need, we'll need a new page. */
- if (pageCount%2 != 0) {
+ if (currentPageNum%2 != 0) {
// Current page is odd
return (breakValue == Constants.EN_ODD_PAGE);
}
if (breakValue == Constants.EN_PAGE) {
return false;
}
- else if (pageCount%2 != 0) {
+ else if (currentPageNum%2 != 0) {
// Current page is odd
return (breakValue == Constants.EN_EVEN_PAGE);
}