private Page currentPage;
- // page number and elated formatting variables
+ // page number and related formatting variables
+ private String ipnValue;
private int currentPageNumber = 0;
private PageNumberGenerator pageNumberGenerator;
+ private int forcePageCount = 0;
+ private int pageCount = 0;
+ private boolean isForcing = false;
+
/** specifies page numbering type (auto|auto-even|auto-odd|explicit) */
private int pageNumberType;
_flowMap = new Hashtable();
thisIsFirstPage = true; // we are now on the first page of the page sequence
- String ipnValue =
- this.properties.get("initial-page-number").getString();
+ ipnValue = this.properties.get("initial-page-number").getString();
if (ipnValue.equals("auto")) {
pageNumberType = AUTO;
this.properties.get("grouping-size").getNumber().intValue(),
this.properties.get("letter-value").getEnum()
);
+
+ this.forcePageCount = this.properties.get("force-page-count").getEnum();
}
public void addFlow(Flow flow) throws FOPException {
this.layoutMasterSet.resetPageMasters();
+ int firstAvailPageNumber = 0;
do {
// makePage() moved to after the page-number computations,
// but store the page-number at this point for that method,
// since we want the 'current' current page-number...
- int firstAvailPageNumber =
+ firstAvailPageNumber =
this.root.getRunningPageNumberCounter();
boolean tempIsFirstPage = false;
}
MessageHandler.log("]");
areaTree.addPage(currentPage);
+ this.pageCount++; // used for 'force-page-count' calculations
} while (flowsAreIncomplete())
;
-
+ // handle the 'force-page-count'
+ forcePage(areaTree, firstAvailPageNumber);
+
MessageHandler.logln("");
}
private SimplePageMaster getNextSimplePageMaster(
PageSequenceMaster sequenceMaster, int currentPageNumber,
boolean thisIsFirstPage, boolean isEmptyPage) {
+ // handle forcing
+ if (isForcing) {
+ String nextPageMaster = getNextPageMasterName(sequenceMaster,
+ currentPageNumber, false, true);
+ return this.layoutMasterSet.getSimplePageMaster(nextPageMaster);
+ }
String nextPageMaster = getNextPageMasterName(sequenceMaster,
currentPageNumber, thisIsFirstPage, isEmptyPage);
return this.layoutMasterSet.getSimplePageMaster(nextPageMaster);
private boolean isFlowForMasterNameDone(String masterName) {
// parameter is master-name of PMR; we need to locate PM
// referenced by this, and determine whether flow(s) are OK
+ if (isForcing) return false;
if (masterName != null) {
SimplePageMaster spm =
public void setIsFlowSet(boolean isFlowSet) {
this.isFlowSet = isFlowSet;
}
+
+ public String getIpnValue() {
+ return ipnValue;
+ }
+
+ public int getCurrentPageNumber() {
+ return currentPageNumber;
+ }
+
+ private void forcePage(AreaTree areaTree, int firstAvailPageNumber) {
+ boolean makePage = false;
+ if (this.forcePageCount == ForcePageCount.AUTO) {
+ PageSequence nextSequence =
+ this.root.getSucceedingPageSequence(this);
+ if (nextSequence != null) {
+ if (nextSequence.getIpnValue().equals("auto")) {
+ // do nothing special
+ } else if (nextSequence.getIpnValue().equals("auto-odd")) {
+ if (firstAvailPageNumber % 2 == 0) {
+ makePage = true;
+ }
+ } else if (nextSequence.getIpnValue().equals("auto-even")) {
+ if (firstAvailPageNumber % 2 != 0) {
+ makePage = true;
+ }
+ } else {
+ int nextSequenceStartPageNumber =
+ nextSequence.getCurrentPageNumber();
+ if ((nextSequenceStartPageNumber % 2 == 0) &&
+ (firstAvailPageNumber % 2 == 0)) {
+ makePage = true;
+ } else if ((nextSequenceStartPageNumber % 2 != 0) &&
+ (firstAvailPageNumber % 2 != 0)) {
+ makePage = true;
+ }
+ }
+ }
+ } else if ((this.forcePageCount == ForcePageCount.EVEN) &&
+ (this.pageCount % 2 != 0)) {
+ makePage = true;
+ } else if ((this.forcePageCount == ForcePageCount.ODD) &&
+ (this.pageCount % 2 == 0)) {
+ makePage = true;
+ } else if ((this.forcePageCount == ForcePageCount.END_ON_EVEN) &&
+ (firstAvailPageNumber % 2 == 0)) {
+ makePage = true;
+ } else if ((this.forcePageCount == ForcePageCount.END_ON_ODD) &&
+ (firstAvailPageNumber % 2 != 0)) {
+ makePage = true;
+ } else if (this.forcePageCount == ForcePageCount.NO_FORCE) {
+ // do nothing
+ }
+ if (makePage) {
+ try
+ {
+ this.isForcing = true;
+ this.currentPageNumber++;
+ firstAvailPageNumber = this.currentPageNumber;
+ currentPage = makePage(areaTree, firstAvailPageNumber,
+ false, true);
+ String formattedPageNumber =
+ pageNumberGenerator.makeFormattedPageNumber(this.currentPageNumber);
+ currentPage.setFormattedNumber(formattedPageNumber);
+ formatStaticContent(areaTree);
+ MessageHandler.log("[forced-" + firstAvailPageNumber + "]");
+ areaTree.addPage(currentPage);
+ this.root.setRunningPageNumberCounter(this.currentPageNumber);
+ this.isForcing = false;
+ }
+ catch (FOPException fopex) {
+ MessageHandler.log("'force-page-count' failure");
+ }
+ }
+ }
}
/** keeps count of page number from over PageSequence instances*/
private int runningPageNumberCounter = 0;
-
protected Root(FObj parent,
PropertyList propertyList) throws FOPException {
super(parent, propertyList);
}
}
-
protected int getRunningPageNumberCounter() {
return this.runningPageNumberCounter;
}
-
protected void setRunningPageNumberCounter(int count) {
this.runningPageNumberCounter = count;
}
-
/** @deprecated handled by addChild now
*/
public void addPageSequence(PageSequence pageSequence) {
this.pageSequences.addElement(pageSequence);
}
-
+ public int getPageSequenceCount() {
+ return pageSequences.size();
+ }
+
+ /**
+ * Some properties, such as 'force-page-count', require a
+ * page-sequence to know about some properties of the next.
+ * @returns succeeding PageSequence; null if none
+ */
+ public PageSequence getSucceedingPageSequence(PageSequence current) {
+ int currentIndex = pageSequences.indexOf(current);
+ if (currentIndex == -1) return null;
+ if (currentIndex < (pageSequences.size()-1)) {
+ return (PageSequence)pageSequences.elementAt(currentIndex+1);
+ } else {
+ return null;
+ }
+ }
+
public LayoutMasterSet getLayoutMasterSet() {
return this.layoutMasterSet;
}