You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/03/20 13:46:11 UTC

cvs commit: xml-fop/src/java/org/apache/fop/render AbstractRenderer.java

jeremias    2005/03/20 04:46:11

  Modified:    src/java/org/apache/fop/layoutmgr Tag:
                        Temp_KnuthStylePageBreaking AbstractBreaker.java
                        BlockContainerLayoutManager.java
                        PageSequenceLayoutManager.java
                        StaticContentLayoutManager.java
                        BlockLayoutManager.java
               src/java/org/apache/fop/area Tag:
                        Temp_KnuthStylePageBreaking MainReference.java
                        BodyRegion.java Span.java
               src/java/org/apache/fop/fo/pagination Tag:
                        Temp_KnuthStylePageBreaking RegionSE.java
                        RegionBA.java
               src/java/org/apache/fop/render Tag:
                        Temp_KnuthStylePageBreaking AbstractRenderer.java
  Added:       src/java/org/apache/fop/fo/pagination Tag:
                        Temp_KnuthStylePageBreaking SideRegion.java
  Removed:     src/java/org/apache/fop/fo/pagination Tag:
                        Temp_KnuthStylePageBreaking RegionOuter.java
  Log:
  Clean-up for accessing column-count and column-gap in area tree.
  Renamed RegionOuter to SideRegion.
  Start for multi-column layout (only plain multi-columns, no spans, no column balancing, yet).
  More consequent use of BlockSequence instead of KnuthSequence in page breaking so the info where a sequence is to be placed (even/odd page...) is easily available.
  Hard breaks now handled under control of the breaker instead of in getParentArea().
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.3   +35 -22    xml-fop/src/java/org/apache/fop/layoutmgr/Attic/AbstractBreaker.java
  
  Index: AbstractBreaker.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/Attic/AbstractBreaker.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- AbstractBreaker.java	18 Mar 2005 13:21:08 -0000	1.1.2.2
  +++ AbstractBreaker.java	20 Mar 2005 12:46:11 -0000	1.1.2.3
  @@ -48,10 +48,7 @@
           }
       }
   
  -    private class BlockSequence extends KnuthSequence {
  -        static final int ANY_PAGE = 0;
  -        static final int ODD_PAGE = 1;
  -        static final int EVEN_PAGE = 2;
  +    public class BlockSequence extends KnuthSequence {
   
           private int startOn;
   
  @@ -59,6 +56,10 @@
               super();
               startOn = iStartOn;
           }
  +        
  +        public int getStartOn() {
  +            return this.startOn;
  +        }
   
           public BlockSequence endBlockSequence() {
               KnuthSequence temp = super.endSequence();
  @@ -88,18 +89,26 @@
       protected abstract void addAreas(PositionIterator posIter, LayoutContext context);
       protected abstract LayoutManager getTopLevelLM();
       protected abstract LayoutManager getCurrentChildLM();
  +    protected abstract LinkedList getNextKnuthElements(LayoutContext context, int alignment);
   
       /** @return true if there's no content that could be handled. */
       public boolean isEmpty() {
           return (blockLists.size() == 0);
       }
       
  +    protected void startPart(BlockSequence list) {
  +        //nop
  +    }
  +    
  +    protected abstract void finishPart();
  +
       protected LayoutContext createLayoutContext() {
           return new LayoutContext(0);
       }
       
       public void doLayout(int flowBPD) {
           LayoutContext childLC = createLayoutContext();
  +        childLC.setStackLimit(new MinOptMax(flowBPD));
   
           //System.err.println("Vertical alignment: " +
           // currentSimplePageMaster.getRegion(FO_REGION_BODY).getDisplayAlign());
  @@ -117,7 +126,7 @@
           System.out.println("PLM> flow BPD =" + flowBPD);
           
           //*** Phase 1: Get Knuth elements ***
  -        int nextSequenceStartsOn = BlockSequence.ANY_PAGE;
  +        int nextSequenceStartsOn = Constants.EN_ANY;
           while (hasMoreContent()) {
               nextSequenceStartsOn = getNextBlockList(childLC, nextSequenceStartsOn, blockLists);
           }
  @@ -129,8 +138,8 @@
               
               //debug code start
               System.err.println("  blockListIndex = " + blockListIndex);
  -            String pagina = (blockList.startOn == BlockSequence.ANY_PAGE) ? "any page"
  -                    : (blockList.startOn == BlockSequence.ODD_PAGE) ? "odd page"
  +            String pagina = (blockList.startOn == Constants.EN_ANY) ? "any page"
  +                    : (blockList.startOn == Constants.EN_ODD_PAGE) ? "odd page"
                               : "even page";
               System.err.println("  sequence starts on " + pagina);
               logBlocklist(blockList);
  @@ -142,7 +151,7 @@
                       alignment, alignmentLast);
               int iOptPageNumber;
   
  -            KnuthSequence effectiveList;
  +            BlockSequence effectiveList;
               if (alignment == Constants.EN_JUSTIFY) {
                   /* justification */
                   effectiveList = justifyBoxes(blockList, alg, flowBPD);
  @@ -171,7 +180,7 @@
        * @param effectiveList effective Knuth element list (after adjustments)
        */
       protected abstract void doPhase3(PageBreakingAlgorithm alg, int partCount, 
  -            KnuthSequence originalList, KnuthSequence effectiveList);
  +            BlockSequence originalList, BlockSequence effectiveList);
       
       /**
        * Phase 3 of Knuth algorithm: Adds the areas 
  @@ -181,20 +190,22 @@
        * @param effectiveList effective Knuth element list (after adjustments)
        */
       protected void addAreas(PageBreakingAlgorithm alg, int partCount, 
  -            KnuthSequence originalList, KnuthSequence effectiveList) {
  +            BlockSequence originalList, BlockSequence effectiveList) {
           LayoutContext childLC;
           // add areas
           ListIterator effectiveListIterator = effectiveList.listIterator();
           int startElementIndex = 0;
           int endElementIndex = 0;
           for (int p = 0; p < partCount; p++) {
  -            int displayAlign = getCurrentDisplayAlign();
  -            
               PageBreakPosition pbp = (PageBreakPosition) alg.getPageBreaks().get(p);
               endElementIndex = pbp.getLeafPos();
  -            System.out.println("PLM> page: " + (p + 1)
  +            System.out.println("PLM> part: " + (p + 1)
                       + ", break at position " + endElementIndex);
   
  +            startPart(effectiveList);
  +            
  +            int displayAlign = getCurrentDisplayAlign();
  +            
               // ignore the first elements added by the
               // PageSequenceLayoutManager
               startElementIndex += (startElementIndex == 0) 
  @@ -271,9 +282,6 @@
               startElementIndex = pbp.getLeafPos() + 1;
           }
       }
  -    protected abstract void finishPart();
  -    
  -    protected abstract LinkedList getNextKnuthElements(LayoutContext context, int alignment);
       
       /**
        * Gets the next block list (sequence) and adds it to a list of block lists if it's not empty.
  @@ -297,15 +305,20 @@
                   switch (breakPenalty.getBreakClass()) {
                   case Constants.EN_PAGE:
                       System.err.println("PLM> break - PAGE");
  -                    nextSequenceStartsOn = BlockSequence.ANY_PAGE;
  +                    nextSequenceStartsOn = Constants.EN_ANY;
  +                    break;
  +                case Constants.EN_COLUMN:
  +                    System.err.println("PLM> break - COLUMN");
  +                    //TODO Fix this when implementing multi-column layout
  +                    nextSequenceStartsOn = Constants.EN_COLUMN;
                       break;
                   case Constants.EN_ODD_PAGE:
                       System.err.println("PLM> break - ODD PAGE");
  -                    nextSequenceStartsOn = BlockSequence.ODD_PAGE;
  +                    nextSequenceStartsOn = Constants.EN_ODD_PAGE;
                       break;
                   case Constants.EN_EVEN_PAGE:
                       System.err.println("PLM> break - EVEN PAGE");
  -                    nextSequenceStartsOn = BlockSequence.EVEN_PAGE;
  +                    nextSequenceStartsOn = Constants.EN_EVEN_PAGE;
                       break;
                   default:
                       throw new IllegalStateException("Invalid break class: " 
  @@ -375,7 +388,7 @@
        * @param availableBPD the available BPD 
        * @return the effective list
        */
  -    private KnuthSequence justifyBoxes(BlockSequence blockList, PageBreakingAlgorithm alg, int availableBPD) {
  +    private BlockSequence justifyBoxes(BlockSequence blockList, PageBreakingAlgorithm alg, int availableBPD) {
           int iOptPageNumber;
           iOptPageNumber = alg.findBreakingPoints(blockList, availableBPD, 1,
                   true, true);
  @@ -532,7 +545,7 @@
           // create a new sequence: the new elements will contain the
           // Positions
           // which will be used in the addAreas() phase
  -        KnuthSequence effectiveList = new KnuthSequence();
  +        BlockSequence effectiveList = new BlockSequence(blockList.getStartOn());
           effectiveList.addAll(getCurrentChildLM().getChangedKnuthElements(
                   blockList.subList(0, blockList.size() - blockList.ignoreAtEnd),
                   /* 0, */0));
  
  
  
  1.36.2.3  +3 -3      xml-fop/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java
  
  Index: BlockContainerLayoutManager.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java,v
  retrieving revision 1.36.2.2
  retrieving revision 1.36.2.3
  diff -u -r1.36.2.2 -r1.36.2.3
  --- BlockContainerLayoutManager.java	18 Mar 2005 13:21:39 -0000	1.36.2.2
  +++ BlockContainerLayoutManager.java	20 Mar 2005 12:46:11 -0000	1.36.2.3
  @@ -470,8 +470,8 @@
           
           //Info for deferred adding of areas
           private PageBreakingAlgorithm deferredAlg;
  -        private KnuthSequence deferredOriginalList;
  -        private KnuthSequence deferredEffectiveList;
  +        private BlockSequence deferredOriginalList;
  +        private BlockSequence deferredEffectiveList;
           
           public BlockContainerBreaker(BlockContainerLayoutManager bclm, MinOptMax ipd) {
               this.bclm = bclm;
  @@ -536,7 +536,7 @@
           }
           
           protected void doPhase3(PageBreakingAlgorithm alg, int partCount, 
  -                KnuthSequence originalList, KnuthSequence effectiveList) {
  +                BlockSequence originalList, BlockSequence effectiveList) {
               //Defer adding of areas until addAreas is called by the parent LM
               this.deferredAlg = alg;
               this.deferredOriginalList = originalList;
  
  
  
  1.50.2.3  +114 -74   xml-fop/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
  
  Index: PageSequenceLayoutManager.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java,v
  retrieving revision 1.50.2.2
  retrieving revision 1.50.2.3
  diff -u -r1.50.2.2 -r1.50.2.3
  --- PageSequenceLayoutManager.java	18 Mar 2005 13:23:08 -0000	1.50.2.2
  +++ PageSequenceLayoutManager.java	20 Mar 2005 12:46:11 -0000	1.50.2.3
  @@ -46,7 +46,7 @@
   import org.apache.fop.fo.pagination.PageSequence;
   import org.apache.fop.fo.pagination.Region;
   import org.apache.fop.fo.pagination.RegionBody;
  -import org.apache.fop.fo.pagination.RegionOuter;
  +import org.apache.fop.fo.pagination.SideRegion;
   import org.apache.fop.fo.pagination.SimplePageMaster;
   import org.apache.fop.fo.pagination.StaticContent;
   import org.apache.fop.fo.properties.CommonMarginBlock;
  @@ -65,6 +65,7 @@
   public class PageSequenceLayoutManager extends AbstractLayoutManager {
       private PageSequence pageSeq;
   
  +    /*
       private static class BlockBreakPosition extends LeafPosition {
           protected BreakPoss breakps;
   
  @@ -72,7 +73,7 @@
               super(lm, 0);
               breakps = bp;
           }
  -    }
  +    }*/
   
   
       private int startPageNum = 0;
  @@ -117,7 +118,7 @@
       //private HashMap staticContentLMs = new HashMap(4);
   
       private FlowLayoutManager childFLM = null;
  -
  +    
       /**
        * Constructor - activated by AreaTreeHandler for each
        * fo:page-sequence in the input FO stream
  @@ -153,7 +154,7 @@
        */
       public void activateLayout() {
           startPageNum = pageSeq.getStartingPageNumber();
  -        currentPageNum = startPageNum;
  +        currentPageNum = startPageNum - 1;
           pageNumberString = pageSeq.makeFormattedPageNumber(currentPageNum);
   
           LineArea title = null;
  @@ -185,11 +186,18 @@
       private class PageBreaker extends AbstractBreaker {
           
           private PageSequenceLayoutManager pslm;
  +        private boolean firstPart = true;
           
           public PageBreaker(PageSequenceLayoutManager pslm) {
               this.pslm = pslm;
           }
           
  +        protected LayoutContext createLayoutContext() {
  +            LayoutContext lc = new LayoutContext(0);
  +            lc.setRefIPD(flowIPD);
  +            return lc;
  +        }
  +        
           protected LayoutManager getTopLevelLM() {
               return pslm;
           }
  @@ -211,18 +219,32 @@
           }
           
           protected void doPhase3(PageBreakingAlgorithm alg, int partCount, 
  -                KnuthSequence originalList, KnuthSequence effectiveList) {
  +                BlockSequence originalList, BlockSequence effectiveList) {
               //Directly add areas after finding the breaks
               addAreas(alg, partCount, originalList, effectiveList);
           }
           
  -        protected void finishPart() {
  +        protected void startPart(BlockSequence list) {
  +            if (curPage == null) {
  +                throw new IllegalStateException("curPage must not be null");
  +            } else {
  +                //firstPart is necessary because we need the first page before we start the 
  +                //algorithm so we have a BPD and IPD. This may subject to change later when we
  +                //start handling more complex cases.
  +                if (!firstPart) {
  +                    if (curSpan.hasMoreAvailableFlows()) {
  +                        curFlow = curSpan.addAdditionalNormalFlow();
  +                    } else {
  +                        handleBreak(list.getStartOn());
  +                    }
  +                }
  +            }
               // add static areas and resolve any new id areas
               // finish page and add to area tree
  -            finishPage();
  -            currentPageNum++;
  -            pageNumberString = pageSeq
  -                    .makeFormattedPageNumber(currentPageNum);
  +            firstPart = false;
  +        }
  +        
  +        protected void finishPart() {
           }
           
           protected LayoutManager getCurrentChildLM() {
  @@ -259,8 +281,8 @@
   /*LF*/      }
   
               LayoutContext childLC = new LayoutContext(0);
  -            childLC.setStackLimit(new MinOptMax(flowBPD));
  -            childLC.setRefIPD(flowIPD);
  +            childLC.setStackLimit(context.getStackLimit());
  +            childLC.setRefIPD(context.getRefIPD());
   
               if (!curLM.isFinished()) {
                   pageSeq.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, flowIPD);
  @@ -419,6 +441,9 @@
       private PageViewport makeNewPage(boolean bIsBlank, boolean bIsLast) {
           finishPage();
   
  +        currentPageNum++;
  +        pageNumberString = pageSeq.makeFormattedPageNumber(currentPageNum);
  +
           try {
               // create a new page
               currentSimplePageMaster = pageSeq.getSimplePageMasterToUse(
  @@ -437,22 +462,34 @@
   
           curPage.setPageNumberString(pageNumberString);
           if (log.isDebugEnabled()) {
  -            log.debug("[" + curPage.getPageNumberString() + "]");
  +            log.debug("[" + curPage.getPageNumberString() + (bIsBlank ? "*" : "") + "]");
           }
   
           flowBPD = (int) curPage.getBodyRegion().getBPD();
  -        createSpan(curPage.getBodyRegion().getColumnCount());
  +        createSpan(curPage.getBodyRegion(), false);
           return curPage;
       }
   
  -    private void createSpan(int numCols) {
  +    /**
  +     * Creates a new span reference area.
  +     * @param bodyRegion The region-body to create the span for
  +     * @param spanned true if a spanned region should be created
  +     */
  +    private void createSpan(BodyRegion bodyRegion, boolean spanned) {
           // get Width or Height as IPD for span
           RegionViewport rv = curPage.getPage().getRegionViewport(FO_REGION_BODY);
           int ipdWidth = (int) rv.getRegion().getIPD() -
               rv.getBorderAndPaddingWidthStart() - rv.getBorderAndPaddingWidthEnd();
   
  -        // currently hardcoding to one column, replace with numCols when ready
  -        curSpan = new Span(1 /* numCols */, ipdWidth);
  +        //TODO currently hardcoding to one column, replace with numCols when ready
  +        if (spanned) {
  +            curSpan = new Span(1, ipdWidth);
  +        } else {
  +            int colWidth 
  +                = (ipdWidth - (bodyRegion.getColumnCount() - 1) * bodyRegion.getColumnGap()) 
  +                    / bodyRegion.getColumnCount();
  +            curSpan = new Span(bodyRegion.getColumnCount(), colWidth);
  +        }
   
           //curSpan.setPosition(BPD, newpos);
           curPage.getBodyRegion().getMainReference().addSpan(curSpan);
  @@ -460,7 +497,7 @@
       }
   
       private void layoutStaticContent(int regionID) {
  -        RegionOuter reg = (RegionOuter)currentSimplePageMaster.getRegion(regionID);
  +        SideRegion reg = (SideRegion)currentSimplePageMaster.getRegion(regionID);
           if (reg == null) {
               return;
           }
  @@ -526,11 +563,61 @@
           layoutStaticContent(FO_REGION_END);
           // Queue for ID resolution and rendering
           areaTreeModel.addPage(curPage);
  +        log.debug("page finished: " + curPage.getPageNumberString() + ", current num: " + currentPageNum);
           curPage = null;
           curSpan = null;
           curFlow = null;
       }
   
  +    private void prepareNormalFlowArea(Area childArea) {
  +        // Need span, break
  +        int breakVal = Constants.EN_AUTO;
  +        Integer breakBefore = (Integer)childArea.getTrait(Trait.BREAK_BEFORE);
  +        if (breakBefore != null) {
  +            breakVal = breakBefore.intValue();
  +        }
  +        if (breakVal != Constants.EN_AUTO) {
  +            // We may be forced to make new page
  +            handleBreak(breakVal);
  +        } else if (curPage == null) {
  +            log.debug("curPage is null. Making new page");
  +            makeNewPage(false, false);
  +        }
  +        // Now we should be on the right kind of page
  +        boolean bNeedNewSpan = false;
  +        /* Determine if a new span is needed.  From the XSL
  +         * fo:region-body definition, if an fo:block has a span="ALL"
  +         * (i.e., span all columns defined for the region-body), it
  +         * must be placed in a span-reference-area whose 
  +         * column-count = 1.  If its span-value is "NONE", 
  +         * place in a normal Span whose column-count is what
  +         * is defined for the region-body. 
  +         */  // temporarily hardcoded to EN_NONE.
  +        int span = Constants.EN_NONE; // childArea.getSpan()
  +        int numColsNeeded;
  +        if (span == Constants.EN_ALL) {
  +            numColsNeeded = 1;
  +        } else { // EN_NONE
  +            numColsNeeded = curPage.getBodyRegion().getColumnCount();
  +        }
  +        if (curSpan == null) {  // should never happen, remove?
  +            bNeedNewSpan = true;
  +        } else if (numColsNeeded != curSpan.getColumnCount()) {
  +            // need a new Span, with numColsNeeded columns
  +            if (curSpan.getColumnCount() > 1) {
  +                // finished with current span, so balance 
  +                // its columns to make them the same "height"
  +                // balanceColumns();  // TODO: implement
  +            }
  +            bNeedNewSpan = true;
  +        }
  +        if (bNeedNewSpan) {
  +            createSpan(curPage.getBodyRegion(), (span == Constants.EN_ALL));
  +        } else if (curFlow == null) {  // should not happen
  +            curFlow = curSpan.addAdditionalNormalFlow();
  +        }
  +    }
  +    
       /**
        * This is called from FlowLayoutManager when it needs to start
        * a new flow container (while generating areas).
  @@ -543,53 +630,8 @@
       public Area getParentArea(Area childArea) {
           int aclass = childArea.getAreaClass();
           if (aclass == Area.CLASS_NORMAL) {
  -            // todo: how to get properties from the Area???
  -            // Need span, break
  -            int breakVal = Constants.EN_AUTO;
  -            Integer breakBefore = (Integer)childArea.getTrait(Trait.BREAK_BEFORE);
  -            if (breakBefore != null) {
  -                breakVal = breakBefore.intValue();
  -            }
  -            if (breakVal != Constants.EN_AUTO) {
  -                // We may be forced to make new page
  -                handleBreak(breakVal);
  -            } else if (curPage == null) {
  -                log.debug("curPage is null. Making new page");
  -                makeNewPage(false, false);
  -            }
  -            // Now we should be on the right kind of page
  -            boolean bNeedNewSpan = false;
  -            /* Determine if a new span is needed.  From the XSL
  -             * fo:region-body definition, if an fo:block has a span="ALL"
  -             * (i.e., span all columns defined for the region-body), it
  -             * must be placed in a span-reference-area whose 
  -             * column-count = 1.  If its span-value is "NONE", 
  -             * place in a normal Span whose column-count is what
  -             * is defined for the region-body. 
  -             */  // temporarily hardcoded to EN_NONE.
  -            int span = Constants.EN_NONE; // childArea.getSpan()
  -            int numColsNeeded;
  -            if (span == Constants.EN_ALL) {
  -                numColsNeeded = 1;
  -            } else { // EN_NONE
  -                numColsNeeded = curPage.getBodyRegion().getColumnCount();
  -            }
  -            if (curSpan == null) {  // should never happen, remove?
  -                bNeedNewSpan = true;
  -            } else if (numColsNeeded != curSpan.getColumnCount()) {
  -                // need a new Span, with numColsNeeded columns
  -                if (curSpan.getColumnCount() > 1) {
  -                    // finished with current span, so balance 
  -                    // its columns to make them the same "height"
  -                    // balanceColumns();  // TODO: implement
  -                }
  -                bNeedNewSpan = true;
  -            }
  -            if (bNeedNewSpan) {
  -                createSpan(numColsNeeded);
  -            } else if (curFlow == null) {  // should not happen
  -                curFlow = curSpan.addAdditionalNormalFlow();
  -            }
  +            //We now do this in PageBreaker
  +            //prepareNormalFlowArea(childArea);
               return curFlow;
           } else {
               if (curPage == null) {
  @@ -625,8 +667,7 @@
        */
       private void handleBreak(int breakVal) {
           if (breakVal == Constants.EN_COLUMN) {
  -            if (curSpan != null
  -                    && curSpan.getNormalFlowCount() < curSpan.getColumnCount()) {
  +            if (curSpan != null && curSpan.hasMoreAvailableFlows()) {
                   // Move to next column
                   curFlow = curSpan.addAdditionalNormalFlow();
                   return;
  @@ -634,6 +675,7 @@
               // else need new page
               breakVal = Constants.EN_PAGE;
           }
  +        log.debug("handling break after page " + currentPageNum + " breakVal=" + breakVal);
           if (needEmptyPage(breakVal)) {
               curPage = makeNewPage(true, false);
           }
  @@ -652,17 +694,15 @@
        */
       private boolean needEmptyPage(int breakValue) {
   
  -        if (breakValue == Constants.EN_PAGE || curPage.getPage().isEmpty()) {
  +        if (breakValue == Constants.EN_PAGE || ((curPage != null) && curPage.getPage().isEmpty())) {
               // any page is OK or we already have an empty page
               return false;
  -        }
  -        else {
  +        } else {
               /* IF we are on the kind of page we need, we'll need a new page. */
               if (currentPageNum % 2 != 0) {
                   // Current page is odd
                   return (breakValue == Constants.EN_ODD_PAGE);
  -            }
  -            else {
  +            } else {
                   return (breakValue == Constants.EN_EVEN_PAGE);
               }
           }
  @@ -676,7 +716,7 @@
               if (breakValue == Constants.EN_PAGE) {
                   return false;
               }
  -            else if (currentPageNum%2 != 0) {
  +            else if (currentPageNum % 2 != 0) {
                   // Current page is odd
                   return (breakValue == Constants.EN_EVEN_PAGE);
               }
  
  
  
  1.8.2.2   +3 -3      xml-fop/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java
  
  Index: StaticContentLayoutManager.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/StaticContentLayoutManager.java,v
  retrieving revision 1.8.2.1
  retrieving revision 1.8.2.2
  diff -u -r1.8.2.1 -r1.8.2.2
  --- StaticContentLayoutManager.java	18 Mar 2005 13:23:08 -0000	1.8.2.1
  +++ StaticContentLayoutManager.java	20 Mar 2005 12:46:11 -0000	1.8.2.2
  @@ -22,7 +22,7 @@
   import org.apache.fop.area.Area;
   import org.apache.fop.area.Block;
   import org.apache.fop.fo.pagination.Region;
  -import org.apache.fop.fo.pagination.RegionOuter;
  +import org.apache.fop.fo.pagination.SideRegion;
   import org.apache.fop.fo.pagination.StaticContent;
   import org.apache.fop.traits.MinOptMax;
   
  @@ -233,7 +233,7 @@
           log.error("Cannot add marker to static areas");
       }
       
  -    public void doLayout(RegionOuter region, StaticContentLayoutManager lm, MinOptMax ipd) {
  +    public void doLayout(SideRegion region, StaticContentLayoutManager lm, MinOptMax ipd) {
           StaticContentBreaker breaker = new StaticContentBreaker(region, lm, ipd);
           breaker.doLayout(lm.getRegionReference().getBPD());
           if (breaker.isOverflow()) {
  @@ -306,7 +306,7 @@
           }
           
           protected void doPhase3(PageBreakingAlgorithm alg, int partCount, 
  -                KnuthSequence originalList, KnuthSequence effectiveList) {
  +                BlockSequence originalList, BlockSequence effectiveList) {
               //Directly add areas after finding the breaks
               addAreas(alg, partCount, originalList, effectiveList);
               if (partCount > 1) {
  
  
  
  1.43.2.2  +3 -2      xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
  
  Index: BlockLayoutManager.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java,v
  retrieving revision 1.43.2.1
  retrieving revision 1.43.2.2
  diff -u -r1.43.2.1 -r1.43.2.2
  --- BlockLayoutManager.java	18 Mar 2005 09:02:55 -0000	1.43.2.1
  +++ BlockLayoutManager.java	20 Mar 2005 12:46:11 -0000	1.43.2.2
  @@ -1310,6 +1310,9 @@
           if (curBlockArea == null) {
               curBlockArea = new Block();
   
  +            TraitSetter.addBreaks(curBlockArea, 
  +                    fobj.getBreakBefore(), fobj.getBreakAfter());
  +
               // Must get dimensions from parent area
               //Don't optimize this line away. It can have ugly side-effects.
               /*Area parentArea =*/ parentLM.getParentArea(curBlockArea);
  @@ -1322,8 +1325,6 @@
               TraitSetter.addMargins(curBlockArea,
                       fobj.getCommonBorderPaddingBackground(), 
                       fobj.getCommonMarginBlock());
  -            TraitSetter.addBreaks(curBlockArea, 
  -                    fobj.getBreakBefore(), fobj.getBreakAfter());
   
               // Set up dimensions
               // Get reference IPD from parentArea
  
  
  
  No                   revision
  No                   revision
  1.5.2.1   +11 -8     xml-fop/src/java/org/apache/fop/area/MainReference.java
  
  Index: MainReference.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/MainReference.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- MainReference.java	11 Mar 2005 07:23:43 -0000	1.5
  +++ MainReference.java	20 Mar 2005 12:46:11 -0000	1.5.2.1
  @@ -28,15 +28,17 @@
    * See fo:region-body definition in the XSL Rec for more information.
    */
   public class MainReference extends Area {
  +
  +    private BodyRegion parent;
       private List spanAreas = new java.util.ArrayList();
  -    private int columnGap;
       private int width;
       private boolean isEmpty = true;
   
       /**
        * Constructor
        */
  -    public MainReference() {
  +    public MainReference(BodyRegion parent) {
  +        this.parent = parent;
           addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
       }
         
  @@ -86,13 +88,14 @@
           return isEmpty;
       }
   
  -    /**
  -     * Get the column gap in millipoints.
  -     *
  -     * @return the column gap in millipoints
  -     */
  +    /** @return the number of columns */
  +    public int getColumnCount() {
  +        return parent.getColumnCount();
  +    }
  +
  +    /** @return the column gap in millipoints */
       public int getColumnGap() {
  -        return columnGap;
  +        return parent.getColumnGap();
       }
   
       /**
  
  
  
  1.12.2.1  +6 -10     xml-fop/src/java/org/apache/fop/area/BodyRegion.java
  
  Index: BodyRegion.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/BodyRegion.java,v
  retrieving revision 1.12
  retrieving revision 1.12.2.1
  diff -u -r1.12 -r1.12.2.1
  --- BodyRegion.java	14 Mar 2005 01:34:26 -0000	1.12
  +++ BodyRegion.java	20 Mar 2005 12:46:11 -0000	1.12.2.1
  @@ -41,7 +41,7 @@
       public BodyRegion() {
           super(Constants.FO_REGION_BODY);
           addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
  -        mainReference = new MainReference();
  +        mainReference = new MainReference(this);
       }
   
       /**
  @@ -89,6 +89,11 @@
           this.columnGap = colGap;
       }
   
  +    /** @return the column-gap value */
  +    public int getColumnGap() {
  +        return this.columnGap;
  +    }
  +    
       /**
        * Set the before float area.
        *
  @@ -99,15 +104,6 @@
       }
   
       /**
  -     * Set the main reference area.
  -     *
  -     * @param mr the main reference area
  -     */
  -    public void setMainReference(MainReference mr) {
  -        mainReference = mr;
  -    }
  -
  -    /**
        * Set the footnote area.
        *
        * @param foot the footnote area
  
  
  
  1.6.2.1   +13 -2     xml-fop/src/java/org/apache/fop/area/Span.java
  
  Index: Span.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/Span.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- Span.java	16 Mar 2005 02:38:12 -0000	1.6
  +++ Span.java	20 Mar 2005 12:46:11 -0000	1.6.2.1
  @@ -54,7 +54,7 @@
        * @return the newly made NormalFlow object
        */
       public NormalFlow addAdditionalNormalFlow() {
  -        if (flowAreas.size() >= columnCount) { // internal error
  +        if (!hasMoreAvailableFlows()) { // internal error
               throw new IllegalStateException("Maximum number of flow areas (" +
                       columnCount + ") for this span reached.");
           }
  @@ -98,7 +98,18 @@
        * @return the flow area for the requested column
        */
       public NormalFlow getNormalFlow(int columnNumber) {
  -        return (NormalFlow) flowAreas.get(columnNumber);
  +        if (columnNumber < flowAreas.size()) {
  +            return (NormalFlow) flowAreas.get(columnNumber);
  +        } else {
  +            return null;
  +        }
  +    }
  +
  +    /**
  +     * @return true if this span can provide additional flow areas.
  +     */
  +    public boolean hasMoreAvailableFlows() {
  +        return (getNormalFlowCount() < getColumnCount());
       }
   
   }
  
  
  
  No                   revision
  No                   revision
  1.19.2.2  +1 -1      xml-fop/src/java/org/apache/fop/fo/pagination/RegionSE.java
  
  Index: RegionSE.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/RegionSE.java,v
  retrieving revision 1.19.2.1
  retrieving revision 1.19.2.2
  diff -u -r1.19.2.1 -r1.19.2.2
  --- RegionSE.java	18 Mar 2005 13:19:50 -0000	1.19.2.1
  +++ RegionSE.java	20 Mar 2005 12:46:11 -0000	1.19.2.2
  @@ -28,7 +28,7 @@
   /**
    * Abstract base class for fo:region-start and fo:region-end.
    */
  -public abstract class RegionSE extends RegionOuter {
  +public abstract class RegionSE extends SideRegion {
       // The value of properties relevant for fo:region-[start|end].
       // End of property values
   
  
  
  
  1.25.2.2  +1 -1      xml-fop/src/java/org/apache/fop/fo/pagination/RegionBA.java
  
  Index: RegionBA.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/RegionBA.java,v
  retrieving revision 1.25.2.1
  retrieving revision 1.25.2.2
  diff -u -r1.25.2.1 -r1.25.2.2
  --- RegionBA.java	18 Mar 2005 13:19:50 -0000	1.25.2.1
  +++ RegionBA.java	20 Mar 2005 12:46:11 -0000	1.25.2.2
  @@ -28,7 +28,7 @@
   /**
    * Abstract base class for fo:region-before and fo:region-after.
    */
  -public abstract class RegionBA extends RegionOuter {
  +public abstract class RegionBA extends SideRegion {
       // The value of properties relevant for fo:region-[before|after].
       private int precedence;
       // End of property values
  
  
  
  No                   revision
  
  Index: RegionBA.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/RegionBA.java,v
  retrieving revision 1.25.2.1
  retrieving revision 1.25.2.2
  diff -u -r1.25.2.1 -r1.25.2.2
  --- RegionBA.java	18 Mar 2005 13:19:50 -0000	1.25.2.1
  +++ RegionBA.java	20 Mar 2005 12:46:11 -0000	1.25.2.2
  @@ -28,7 +28,7 @@
   /**
    * Abstract base class for fo:region-before and fo:region-after.
    */
  -public abstract class RegionBA extends RegionOuter {
  +public abstract class RegionBA extends SideRegion {
       // The value of properties relevant for fo:region-[before|after].
       private int precedence;
       // End of property values
  
  
  
  No                   revision
  
  Index: RegionBA.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/RegionBA.java,v
  retrieving revision 1.25.2.1
  retrieving revision 1.25.2.2
  diff -u -r1.25.2.1 -r1.25.2.2
  --- RegionBA.java	18 Mar 2005 13:19:50 -0000	1.25.2.1
  +++ RegionBA.java	20 Mar 2005 12:46:11 -0000	1.25.2.2
  @@ -28,7 +28,7 @@
   /**
    * Abstract base class for fo:region-before and fo:region-after.
    */
  -public abstract class RegionBA extends RegionOuter {
  +public abstract class RegionBA extends SideRegion {
       // The value of properties relevant for fo:region-[before|after].
       private int precedence;
       // End of property values
  
  
  
  1.1.2.1   +49 -0     xml-fop/src/java/org/apache/fop/fo/pagination/Attic/SideRegion.java
  
  
  
  
  No                   revision
  No                   revision
  1.43.2.1  +10 -5     xml-fop/src/java/org/apache/fop/render/AbstractRenderer.java
  
  Index: AbstractRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/AbstractRenderer.java,v
  retrieving revision 1.43
  retrieving revision 1.43.2.1
  diff -u -r1.43 -r1.43.2.1
  --- AbstractRenderer.java	11 Mar 2005 07:23:43 -0000	1.43
  +++ AbstractRenderer.java	20 Mar 2005 12:46:11 -0000	1.43.2.1
  @@ -374,19 +374,24 @@
   
           Span span = null;
           List spans = mr.getSpans();
  +        int saveBPPos = currentBPPosition;
           for (int count = 0; count < spans.size(); count++) {
               span = (Span) spans.get(count);
               int offset = (mr.getWidth()
  -                    - (span.getColumnCount() - 1) * mr.getColumnGap())
  -                    / span.getColumnCount() + mr.getColumnGap();
  +                    - (mr.getColumnCount() - 1) * mr.getColumnGap())
  +                    / mr.getColumnCount() + mr.getColumnGap();
               for (int c = 0; c < span.getColumnCount(); c++) {
                   NormalFlow flow = (NormalFlow) span.getNormalFlow(c);
   
  -                renderFlow(flow);
  -                currentIPPosition += offset;
  +                if (flow != null) {
  +                    currentBPPosition = saveBPPos;
  +                    renderFlow(flow);
  +                    currentIPPosition += flow.getIPD();
  +                    currentIPPosition += offset;
  +                }
               }
               currentIPPosition = saveIPPos;
  -            currentBPPosition += span.getHeight();
  +            currentBPPosition = saveBPPos + span.getHeight();
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Re: cvs commit: xml-fop/src/java/org/apache/fop/render AbstractRenderer.java

Posted by Jeremias Maerki <de...@greenmail.ch>.
Over all, this sounds ok. There's one point, though: the one with the
column balancing. Following XP principles I'd skip that because I'm
almost sure that we can't implement column balancing just by calling a
balanceColumns() method like your foresee. Don't try to do too many
optimizations too soon as we're currently in "rough mode" (in the branch).

On 23.03.2005 00:22:44 Glen Mazza wrote:
> --- jeremias@apache.org wrote:
> >
> >   -    private void createSpan(int numCols) {
> >   +    /**
> >   +     * Creates a new span reference area.
> >   +     * @param bodyRegion The region-body to
> > create the span for
> >   +     * @param spanned true if a spanned region
> > should be created
> >   +     */
> >   +    private void createSpan(BodyRegion
> > bodyRegion, boolean spanned) {
> 
> 
> Jeremias, I would like to move the initialization of
> the Span's columns/normal-flow-reference-areas to the
> Span class directly.  The Span constructor will take
> three parameters: #columns, column gap, and totalIPD,
> instead of its current two, and automatically make
> those columns/NFRAs using the calculations you have
> here in PSLM.
> 
> As a result, we will no longer be creating the
> n-f-r-a's within PSLM directly (no more
> Span.addAdditionalNormalFlow() calls) because they
> will all be created by Span at one time.  When one
> column is finished, we just have curFlow point to the
> next one in the Span.
> 
> Next, within PSLM, instead of a curFlow variable, we
> have a int curFlowIdx variable that points to the
> zero-based column within the Span currently being
> filled.  i.e.,
> curSpan.getNormalFlow/Column(curFlowIdx).  This
> reduces the chances of curFlow accidentally pointing
> to a different Span object's columns.  curFlowIdx
> would get incremented each time a column is filled,
> and when done a new page is created (or the
> page-breaking strategy is activated, etc.)
> 
> [I have one more method I would like to add in Span,
> public int balanceColumns(), which will be eventually
> called by PSLM whenever column balancing needs to be
> done (e.g., a new block-area with span traits
> indicating a new Span is needed), and would perhaps
> return the new, smaller, bpd as a result of the
> balancing.  It will stay empty for some time, but PSLM
> can call it and PSLM at least will be finished in this
> regard.]
> 
> Once this is done, I would like to modify
> MainReference so that it always has one span by
> default.  90% of the time that one span is all that is
> needed.  PSLM().addSpan(BR, spanned) (to become
> BodyRegion/MainReference.addSpan(boolean spanned)
> perhaps), would be called only for new spans needed as
> a result of an incoming block-area's span trait
> needing a different number of columns (either one or
> BR.getColumnCount()).  But the changes in this
> paragraph I would revisit after the Span issues above
> are finished.
> 
> Basically, the change would be that PSLM will still
> handle the page-breaking, the flow-mapping, the
> collection of areas and determination of (1) when new
> spans are needed, (2) when curFlowIdx needs to be
> incremented to the next column, and (3) when columns
> in a span need to be balanced; however:  the actual
> *creating* of n-f-r-a's, spans, and column balancing
> will move to Span and BodyRegion/MainReference as
> appropriate.
> 
> Thoughts?
> 
> Thanks,
> Glen 



Jeremias Maerki


Re: cvs commit: xml-fop/src/java/org/apache/fop/render AbstractRenderer.java

Posted by Glen Mazza <gr...@yahoo.com>.
--- jeremias@apache.org wrote:
>
>   -    private void createSpan(int numCols) {
>   +    /**
>   +     * Creates a new span reference area.
>   +     * @param bodyRegion The region-body to
> create the span for
>   +     * @param spanned true if a spanned region
> should be created
>   +     */
>   +    private void createSpan(BodyRegion
> bodyRegion, boolean spanned) {


Jeremias, I would like to move the initialization of
the Span's columns/normal-flow-reference-areas to the
Span class directly.  The Span constructor will take
three parameters: #columns, column gap, and totalIPD,
instead of its current two, and automatically make
those columns/NFRAs using the calculations you have
here in PSLM.

As a result, we will no longer be creating the
n-f-r-a's within PSLM directly (no more
Span.addAdditionalNormalFlow() calls) because they
will all be created by Span at one time.  When one
column is finished, we just have curFlow point to the
next one in the Span.

Next, within PSLM, instead of a curFlow variable, we
have a int curFlowIdx variable that points to the
zero-based column within the Span currently being
filled.  i.e.,
curSpan.getNormalFlow/Column(curFlowIdx).  This
reduces the chances of curFlow accidentally pointing
to a different Span object's columns.  curFlowIdx
would get incremented each time a column is filled,
and when done a new page is created (or the
page-breaking strategy is activated, etc.)

[I have one more method I would like to add in Span,
public int balanceColumns(), which will be eventually
called by PSLM whenever column balancing needs to be
done (e.g., a new block-area with span traits
indicating a new Span is needed), and would perhaps
return the new, smaller, bpd as a result of the
balancing.  It will stay empty for some time, but PSLM
can call it and PSLM at least will be finished in this
regard.]

Once this is done, I would like to modify
MainReference so that it always has one span by
default.  90% of the time that one span is all that is
needed.  PSLM().addSpan(BR, spanned) (to become
BodyRegion/MainReference.addSpan(boolean spanned)
perhaps), would be called only for new spans needed as
a result of an incoming block-area's span trait
needing a different number of columns (either one or
BR.getColumnCount()).  But the changes in this
paragraph I would revisit after the Span issues above
are finished.

Basically, the change would be that PSLM will still
handle the page-breaking, the flow-mapping, the
collection of areas and determination of (1) when new
spans are needed, (2) when curFlowIdx needs to be
incremented to the next column, and (3) when columns
in a span need to be balanced; however:  the actual
*creating* of n-f-r-a's, spans, and column balancing
will move to Span and BodyRegion/MainReference as
appropriate.

Thoughts?

Thanks,
Glen