pietsch     2002/07/11 18:15:33

  Modified:    src/org/apache/fop/fo/pagination Tag: fop-0_20_2-maintain
                        PageSequence.java Root.java
  Log:
  Rearranged and simplified calculations related to page
  numbering and forced pages.
  Fixed force-page-count="auto"
  Removed some cruft.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.39.2.3  +97 -134   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.39.2.2
  retrieving revision 1.39.2.3
  diff -u -r1.39.2.2 -r1.39.2.3
  --- PageSequence.java 3 Jan 2002 10:39:56 -0000       1.39.2.2
  +++ PageSequence.java 12 Jul 2002 01:15:33 -0000      1.39.2.3
  @@ -101,10 +101,12 @@
       private Page currentPage;
   
       // page number and related formatting variables
  -    private String ipnValue;
  -    private int currentPageNumber = 0;
  +//    private String ipnValue;
  +    private int firstPageNumber = 0;
       private PageNumberGenerator pageNumberGenerator;
   
  +    private int currentPageNumber = 0;
  +
       private int forcePageCount = 0;
       private int pageCount = 0;
       private boolean isForcing = false;
  @@ -115,11 +117,6 @@
       private int pageNumberType;
   
       /**
  -     * used to determine whether to calculate auto, auto-even, auto-odd
  -     */
  -    private boolean thisIsFirstPage;
  -
  -    /**
        * the current subsequence while formatting a given page sequence
        */
       private SubSequenceSpecifier currentSubsequence;
  @@ -143,7 +140,6 @@
   
           if (parent.getName().equals("fo:root")) {
               this.root = (Root)parent;
  -            // this.root.addPageSequence(this);
           }
           else {
               throw new FOPException("page-sequence must be child of root, not "
  @@ -157,21 +153,22 @@
   
           _flowMap = new Hashtable();
   
  -        thisIsFirstPage =
  -            true;    // we are now on the first page of the page sequence
  -        ipnValue = this.properties.get("initial-page-number").getString();
  +        String ipnValue = this.properties.get("initial-page-number").getString();
   
           if (ipnValue.equals("auto")) {
               pageNumberType = AUTO;
  +            this.firstPageNumber = 1;
           } else if (ipnValue.equals("auto-even")) {
               pageNumberType = AUTO_EVEN;
  +            this.firstPageNumber = 2;
           } else if (ipnValue.equals("auto-odd")) {
               pageNumberType = AUTO_ODD;
  +            this.firstPageNumber = 1;
           } else {
               pageNumberType = EXPLICIT;
               try {
                   int pageStart = new Integer(ipnValue).intValue();
  -                this.currentPageNumber = (pageStart > 0) ? pageStart - 1 : 0;
  +                this.firstPageNumber = (pageStart > 0) ? pageStart  : 1;
               } catch (NumberFormatException nfe) {
                   throw new FOPException("\"" + ipnValue
                                          + "\" is not a valid value for 
initial-page-number");
  @@ -219,68 +216,71 @@
   
           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...
  -            firstAvailPageNumber = this.root.getRunningPageNumberCounter();
  -            boolean tempIsFirstPage = false;
  -
  -            if (thisIsFirstPage) {
  -                tempIsFirstPage = thisIsFirstPage;
  -                if (pageNumberType == AUTO) {
  -                    this.currentPageNumber =
  -                        this.root.getRunningPageNumberCounter();
  -                } else if (pageNumberType == AUTO_ODD) {
  -                    this.currentPageNumber =
  -                        this.root.getRunningPageNumberCounter();
  -                    if (this.currentPageNumber % 2 == 1) {
  -                        this.currentPageNumber++;
  +        PageSequence previousPageSequence=this.root.getPageSequence();
  +        if( previousPageSequence!=null ) {
  +            currentPageNumber = previousPageSequence.currentPageNumber;
  +            if (previousPageSequence.forcePageCount == ForcePageCount.AUTO) {
  +                if (pageNumberType == AUTO_ODD) {
  +                    if (currentPageNumber % 2 == 0) {
  +                        makeBlankPage(areaTree);
  +                    }
  +                } else if (pageNumberType == AUTO_EVEN) {
  +                    if (currentPageNumber % 2 == 1) {
  +                        makeBlankPage(areaTree);
  +                    }
  +                } else if (pageNumberType == EXPLICIT){
  +                    if ((currentPageNumber % 2)
  +                        == (firstPageNumber % 2)) {
  +                        makeBlankPage(areaTree);
  +                    }
  +                    currentPageNumber = firstPageNumber;
  +                }
  +            } else {
  +                if (pageNumberType == AUTO_ODD) {
  +                    if (currentPageNumber % 2 == 0) {
  +                      currentPageNumber++;
                       }
                   } else if (pageNumberType == AUTO_EVEN) {
  -                    this.currentPageNumber =
  -                        this.root.getRunningPageNumberCounter();
  -                    if (this.currentPageNumber % 2 == 0) {
  -                        this.currentPageNumber++;
  +                    if (currentPageNumber % 2 == 1) {
  +                      currentPageNumber++;
                       }
  +                } else if (pageNumberType == EXPLICIT){
  +                    currentPageNumber = firstPageNumber;
                   }
  -                thisIsFirstPage = false;
               }
  -
  -            this.currentPageNumber++;
  -
  -            // deliberately moved down here so page-number calculations
  -            // are complete;
  -            // compute flag for 'blank-or-not-blank'
  +        } else {
  +            currentPageNumber = firstPageNumber;
  +        }
  +        previousPageSequence = null;
  +        this.root.setPageSequence(this);
  +        boolean isFirstPage = true;
  +        int pageCount = 0;
  +        do {
               boolean isEmptyPage = false;
   
  -            if ((status.getCode() == Status.FORCE_PAGE_BREAK_EVEN)
  -                    && ((currentPageNumber % 2) == 1)) {
  -                isEmptyPage = true;
  -            } else if ((status.getCode() == Status.FORCE_PAGE_BREAK_ODD)
  -                       && ((currentPageNumber % 2) == 0)) {
  -                isEmptyPage = true;
  -            } else {
  -                isEmptyPage = false;
  +            // for this calculation we are alreaddy on the
  +            // blank page
  +            if (status.getCode() == Status.FORCE_PAGE_BREAK_EVEN) {
  +                if ((currentPageNumber % 2) == 1) {
  +                   isEmptyPage = true;
  +                } 
  +            } else if (status.getCode() == Status.FORCE_PAGE_BREAK_ODD) {
  +                if ((currentPageNumber % 2) == 0) {
  +                   isEmptyPage = true;
  +                } 
               }
   
  -            currentPage = makePage(areaTree, firstAvailPageNumber,
  -                                   tempIsFirstPage, isEmptyPage);
  +            currentPage = makePage(areaTree, currentPageNumber,
  +                                   isFirstPage, isEmptyPage);
   
               currentPage.setNumber(this.currentPageNumber);
               String formattedPageNumber =
                   pageNumberGenerator.makeFormattedPageNumber(this.currentPageNumber);
               currentPage.setFormattedNumber(formattedPageNumber);
  -            this.root.setRunningPageNumberCounter(this.currentPageNumber);
   
               log.info("[" + currentPageNumber + "]");
   
  -            if ((status.getCode() == Status.FORCE_PAGE_BREAK_EVEN)
  -                && ((currentPageNumber % 2) == 1)) {}
  -            else if ((status.getCode() == Status.FORCE_PAGE_BREAK_ODD)
  -                 && ((currentPageNumber % 2) == 0)) {}
  -            else {
  +            if (!isEmptyPage) {
                   BodyAreaContainer bodyArea = currentPage.getBody();
                   bodyArea.setIDReferences(areaTree.getIDReferences());
   
  @@ -291,26 +291,41 @@
                                              + "in page-master '"
                                              + currentPageMasterName + "'");
                       break;
  -
                   } else {
                       status = flow.layout(bodyArea);
                   }
  -
               }
   
               // 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
  +
  +            this.currentPageNumber++;
  +            pageCount++;    // used for 'force-page-count' calculations
  +            isFirstPage = false;
           }
           while (flowsAreIncomplete());
  -        // handle the 'force-page-count'
  -        forcePage(areaTree, firstAvailPageNumber);
  -
  +        // handle cases of 'force-page-count' which do not depend
  +        // on the presence of a following page sequence
  +        if (this.forcePageCount == ForcePageCount.EVEN) {
  +            if (pageCount % 2 != 0) {
  +                makeBlankPage(areaTree);
  +            }
  +        } else if (this.forcePageCount == ForcePageCount.ODD) {
  +            if (pageCount % 2 != 1) {
  +                makeBlankPage(areaTree);
  +            }
  +        } else if (this.forcePageCount == ForcePageCount.END_ON_EVEN) {
  +            if (currentPageNumber % 2 == 0) {
  +                makeBlankPage(areaTree);
  +            }
  +        } else if (this.forcePageCount == ForcePageCount.END_ON_ODD) {
  +            if (currentPageNumber % 2 == 1) {
  +                makeBlankPage(areaTree);
  +            }
  +        }
           currentPage = null;
       }
   
  @@ -608,10 +623,6 @@
           this.isFlowSet = isFlowSet;
       }
   
  -    public String getIpnValue() {
  -        return ipnValue;
  -    }
  -
       public int getCurrentPageNumber() {
           return currentPageNumber; 
       }
  @@ -620,70 +631,22 @@
        return this.pageCount;
       }
   
  -    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);
  -                currentPage.setPageSequence(this);
  -                formatStaticContent(areaTree);
  -                log.debug("[forced-" + firstAvailPageNumber + "]");
  -                areaTree.addPage(currentPage);
  -                this.root.setRunningPageNumberCounter(this.currentPageNumber);
  -                this.isForcing = false;
  -            } catch (FOPException fopex) {
  -                log.debug("'force-page-count' failure");
  -            }
  +    private void makeBlankPage(AreaTree areaTree) {
  +        try {
  +            this.isForcing = true;
  +            currentPage = makePage(areaTree, currentPageNumber, false,
  +                                   true);
  +            String formattedPageNumber =
  +              pageNumberGenerator.makeFormattedPageNumber(this.currentPageNumber);
  +            currentPage.setFormattedNumber(formattedPageNumber);
  +            currentPage.setPageSequence(this);
  +            formatStaticContent(areaTree);
  +            log.debug("[forced-" + currentPageNumber + "]");
  +            areaTree.addPage(currentPage);
  +            this.isForcing = false;
  +            this.currentPageNumber++;
  +        } catch (FOPException fopex) {
  +            log.debug("'force-page-count' failure");
           }
       }
   
  
  
  
  1.16.2.1  +8 -56     xml-fop/src/org/apache/fop/fo/pagination/Root.java
  
  Index: Root.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/pagination/Root.java,v
  retrieving revision 1.16
  retrieving revision 1.16.2.1
  diff -u -r1.16 -r1.16.2.1
  --- Root.java 21 Aug 2001 08:26:11 -0000      1.16
  +++ Root.java 12 Jul 2002 01:15:33 -0000      1.16.2.1
  @@ -38,12 +38,11 @@
       }
   
       LayoutMasterSet layoutMasterSet;
  -    Vector pageSequences;
  -
       /**
  -     * keeps count of page number from over PageSequence instances
  +     * Store a page sequence over a sequence change. The next sequence will
  +     * get the page number from this and also take care of forced pages.
        */
  -    private int runningPageNumberCounter = 0;
  +    PageSequence pageSequence;
   
       protected Root(FObj parent,
                      PropertyList propertyList) throws FOPException {
  @@ -52,46 +51,17 @@
   
           // this.properties.get("media-usage");
   
  -        pageSequences = new Vector();
  -
           if (parent != null) {
               throw new FOPException("root must be root element");
           }
       }
   
  -    protected int getRunningPageNumberCounter() {
  -        return this.runningPageNumberCounter;
  +    public void setPageSequence(PageSequence pageSequence) {
  +        this.pageSequence=pageSequence;
       }
   
  -    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 PageSequence getPageSequence() {
  +        return this.pageSequence;
       }
   
       public LayoutMasterSet getLayoutMasterSet() {
  @@ -101,22 +71,4 @@
       public void setLayoutMasterSet(LayoutMasterSet layoutMasterSet) {
           this.layoutMasterSet = layoutMasterSet;
       }
  -/*
  -    public void format(AreaTree areaTree) throws FOPException {
  -        // log.debug(" Root[" + marker + "] ");
  -        if (layoutMasterSet == null) {
  -            throw new FOPException("No layout master set.");
  -        }
  -
  -        Enumeration e = children.elements();
  -        while (e.hasMoreElements()) {
  -            Object o = e.nextElement();
  -            if (o instanceof PageSequence) {
  -                ((PageSequence)o).format(areaTree);
  -            } else if (o instanceof ExtensionObj) {
  -                ((ExtensionObj)o).format(areaTree);
  -            }
  -        }
  -    }
  -*/
   }
  
  
  

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

Reply via email to