aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorSimon Pepping <spepping@apache.org>2006-01-06 21:31:02 +0000
committerSimon Pepping <spepping@apache.org>2006-01-06 21:31:02 +0000
commit5c359c10e6131572e46745dfe46c4c556e361ea0 (patch)
tree053cb689ec15010fe4f01fdc489054dddde99299 /src/java/org/apache
parentee938b7c2361df5ad4629ba6f90d84c74b5278a5 (diff)
downloadxmlgraphics-fop-5c359c10e6131572e46745dfe46c4c556e361ea0.tar.gz
xmlgraphics-fop-5c359c10e6131572e46745dfe46c4c556e361ea0.zip
Implementation of force-page-count property, patch by Gerhard Oettl,
somewhat rearranged by me. See bug 38087. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@366569 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/area/AreaTreeHandler.java17
-rw-r--r--src/java/org/apache/fop/fo/pagination/PageSequence.java18
-rw-r--r--src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java76
3 files changed, 104 insertions, 7 deletions
diff --git a/src/java/org/apache/fop/area/AreaTreeHandler.java b/src/java/org/apache/fop/area/AreaTreeHandler.java
index 09d8cb80b..9fdc17870 100644
--- a/src/java/org/apache/fop/area/AreaTreeHandler.java
+++ b/src/java/org/apache/fop/area/AreaTreeHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -98,6 +98,8 @@ public class AreaTreeHandler extends FOEventHandler {
// The formatting results to be handed back to the caller.
private FormattingResults results = new FormattingResults();
+ private PageSequenceLayoutManager prevPageSeqLM;
+
private static Log log = LogFactory.getLog(AreaTreeHandler.class);
/**
@@ -266,7 +268,15 @@ public class AreaTreeHandler extends FOEventHandler {
/** @see org.apache.fop.fo.FOEventHandler */
public void startPageSequence(PageSequence pageSequence) {
rootFObj = pageSequence.getRoot();
-
+ // finish the previous pageSequence (handle force-page-count)
+ if (prevPageSeqLM != null) {
+ prevPageSeqLM.doForcePageCount(pageSequence.getInitialPageNumber());
+ prevPageSeqLM.finishPageSequence();
+ prevPageSeqLM = null;
+ // recalc pagenumber for the case that a new page is
+ // inserted by checkForcePageCount
+ }
+ pageSequence.initPageNumber();
//extension attachments from fo:root
wrapAndAddExtensionAttachments(rootFObj.getExtensionAttachments());
//extension attachments from fo:declarations
@@ -303,6 +313,9 @@ public class AreaTreeHandler extends FOEventHandler {
pageSLM = getLayoutManagerMaker().makePageSequenceLayoutManager(
this, pageSequence);
pageSLM.activateLayout();
+ // preserve the current PageSequenceLayoutManger for the
+ // force-page-count check at the beginning of the next PageSequence
+ prevPageSeqLM = pageSLM;
}
}
diff --git a/src/java/org/apache/fop/fo/pagination/PageSequence.java b/src/java/org/apache/fop/fo/pagination/PageSequence.java
index 1066b67e1..80006da30 100644
--- a/src/java/org/apache/fop/fo/pagination/PageSequence.java
+++ b/src/java/org/apache/fop/fo/pagination/PageSequence.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -139,7 +139,6 @@ public class PageSequence extends FObj {
new PageNumberGenerator(format, groupingSeparator, groupingSize, letterValue);
checkId(id);
- initPageNumber();
getFOEventHandler().startPageSequence(this);
}
@@ -235,7 +234,7 @@ public class PageSequence extends FObj {
/**
* Initialize the current page number for the start of the page sequence.
*/
- private void initPageNumber() {
+ public void initPageNumber() {
int pageNumberType = 0;
if (initialPageNumber.getEnum() != 0) {
@@ -511,4 +510,17 @@ public class PageSequence extends FObj {
public int getNameId() {
return FO_PAGE_SEQUENCE;
}
+ /**
+ * get the forcePageCount value
+ */
+ public int getForcePageCount() {
+ return forcePageCount;
+ }
+
+ /**
+ * get the initial pagenumber property value
+ */
+ public Numeric getInitialPageNumber() {
+ return initialPageNumber;
+ }
}
diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
index b5f69f613..a7c6c7b6a 100644
--- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ package org.apache.fop.layoutmgr;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.datatypes.Numeric;
import org.apache.fop.area.AreaTreeHandler;
import org.apache.fop.area.AreaTreeModel;
@@ -145,8 +146,11 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
PageBreaker breaker = new PageBreaker(this);
int flowBPD = (int)getCurrentPV().getBodyRegion().getRemainingBPD();
breaker.doLayout(flowBPD);
-
+
finishPage();
+ }
+
+ public void finishPageSequence() {
pageSeq.getRoot().notifyPageSequenceFinished(currentPageNum,
(currentPageNum - startPageNum) + 1);
areaTreeHandler.notifyPageSequenceFinished(pageSeq,
@@ -888,4 +892,72 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
}
}
+
+ /*
+ * check if the page-number of the last page suits to the force-page-count property
+ */
+ public void doForcePageCount(Numeric nextPageSeqInitialPageNumber) {
+
+ int forcePageCount = pageSeq.getForcePageCount();
+
+ // xsl-spec version 1.0 (15.oct 2001)
+ // auto | even | odd | end-on-even | end-on-odd | no-force | inherit
+ // auto:
+ // Force the last page in this page-sequence to be an odd-page
+ // if the initial-page-number of the next page-sequence is even.
+ // Force it to be an even-page
+ // if the initial-page-number of the next page-sequence is odd.
+ // If there is no next page-sequence
+ // or if the value of its initial-page-number is "auto" do not force any page.
+
+
+ // if force-page-count is auto then set the value of forcePageCount
+ // depending on the initial-page-number of the next page-sequence
+ if (forcePageCount == Constants.EN_AUTO) {
+ if (nextPageSeqInitialPageNumber.getEnum() != 0) {
+ // auto | auto-odd | auto-even
+ int nextPageSeqPageNumberType = nextPageSeqInitialPageNumber.getEnum();
+ if (nextPageSeqPageNumberType == Constants.EN_AUTO_ODD) {
+ forcePageCount = Constants.EN_END_ON_EVEN;
+ } else if (nextPageSeqPageNumberType == Constants.EN_AUTO_EVEN) {
+ forcePageCount = Constants.EN_END_ON_ODD;
+ } else { // auto
+ forcePageCount = Constants.EN_NO_FORCE;
+ }
+ } else { // <integer> for explicit page number
+ int nextPageSeqPageStart = nextPageSeqInitialPageNumber.getValue();
+ // spec rule
+ nextPageSeqPageStart = (nextPageSeqPageStart > 0) ? nextPageSeqPageStart : 1;
+ if (nextPageSeqPageStart % 2 == 0) { // explicit even startnumber
+ forcePageCount = Constants.EN_END_ON_ODD;
+ } else { // explicit odd startnumber
+ forcePageCount = Constants.EN_END_ON_EVEN;
+ }
+ }
+ }
+
+ if (forcePageCount == Constants.EN_EVEN) {
+ if ((currentPageNum - startPageNum + 1) % 2 != 0) { // we have a odd number of pages
+ curPage = makeNewPage(true, false);
+ }
+ } else if (forcePageCount == Constants.EN_ODD) {
+ if ((currentPageNum - startPageNum + 1) % 2 == 0) { // we have a even number of pages
+ curPage = makeNewPage(true, false);
+ }
+ } else if (forcePageCount == Constants.EN_END_ON_EVEN) {
+ if (currentPageNum % 2 != 0) { // we are now on a odd page
+ curPage = makeNewPage(true, false);
+ }
+ } else if (forcePageCount == Constants.EN_END_ON_ODD) {
+ if (currentPageNum % 2 == 0) { // we are now on a even page
+ curPage = makeNewPage(true, false);
+ }
+ } else if (forcePageCount == Constants.EN_NO_FORCE) {
+ // i hope: nothing special at all
+ }
+
+ if (curPage != null) {
+ finishPage();
+ }
+ }
}