aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGlen Mazza <gmazza@apache.org>2005-02-12 22:32:36 +0000
committerGlen Mazza <gmazza@apache.org>2005-02-12 22:32:36 +0000
commitda94c4f54fea92c5615def50c1c9ba2ce2f9b960 (patch)
tree60ee65df2715bb684ccf19ffe9238e919cb36bc7 /src
parent42cc3d4164154da2e0b03f19f49d4acf3f73471d (diff)
downloadxmlgraphics-fop-da94c4f54fea92c5615def50c1c9ba2ce2f9b960.tar.gz
xmlgraphics-fop-da94c4f54fea92c5615def50c1c9ba2ce2f9b960.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/fo/pagination/PageSequence.java32
-rw-r--r--src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java73
2 files changed, 31 insertions, 74 deletions
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();
- }
}
/**
@@ -152,17 +150,6 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
}
/**
- * 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
*/
private LineArea getTitleArea(Title foTitle) {
@@ -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();