keiron      2002/11/04 03:50:11

  Modified:    src/org/apache/fop/layoutmgr PageLayoutManager.java
               src/org/apache/fop/fo/pagination PageSequence.java
  Log:
  page numbering across sequences and number formatting
  
  Revision  Changes    Path
  1.22      +20 -7     xml-fop/src/org/apache/fop/layoutmgr/PageLayoutManager.java
  
  Index: PageLayoutManager.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/layoutmgr/PageLayoutManager.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- PageLayoutManager.java    25 Oct 2002 09:29:45 -0000      1.21
  +++ PageLayoutManager.java    4 Nov 2002 11:50:11 -0000       1.22
  @@ -13,6 +13,7 @@
   import org.apache.fop.fo.pagination.PageSequence;
   import org.apache.fop.fo.pagination.Region;
   import org.apache.fop.fo.pagination.SimplePageMaster;
  +import org.apache.fop.fo.pagination.PageNumberGenerator;
   import org.apache.fop.fo.properties.Constants;
   
   import java.util.ArrayList;
  @@ -33,6 +34,10 @@
           }
       }
   
  +    private PageNumberGenerator pageNumberGenerator;
  +    private int pageCount = 1;
  +    private String pageNumberString;
  +
       /** True if haven't yet laid out any pages.*/
       private boolean bFirstPage;
       /** Current page being worked on. */
  @@ -60,8 +65,6 @@
       private AreaTree areaTree;
       private PageSequence pageSequence;
   
  -    private int pageCount = 1;
  -
       /**
        * This is the top level layout manager.
        * It is created by the PageSequence FO.
  @@ -72,6 +75,15 @@
           pageSequence = pageseq;
       }
   
  +    public void setPageCounting(int pc, PageNumberGenerator generator) {
  +        pageCount = pc;
  +        pageNumberGenerator = generator;
  +        pageNumberString = pageNumberGenerator.makeFormattedPageNumber(pageCount);
  +    }
  +
  +    public int getPageCount() {
  +        return pageCount;
  +    }
   
       /**
        * The layout process is designed to be able to be run in a thread.
  @@ -104,10 +116,11 @@
   
                   // finish page and add to area tree
                   finishPage();
  +                pageCount++;
  +                pageNumberString = 
pageNumberGenerator.makeFormattedPageNumber(pageCount);
               }
  -            pageCount++;
           }
  -
  +        pageCount--;
       }
   
   
  @@ -135,7 +148,7 @@
       }
   
       public String getCurrentPageNumber() {
  -        return "" + pageCount;
  +        return pageNumberString;
       }
   
       public PageViewport resolveRefID(String ref) {
  @@ -251,7 +264,7 @@
       private PageViewport makeNewPage(boolean bIsBlank, boolean bIsLast) {
           finishPage();
           try {
  -            curPage = pageSequence.createPage(bIsBlank, bIsLast);
  +            curPage = pageSequence.createPage(pageCount, bIsBlank, bIsLast);
           } catch (FOPException fopex) { /* ???? */
               fopex.printStackTrace();
           }
  
  
  
  1.57      +39 -135   xml-fop/src/org/apache/fop/fo/pagination/PageSequence.java
  
  Index: PageSequence.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/pagination/PageSequence.java,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- PageSequence.java 25 Oct 2002 09:29:43 -0000      1.56
  +++ PageSequence.java 4 Nov 2002 11:50:11 -0000       1.57
  @@ -1,14 +1,9 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    */
  -/*
  - Modified by Mark Lillywhite [EMAIL PROTECTED] Does not add
  - itself to the root any more. Does not hang onto currentPage
  - pointer, which caused GC issues.
  - */
   
   package org.apache.fop.fo.pagination;
   
  @@ -115,7 +110,7 @@
       /**
        * The main content flow for this page-sequence.
        */
  -    private Flow mainFlow=null;
  +    private Flow mainFlow = null;
   
       /**
        * The fo:title object for this page-sequence.
  @@ -146,8 +141,8 @@
   
           _flowMap = new HashMap();
   
  -        thisIsFirstPage =
  -            true;    // we are now on the first page of the page sequence
  +        // we are now on the first page of the page sequence
  +        thisIsFirstPage = true;
           ipnValue = this.properties.get("initial-page-number").getString();
   
           if (ipnValue.equals("auto")) {
  @@ -171,10 +166,10 @@
           String masterName = this.properties.get("master-reference").getString();
           this.currentSimplePageMaster =
             this.layoutMasterSet.getSimplePageMaster(masterName);
  -        if (this.currentSimplePageMaster==null) {
  +        if (this.currentSimplePageMaster == null) {
               this.pageSequenceMaster =
                 this.layoutMasterSet.getPageSequenceMaster(masterName);
  -            if (this.pageSequenceMaster==null) {
  +            if (this.pageSequenceMaster == null) {
                   throw new FOPException("master-reference '" + masterName
                                          + "' for fo:page-sequence matches no 
simple-page-master or page-sequence-master");
               }
  @@ -319,9 +314,12 @@
           }
   
           int firstAvailPageNumber = 0;
  +        initPageNumber();
   
           // This will layout pages and add them to the area tree
           PageLayoutManager pageLM = new PageLayoutManager(areaTree, this);
  +        pageLM.setPageCounting(currentPageNumber, pageNumberGenerator);
  +
           // For now, skip the threading and just call run directly.
           pageLM.run();
   
  @@ -336,30 +334,30 @@
   // } catch (InterruptedException ie) {
   //     log.error("PageSequence.format() interrupted waiting on layout");
   // }
  +        this.currentPageNumber = pageLM.getPageCount();
           // Tell the root the last page number we created.
           this.root.setRunningPageNumberCounter(this.currentPageNumber);
       }
   
       private void initPageNumber() {
  -    this.currentPageNumber = this.root.getRunningPageNumberCounter() + 1;
  +        this.currentPageNumber = this.root.getRunningPageNumberCounter() + 1;
   
  -    if (this.pageNumberType == 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 == AUTO_EVEN) {
  -        if (currentPageNumber % 2 == 1) {
  -        this.currentPageNumber++;
  +        if (this.pageNumberType == 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 == AUTO_EVEN) {
  +            if (currentPageNumber % 2 == 1) {
  +                this.currentPageNumber++;
  +            }
  +        } else if (pageNumberType == EXPLICIT) {
  +            this.currentPageNumber = this.explicitFirstNumber;
           }
  -    }
  -    else if (pageNumberType == EXPLICIT) {
  -        this.currentPageNumber = this.explicitFirstNumber;
  -    }
  -    this.firstPageNumber = this.currentPageNumber;
  +        this.firstPageNumber = this.currentPageNumber;
       }
   
       /**
  @@ -369,11 +367,11 @@
        * @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.
        */
  -    public PageViewport createPage(boolean bIsBlank, boolean bIsLast)
  +    public PageViewport createPage(int pageNumber, boolean bIsBlank, boolean 
bIsLast)
         throws FOPException {
  -        if (this.pageSequenceMaster!=null) {
  +        if (this.pageSequenceMaster != null) {
               this.currentSimplePageMaster = this.pageSequenceMaster
  -              .getNextSimplePageMaster(((this.currentPageNumber % 2)==1),
  +              .getNextSimplePageMaster(((pageNumber % 2) == 1),
                                          thisIsFirstPage,
                                          bIsBlank);
           }
  @@ -385,32 +383,13 @@
           }
           PageMaster pageMaster = this.currentSimplePageMaster.getPageMaster();
           PageViewport p = pageMaster.makePage();
  -//         if (currentPage != null) {
  -//             Vector foots = currentPage.getPendingFootnotes();
  -//             p.setPendingFootnotes(foots);
  -//         }
           return p;
           // The page will have a viewport/reference area pair defined
           // for each region in the master.
           // Set up the page itself
  -    //            currentPage.setNumber(this.currentPageNumber);
   // SKIP ALL THIS FOR NOW!!!
  -//             String formattedPageNumber =
  -//                 
pageNumberGenerator.makeFormattedPageNumber(this.currentPageNumber);
  -//             currentPage.setFormattedNumber(formattedPageNumber);
  -//     this.currentPageNumber++;
   //             //this.root.setRunningPageNumberCounter(this.currentPageNumber);
   
  -//                 BodyAreaContainer bodyArea = currentPage.getBody();
  -//                 bodyArea.setIDReferences(areaTree.getIDReferences());
  -
  -//             // because of markers, do after fo:flow (likely also
  -//             // justifiable because of spec)
  -//             currentPage.setPageSequence(this);
  -//             formatStaticContent(areaTree);
  -
  -//             //log.info("]");
  -//             areaTree.addPage(currentPage);
   //             this.pageCount++;    // used for 'force-page-count' calculations
   
           // handle the 'force-page-count'
  @@ -448,86 +427,10 @@
   //              throw new FOPException("page masters exhausted. Cannot recover.");
   //          }
   //          PageViewport p = pageMaster.makePage();
  -//  //         if (currentPage != null) {
  -//  //             Vector foots = currentPage.getPendingFootnotes();
  -//  //             p.setPendingFootnotes(foots);
  -//  //         }
   //          return p;
   //      }
   
       /**
  -     * Formats the static content of the current page
  -     */
  -//     private void formatStaticContent(AreaTree areaTree) throws FOPException {
  -//         SimplePageMaster simpleMaster = getCurrentSimplePageMaster();
  -
  -//         if (simpleMaster.getRegion(Region.BODY) != null
  -//                 && (currentPage.getBefore() != null)) {
  -//             Flow staticFlow =
  -//                 
(Flow)_flowMap.get(simpleMaster.getRegion(RegionBefore.REGION_CLASS).getRegionName());
  -//             if (staticFlow != null) {
  -//                 AreaContainer beforeArea = currentPage.getBefore();
  -//                 beforeArea.setIDReferences(areaTree.getIDReferences());
  -//                 layoutStaticContent(staticFlow,
  -//                                     
simpleMaster.getRegion(RegionBefore.REGION_CLASS),
  -//                                     beforeArea);
  -//             }
  -//         }
  -
  -//         if (simpleMaster.getRegion(RegionAfter.REGION_CLASS) != null
  -//                 && (currentPage.getAfter() != null)) {
  -//             Flow staticFlow =
  -//                 
(Flow)_flowMap.get(simpleMaster.getRegion(RegionAfter.REGION_CLASS).getRegionName());
  -//             if (staticFlow != null) {
  -//                 AreaContainer afterArea = currentPage.getAfter();
  -//                 afterArea.setIDReferences(areaTree.getIDReferences());
  -//                 layoutStaticContent(staticFlow,
  -//                                     
simpleMaster.getRegion(RegionAfter.REGION_CLASS),
  -//                                     afterArea);
  -//             }
  -//         }
  -
  -//         if (simpleMaster.getRegion(RegionStart.REGION_CLASS) != null
  -//                 && (currentPage.getStart() != null)) {
  -//             Flow staticFlow =
  -//                 
(Flow)_flowMap.get(simpleMaster.getRegion(RegionStart.REGION_CLASS).getRegionName());
  -//             if (staticFlow != null) {
  -//                 AreaContainer startArea = currentPage.getStart();
  -//                 startArea.setIDReferences(areaTree.getIDReferences());
  -//                 layoutStaticContent(staticFlow,
  -//                                     
simpleMaster.getRegion(RegionStart.REGION_CLASS),
  -//                                     startArea);
  -//             }
  -//         }
  -
  -//         if (simpleMaster.getRegion(RegionEnd.REGION_CLASS) != null
  -//                 && (currentPage.getEnd() != null)) {
  -//             Flow staticFlow =
  -//                 
(Flow)_flowMap.get(simpleMaster.getRegion(RegionEnd.REGION_CLASS).getRegionName());
  -//             if (staticFlow != null) {
  -//                 AreaContainer endArea = currentPage.getEnd();
  -//                 endArea.setIDReferences(areaTree.getIDReferences());
  -//                 layoutStaticContent(staticFlow,
  -//                                     
simpleMaster.getRegion(RegionEnd.REGION_CLASS),
  -//                                     endArea);
  -//             }
  -//         }
  -
  -//     }
  -//
  -//     private void layoutStaticContent(Flow flow, Region region,
  -//                                      AreaContainer area) throws FOPException {
  -//         if (flow instanceof StaticContent) {
  -//             AreaContainer beforeArea = currentPage.getBefore();
  -//             ((StaticContent)flow).layout(area, region);
  -//         } else {
  -//             log.error("" + region.getName()
  -//                                    + " only supports static-content flows 
currently. Cannot use flow named '"
  -//                                    + flow.getFlowName() + "'");
  -//         }
  -//     }
  -
  -    /**
        * Returns the next SubSequenceSpecifier for the given page sequence master.
        * The result is bassed on the current state of this page sequence.
        */
  @@ -549,16 +452,16 @@
        * other state information
        */
   //      private SimplePageMaster getNextSimplePageMaster(PageSequenceMaster 
sequenceMaster,
  -//              int currentPageNumber, boolean thisIsFirstPage,
  +//              int pageNumber, boolean thisIsFirstPage,
   //              boolean isEmptyPage) {
   //          // handle forcing
   //          if (isForcing) {
   //              String nextPageMaster = getNextPageMasterName(sequenceMaster,
  -//                                      currentPageNumber, false, true);
  +//                                      pageNumber, false, true);
   //              return this.layoutMasterSet.getSimplePageMaster(nextPageMaster);
   //          }
   //          String nextPageMaster = getNextPageMasterName(sequenceMaster,
  -//                                  currentPageNumber, thisIsFirstPage, 
isEmptyPage);
  +//                                  pageNumber, thisIsFirstPage, isEmptyPage);
   //          return this.layoutMasterSet.getSimplePageMaster(nextPageMaster);
   
   //      }
  @@ -570,7 +473,7 @@
        * master name is used.
        */
   //      private String getNextPageMasterName(PageSequenceMaster sequenceMaster,
  -//                                           int currentPageNumber,
  +//                                           int pageNumber,
   //                                           boolean thisIsFirstPage,
   //                                           boolean isEmptyPage) {
   
  @@ -579,7 +482,7 @@
   //          }
   
   //          String nextPageMaster =
  -//              currentSubsequence.getNextPageMaster(currentPageNumber,
  +//              currentSubsequence.getNextPageMaster(pageNumber,
   //                                                   thisIsFirstPage,
   //                                                   isEmptyPage);
   
  @@ -601,7 +504,7 @@
   //              }
   
   //              nextPageMaster =
  -//                  currentSubsequence.getNextPageMaster(currentPageNumber,
  +//                  currentSubsequence.getNextPageMaster(pageNumber,
   //                                                       thisIsFirstPage,
   //                                                       isEmptyPage);
   //          }
  @@ -621,7 +524,7 @@
   
       // refactored from LayoutMasterSet
   //      private PageMaster getNextPageMaster(String pageSequenceName,
  -//                                           int currentPageNumber,
  +//                                           int pageNumber,
   //                                           boolean thisIsFirstPage,
   //                                           boolean isEmptyPage) throws 
FOPException {
   //          PageMaster pageMaster = null;
  @@ -632,7 +535,7 @@
   
   //          if (sequenceMaster != null) {
   //              pageMaster = getNextSimplePageMaster(sequenceMaster,
  -//                                                   currentPageNumber,
  +//                                                   pageNumber,
   //                                                   thisIsFirstPage,
   //                                                   isEmptyPage).getPageMaster();
   
  @@ -801,3 +704,4 @@
           return (StaticContent)_flowMap.get(name);
       }
   }
  +
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to