]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
get some page breaking working
authorKeiron Liddle <keiron@apache.org>
Sun, 11 Aug 2002 07:31:30 +0000 (07:31 +0000)
committerKeiron Liddle <keiron@apache.org>
Sun, 11 Aug 2002 07:31:30 +0000 (07:31 +0000)
properly resets leaf node

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195077 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/layoutmgr/BlockLayoutManager.java
src/org/apache/fop/layoutmgr/FlowLayoutManager.java
src/org/apache/fop/layoutmgr/LayoutContext.java
src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java
src/org/apache/fop/layoutmgr/LineBPLayoutManager.java
src/org/apache/fop/layoutmgr/PageLayoutManager.java

index 85a93b1646fc711924a6122f02e35e82905c3aa2..3b15f5f85dc635faaa5df21def1401133a916a92 100644 (file)
@@ -30,6 +30,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
     int lineHeight = 14000;
     int follow = 2000;
 
+    ArrayList childBreaks = new ArrayList();
+
     public BlockLayoutManager(FObj fobj) {
         super(fobj);
     }
@@ -52,15 +54,6 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
         return curBlockArea.getIPD();
     }
 
-    private static class BlockBreakPosition extends LeafPosition {
-        List blockps;
-
-        BlockBreakPosition(BPLayoutManager lm, int iBreakIndex, List bps) {
-            super(lm, iBreakIndex);
-            blockps = bps;
-        }
-    }
-
     protected BPLayoutManager getChildLM() {
         if (m_curChildLM != null && !m_curChildLM.isFinished()) {
             return m_curChildLM;
@@ -77,7 +70,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
                         inlines.add(lm);
                         //lms.remove(count + 1);
                     } else {
-                        m_childLMiter.previousIndex();
+                        m_childLMiter.previous();
                         break;
                     }
                 }
@@ -106,19 +99,27 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
                                       Position prevLineBP) {
 
         BPLayoutManager curLM ; // currently active LM
-        ArrayList list = new ArrayList();
+
+        MinOptMax stackSize = new MinOptMax();
+        // if starting add space before
+        // stackSize.add(spaceBefore);
 
         while ((curLM = getChildLM()) != null) {
-            // Make break positions and return lines!
+            // Make break positions and return blocks!
             // Set up a LayoutContext
             int ipd = 0;
             BreakPoss bp;
-            ArrayList vecBreakPoss = new ArrayList();
 
             // Force area creation on first call
             // NOTE: normally not necessary when fully integrated!
             LayoutContext childLC =
               new LayoutContext(LayoutContext.CHECK_REF_AREA);
+            if(curLM.generatesInlineAreas()) {
+                // Reset stackLimit for non-first lines
+                childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents*/));
+            } else {
+                childLC.setStackLimit(MinOptMax.subtract(context.getStackLimit(), stackSize));
+            }
 
             while (!curLM.isFinished()) {
                 if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) {
@@ -133,30 +134,54 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
                         ipd = getContentIPD();
                         childLC.flags &= ~LayoutContext.CHECK_REF_AREA;
                         childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents -
-                                                                                                                                                                                                                                                                                     m_iTextIndent*/));
+                                                              m_iTextIndent*/));
                     } else {
-                        vecBreakPoss.add(bp);
+                        stackSize.add(bp.getStackingSize());
+                        if(stackSize.min > context.getStackLimit().max) {
+                            // reset to last break
+                            // curLM.reset();
+                            break;
+                        }
+                        childBreaks.add(bp);
+
+                        if(curLM.generatesInlineAreas()) {
                         // Reset stackLimit for non-first lines
                         childLC.setStackLimit(new MinOptMax(ipd/* - m_iIndents*/));
+                        } else {
+                            childLC.setStackLimit(MinOptMax.subtract(context.getStackLimit(), stackSize));
+                        }
                     }
                 }
             }
-            list.add(vecBreakPoss);
-            return new BreakPoss(
-                     new BlockBreakPosition(curLM, 0, vecBreakPoss));
+            BreakPoss breakPoss = new BreakPoss(
+                     new LeafPosition(this, childBreaks.size() - 1));
+            breakPoss.setStackingSize(stackSize);
+            return breakPoss;
         }
         setFinished(true);
-        return new BreakPoss(new BlockBreakPosition(this, 0, list));
+        return null;
     }
 
-    public void addAreas(PositionIterator parentIter, LayoutContext lc) {
+    public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
 
+        BPLayoutManager childLM ;
+        int iStartPos = 0;
+        LayoutContext lc = new LayoutContext(0);
         while (parentIter.hasNext()) {
-            BlockBreakPosition bbp = (BlockBreakPosition) parentIter.next();
-            bbp.getLM().addAreas( new BreakPossPosIter(bbp.blockps, 0,
-                                  bbp.blockps.size()), null);
+            LeafPosition lfp = (LeafPosition) parentIter.next();
+            // Add the block areas to Area
+            PositionIterator breakPosIter =
+              new BreakPossPosIter(childBreaks, iStartPos,
+                                   lfp.getLeafPos() + 1);
+            iStartPos = lfp.getLeafPos() + 1;
+            while ((childLM = breakPosIter.getNextChildLM()) != null) {
+                childLM.addAreas(breakPosIter, lc);
+            }
         }
+
         flush();
+
+        childBreaks.clear();
     }
 
     /**
@@ -208,48 +233,5 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
         return false;
     }
 
-
-
-    //     /**
-    //      * Called by child LayoutManager when it has filled one of its areas.
-    //      * If no current container, make one.
-    //      * See if the area will fit in the current container.
-    //      * If so, add it.
-    //      * @param childArea the area to add: will either be a LineArea or
-    //      * a BlockArea.
-    //      */
-    //     public void  addChild(Area childArea) {
-    //         /* If the childArea fits entirely in the maximum available BPD
-    //          * add it and return an OK status.
-    //          * If it doesn't all fit, overrun or ask for split?
-    //          * Might as well just add it since the page layout process
-    //          * may need to make other adjustments, resulting in changing
-    //          * split point.
-    //          */
-    //         // Things like breaks on child area can cause premature
-    //         // termination of the current area.
-    //         /* We go past the theoretical maximum to be able to handle things
-    //          * like widows.
-    //          */
-    //         // WARNING: this doesn't take into account space-specifier
-    //         // adujstment between childArea and last content of blockArea!
-    //         if (blockArea.getContentBPD().min + childArea.getAllocationBPD().min
-    //             > blockArea.getAvailBPD().max) {
-    //             if (++extraLines <= iWidows) {
-    //                 blockArea.add(childArea);
-    //             }
-    //             else {
-    //                 blockArea.setIsLast(false);
-    //                 parentLM.addChildArea(blockArea);
-    //                 // Make a new one for this area
-    //                 blockArea = makeAreaForChild(childArea);
-    //                 extraLines = 0; // Count potential widows
-    //                 blockArea.add(childArea);
-    //             }
-    //         }
-    //         else {
-    //             blockArea.add(childArea);
-    //         }
-    //     }
-
 }
+
index 6919a71d5ac6e3227b68ba36d346e6bd509bd410..b3906aaf675a8628c0fbe224b842e9d45a293c96 100644 (file)
@@ -23,14 +23,7 @@ import java.util.List;
  */
 public class FlowLayoutManager extends BlockStackingLayoutManager {
 
-    private static class BlockBreakPosition extends LeafPosition {
-        List blockps;
-
-        BlockBreakPosition(BPLayoutManager lm, int iBreakIndex, List bps) {
-            super(lm, iBreakIndex);
-            blockps = bps;
-        }
-    }
+    ArrayList blockBreaks = new ArrayList();      
 
     /** Array of areas currently being filled stored by area class */
     private BlockParent[] currentAreas = new BlockParent[Area.CLASS_MAX];
@@ -47,40 +40,71 @@ public class FlowLayoutManager extends BlockStackingLayoutManager {
                                       Position prevLineBP) {
 
         BPLayoutManager curLM ; // currently active LM
+        MinOptMax stackSize = new MinOptMax();
 
         while ((curLM = getChildLM()) != null) {
-            // Make break positions and return lines!
+            // Make break positions and return page break
             // Set up a LayoutContext
-            int bpd = 0;
+            MinOptMax bpd = context.getStackLimit();
             BreakPoss bp;
-            ArrayList vecBreakPoss = new ArrayList();
 
-            // Force area creation on first call
-            // NOTE: normally not necessary when fully integrated!
             LayoutContext childLC = new LayoutContext(0);
+            boolean breakPage = false;
+            childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize));
 
-            while (!curLM.isFinished()) {
+            if (!curLM.isFinished()) {
                 if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) {
-                    vecBreakPoss.add(bp);
-                    // Reset stackLimit for non-first lines
-                    childLC.setStackLimit(new MinOptMax(bpd));
+                    stackSize.add(bp.getStackingSize());
+                    blockBreaks.add(bp);
+                    // set stackLimit for remaining space
+                    childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize));
+
+                    if(bp.isForcedBreak()) {
+                        breakPage = true;
+                        break;
+                    }
                 }
             }
 
-            return new BreakPoss(
-                     new BlockBreakPosition(curLM, 0, vecBreakPoss));
+            // check the stack bpd and if greater than available
+            // height then go to the last best break and return
+            // break position
+            if(stackSize.min > context.getStackLimit().opt) {
+                breakPage = true;
+            }
+            if(breakPage) {
+                return new BreakPoss(
+                            new LeafPosition(this, blockBreaks.size() - 1));
+            }
         }
         setFinished(true);
+        if(blockBreaks.size() > 0) {
+            return new BreakPoss(
+                             new LeafPosition(this, blockBreaks.size() - 1));
+        }
         return null;
     }
 
-    public void addAreas(PositionIterator parentIter, LayoutContext lc) {
+    public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
+
+        BPLayoutManager childLM ;
+        int iStartPos = 0;
+        LayoutContext lc = new LayoutContext(0);
         while (parentIter.hasNext()) {
-            BlockBreakPosition bbp = (BlockBreakPosition) parentIter.next();
-            bbp.getLM().addAreas( new BreakPossPosIter(bbp.blockps, 0,
-                                  bbp.blockps.size()), null);
+            LeafPosition lfp = (LeafPosition) parentIter.next();
+            // Add the block areas to Area
+            PositionIterator breakPosIter =
+              new BreakPossPosIter(blockBreaks, iStartPos,
+                                   lfp.getLeafPos() + 1);
+            iStartPos = lfp.getLeafPos() + 1; 
+            while ((childLM = breakPosIter.getNextChildLM()) != null) {
+                childLM.addAreas(breakPosIter, lc);
+            }
         }
+
         flush();
+        // clear the breaks for the page to start for the next page
+        blockBreaks.clear();
     }
 
 
index d095b3fc83b26950b6b98f3c4003acdea72697ee..2ec273ee47492e96f75afedd8084cb28930fbfce 100644 (file)
@@ -149,7 +149,7 @@ public class LayoutContext {
     }
 
     public MinOptMax getStackLimit() {
-        return m_stackLimit ;
+        return m_stackLimit;
     }
 
     public void setHyphContext(HyphContext hyphContext) {
index 0f060d3fb4c08d79da7024ab45312ca7f25dbf56..43cae55ae95dbbc154350b94bbf1f690867d90a0 100644 (file)
@@ -59,7 +59,6 @@ public class LeafNodeLayoutManager extends AbstractBPLayoutManager {
         return false;
     }
 
-
     /**
      * This is a leaf-node, so this method is never called.
      */
@@ -77,12 +76,17 @@ public class LeafNodeLayoutManager extends AbstractBPLayoutManager {
         BreakPoss bp = new BreakPoss(new LeafPosition(this, 0),
                                      BreakPoss.CAN_BREAK_AFTER |
                                      BreakPoss.CAN_BREAK_BEFORE | BreakPoss.ISFIRST |
-                                     BreakPoss.ISLAST | BreakPoss.REST_ARE_SUPPRESS_AT_LB);
+                                     BreakPoss.ISLAST);
         bp.setStackingSize(curArea.getAllocationIPD());
+        bp.setNonStackingSize(curArea.getAllocationBPD());
         setFinished(true);
         return bp;
     }
 
+    public void resetPosition(Position resetPos) {
+        setFinished(false);
+    }
+
     public void addAreas(PositionIterator posIter, LayoutContext context) {
         parentLM.addChild(curArea);
         while (posIter.hasNext()) {
index 489af745927a604bfb76a8b2338e50d5e3e4540d..dfeb56aa31c75da0652c2f0a0034c17695888714 100644 (file)
@@ -437,6 +437,9 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager {
     public void addAreas(PositionIterator parentIter,
                          LayoutContext context) {
         addAreas(parentIter, 0.0);
+
+        //m_vecInlineBreaks.clear();
+        m_prevBP = null;
     }
 
     // Generate and add areas to parent area
@@ -464,8 +467,10 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager {
                 lc.setLeadingSpace(lc.getTrailingSpace());
                 lc.setTrailingSpace(new SpaceSpecifier(false));
             }
+if(lc.getTrailingSpace() != null) {
             addSpace(lineArea, lc.getTrailingSpace().resolve(true),
                      lc.getSpaceAdjust());
+}
             lineArea.verticalAlign(lineHeight, lead, follow);
             parentLM.addChild(lineArea);
         }
index a30e3335bcfc070d3747cb17e3e8cc0f553c0ba2..2fde2b55dee2bc41572324f4a27a628630cb9ef6 100644 (file)
@@ -44,10 +44,11 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab
     /** Number of columns in current span area. */
     private int curSpanColumns;
 
-
     /** Current flow-reference-area (column) being filled. */
     private Flow curFlow;
 
+    private int flowBPD = 0;
+
     /** Manager which handles a queue of all pages which are completely
      * laid out and ready for rendering, except for resolution of ID
      * references?
@@ -82,7 +83,7 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab
 
     public void doLayout() {
 
-        //ArrayList vecBreakPoss = new ArrayList();
+        makeNewPage(false, false);
 
         BreakPoss bp;
         LayoutContext childLC = new LayoutContext(0);
@@ -92,13 +93,13 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab
                 vecBreakPoss.add(bp);
                 addAreas( new BreakPossPosIter(vecBreakPoss, 0,
                                        vecBreakPoss.size()), null);
+                // add static areas and resolve any new id areas
+
+                // finish page and add to area tree
                 finishPage();
             }
         }
 
-        //addAreas( new BreakPossPosIter(vecBreakPoss, 0,
-        //                               vecBreakPoss.size()), null);
-
     }
 
 
@@ -108,16 +109,11 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab
         BPLayoutManager curLM ; // currently active LM
 
         while ((curLM = getChildLM()) != null) {
-            // Make break positions and return lines!
-            // Set up a LayoutContext
-            int bpd = 0;
             BreakPoss bp;
             ArrayList vecBreakPoss = new ArrayList();
 
-            // Force area creation on first call
-            // NOTE: normally not necessary when fully integrated!
             LayoutContext childLC = new LayoutContext(0);
-            childLC.setStackLimit(new MinOptMax(bpd));
+            childLC.setStackLimit(new MinOptMax(flowBPD));
 
             if (!curLM.isFinished()) {
                 if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) {
@@ -218,8 +214,10 @@ getParentArea(area);
         } catch (FOPException fopex) { /* ???? */
             fopex.printStackTrace();
         }
-        curBody = (BodyRegion) curPage.getPage(). getRegion(
-                    RegionReference.BODY).getRegion();
+        RegionViewport reg = curPage.getPage(). getRegion(
+                    RegionReference.BODY);
+        curBody = (BodyRegion) reg.getRegion();
+        flowBPD = (int)reg.getViewArea().getHeight();
         return curPage;
     }