hello

I tried to implement the force-page-count property. It looks like
someone had already prepaired many things and it looks easy, but
there is a showstopper: I had no luck using the
getSucceedingPageSequence function of
/fop/fo/pagination/Root.java from
/fop/layoutmgr/PageSequenceLayoutManager.java by calling

nextPageSeq = pageSeq.getRoot().getSucceedingPageSequence(pageSeq)

it always returns null. In detail the
currentIndex = pageSequences.indexOf(current)
part of the getSucceedingPageSequence function always returns -1

Because i am not very familiar with java and the
getSucceedingPageSequence function is not used elsewhere i want
to ask if it is working as expected or if i called it in a wrong
manner.

Though the work is not ready and not tested at all i venture to
append the patch because it is very little to give you a larger
picture of the circumstances.


gerhard

-- 
 .''`.   gerhard oettl   on   Debian/Gnu Linux
: :'  :  
`. `'`   gpg key: 1024D/D59131AA 2002-06-18
  `-
Index: src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
===================================================================
--- src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java    
(Revision 360063)
+++ src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java    
(Arbeitskopie)
@@ -21,6 +21,7 @@
 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;
@@ -146,6 +147,8 @@
         int flowBPD = (int)getCurrentPV().getBodyRegion().getRemainingBPD();
         breaker.doLayout(flowBPD);
         
+        checkForcePageCount();
+
         finishPage();
         pageSeq.getRoot().notifyPageSequenceFinished(currentPageNum,
                 (currentPageNum - startPageNum) + 1);
@@ -888,4 +891,90 @@
         }
         
     }
+
+
+
+    /*
+     * check if the page-number of the last page suits to the force-page-count 
property
+     */
+    private void checkForcePageCount() {
+        // if (curPage != null) {
+        //     finishPage();
+        // }
+
+        int forcePageCount = pageSeq.getForcePageCount();
+        PageSequence nextPageSeq;
+        int nextPageSeqStartPageNum;
+        int nextPageSeqPageNumberType = 0;
+        Numeric nextPageSeqInitialPageNumber;
+       int nextPageSeqStartingPageNumber;
+
+        log.warn("blabla oettl");
+
+        // 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 ((nextPageSeq = 
pageSeq.getRoot().getSucceedingPageSequence(pageSeq)) == null) {
+                log.warn("no next pageseq");
+                forcePageCount = Constants.EN_NO_FORCE;
+            } else {
+                nextPageSeqInitialPageNumber = 
nextPageSeq.getInitialPageNumber();
+                if (nextPageSeqInitialPageNumber.getEnum() != 0) {
+                    // auto | auto-odd | auto-even
+                    nextPageSeqPageNumberType = 
nextPageSeqInitialPageNumber.getEnum();
+                    if (nextPageSeqPageNumberType == Constants.EN_AUTO_ODD) {
+                        forcePageCount = Constants.EN_EVEN;
+                    } else if (nextPageSeqPageNumberType == 
Constants.EN_AUTO_EVEN) {
+                        forcePageCount = Constants.EN_ODD;
+                    } else {   // auto
+                        forcePageCount = Constants.EN_NO_FORCE;
+                    }
+                } else { // <integer> for explicit page number
+                    int nextPageSeqPageStart = 
nextPageSeqInitialPageNumber.getValue();
+                    nextPageSeqStartingPageNumber = 
+                        (nextPageSeqPageStart > 0) ? nextPageSeqPageStart : 1; 
// spec rule
+                    if (nextPageSeqStartingPageNumber % 2 == 0) {   // 
explicit even startnumber
+                        forcePageCount = Constants.EN_ODD;
+                    } else {    // explicit odd startnumber
+                        forcePageCount = Constants.EN_EVEN;
+                    }
+                }
+            }
+        }
+
+        log.warn("forcePageCount" + forcePageCount);
+
+        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
+        }
+
+    }
+
 }
Index: src/java/org/apache/fop/fo/pagination/PageSequence.java
===================================================================
--- src/java/org/apache/fop/fo/pagination/PageSequence.java     (Revision 
360063)
+++ src/java/org/apache/fop/fo/pagination/PageSequence.java     (Arbeitskopie)
@@ -511,4 +511,20 @@
     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;
+    }
+
+
 }

Reply via email to