]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
start of spacing and borders
authorKeiron Liddle <keiron@apache.org>
Wed, 18 Sep 2002 14:15:05 +0000 (14:15 +0000)
committerKeiron Liddle <keiron@apache.org>
Wed, 18 Sep 2002 14:15:05 +0000 (14:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195226 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/layoutmgr/BlockLayoutManager.java
src/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
src/org/apache/fop/layoutmgr/FlowLayoutManager.java
src/org/apache/fop/layoutmgr/InlineStackingLayoutManager.java
src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java
src/org/apache/fop/layoutmgr/LineLayoutManager.java
src/org/apache/fop/layoutmgr/PageLayoutManager.java
src/org/apache/fop/layoutmgr/table/Body.java
src/org/apache/fop/layoutmgr/table/Cell.java
src/org/apache/fop/layoutmgr/table/TableLayoutManager.java

index ec6e58c18c0d1738fbd274c5c14088bd63f785ad..280963eb4cd2017374d59f7ac75e980678634d69 100644 (file)
@@ -9,11 +9,18 @@ package org.apache.fop.layoutmgr;
 
 import org.apache.fop.fo.FObj;
 import org.apache.fop.fo.TextInfo;
+import org.apache.fop.fo.PropertyManager;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.BlockParent;
 import org.apache.fop.area.Block;
 import org.apache.fop.area.LineArea;
 import org.apache.fop.area.MinOptMax;
+import org.apache.fop.area.Trait;
+import org.apache.fop.traits.LayoutProps;
+import org.apache.fop.layout.BorderAndPadding;
+import org.apache.fop.layout.BackgroundProps;
+import org.apache.fop.traits.SpaceVal;
+import org.apache.fop.traits.BorderProps;
 
 import java.util.ListIterator;
 import java.util.ArrayList;
@@ -26,6 +33,10 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
 
     private Block curBlockArea;
 
+    LayoutProps layoutProps;
+    BorderAndPadding borderProps;
+    BackgroundProps backgroundsPops;
+
     int lead = 12000;
     int lineHeight = 14000;
     int follow = 2000;
@@ -96,12 +107,23 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
         lineHeight = ti.lineHeight;
     }
 
+    /**
+     * This method provides a hook for a LayoutManager to intialize traits
+     * for the areas it will create, based on Properties set on its FO.
+     */
+    protected void initProperties(PropertyManager pm) {
+        layoutProps = pm.getLayoutProps();
+        borderProps = pm.getBorderAndPadding();
+        backgroundsPops = pm.getBackgroundProps();
+    }
+    
     public BreakPoss getNextBreakPoss(LayoutContext context) {
         LayoutManager curLM ; // currently active LM
 
         MinOptMax stackSize = new MinOptMax();
         // if starting add space before
-        // stackSize.add(spaceBefore);
+        stackSize.add(layoutProps.spaceBefore.space);
+
         BreakPoss lastPos = null;
 
         while ((curLM = getChildLM()) != null) {
@@ -127,7 +149,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
             while (!curLM.isFinished()) {
                 if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
                     stackSize.add(bp.getStackingSize());
-                    if (stackSize.min > context.getStackLimit().max) {
+                    if (stackSize.opt > context.getStackLimit().max) {
                         // reset to last break
                         if (lastPos != null) {
                             reset(lastPos.getPosition());
@@ -148,6 +170,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
                     }
                 }
             }
+            if(getChildLM() == null) {
+                stackSize.add(layoutProps.spaceAfter.space);
+            }
             BreakPoss breakPoss = new BreakPoss(
                                     new LeafPosition(this, childBreaks.size() - 1));
             breakPoss.setStackingSize(stackSize);
@@ -160,6 +185,11 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
     public void addAreas(PositionIterator parentIter,
                          LayoutContext layoutContext) {
         getParentArea(null);
+
+        // if adjusted space before
+        double adjust = layoutContext.getSpaceAdjust();
+        addBlockSpacing(adjust, layoutProps.spaceBefore.space);
+
         addID();
 
         LayoutManager childLM ;
@@ -179,6 +209,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
 
         flush();
 
+        // if adjusted space after
+        addBlockSpacing(adjust, layoutProps.spaceAfter.space);
+
         childBreaks.clear();
         curBlockArea = null;
     }
@@ -196,6 +229,10 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
     public Area getParentArea(Area childArea) {
         if (curBlockArea == null) {
             curBlockArea = new Block();
+
+            // set traits
+            addBorders(curBlockArea);
+
             // Set up dimensions
             // Must get dimensions from parent area
             Area parentArea = parentLM.getParentArea(curBlockArea);
@@ -207,6 +244,32 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
         return curBlockArea;
     }
 
+    public void addBorders(Block curBlockArea) {
+        BorderProps bps = getBorderProps(BorderAndPadding.TOP);
+        if(bps.width != 0) {
+            curBlockArea.addTrait(Trait.BORDER_START, bps);
+        }
+        bps = getBorderProps(BorderAndPadding.BOTTOM);
+        if(bps.width != 0) {
+            curBlockArea.addTrait(Trait.BORDER_END, bps);
+        }
+        bps = getBorderProps(BorderAndPadding.LEFT);
+        if(bps.width != 0) {
+            curBlockArea.addTrait(Trait.BORDER_BEFORE, bps);
+        }
+        bps = getBorderProps(BorderAndPadding.RIGHT);
+        if(bps.width != 0) {
+            curBlockArea.addTrait(Trait.BORDER_AFTER, bps);
+        }
+    }
+
+    private BorderProps getBorderProps(int side) {
+        BorderProps bps;
+        bps = new BorderProps(borderProps.getBorderStyle(side),
+                              borderProps.getBorderWidth(side, false),
+                              borderProps.getBorderColor(side));
+        return bps;
+    }
 
     public boolean addChild(Area childArea) {
         if (curBlockArea != null) {
index 2495009314b1e7fdc8bffc499450ae933f8a26e6..7c8fba848862fc3192b8af334b2164dec5bdda0b 100644 (file)
@@ -58,6 +58,27 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager {
         return spaceSpec.resolve(false);
     }
 
+    /**
+     * Add a block spacer for space before and space after a block.
+     * This adds an empty Block area that acts as a block space.
+     *
+     * @param adjust the adjustment value
+     * @param minoptmax the min/opt/max value of the spacing
+     */
+    public void addBlockSpacing(double adjust, MinOptMax minoptmax) {
+        int sp = minoptmax.opt;
+        if(adjust > 0) {
+            sp = sp + (int)(adjust * (minoptmax.max - minoptmax.opt));
+        } else {
+            sp = sp + (int)(adjust * (minoptmax.opt - minoptmax.min));
+        }
+        if(sp != 0) {
+            Block spacer = new Block();
+            spacer.setHeight(sp);
+            parentLM.addChild(spacer);
+        }
+    }
+
     /**
      * Add the childArea to the passed area.
      * Called by child LayoutManager when it has filled one of its areas.
@@ -77,14 +98,14 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager {
 
         // See if the whole thing fits, including space before
         // Calculate space between last child in curFlow and childArea
-        MinOptMax targetDim = parentArea.getAvailBPD();
+        //MinOptMax targetDim = parentArea.getAvailBPD();
         MinOptMax spaceBefore = resolveSpaceSpecifier(childArea);
-        targetDim.subtract(spaceBefore);
-        if (targetDim.max >= childArea.getAllocationBPD().min) {
+        //targetDim.subtract(spaceBefore);
+        //if (targetDim.max >= childArea.getAllocationBPD().min) {
             //parentArea.addBlock(new InterBlockSpace(spaceBefore));
-            parentArea.addBlock((Block) childArea);
-            return false;
-        } else {
+        //    parentArea.addBlock((Block) childArea);
+        //    return false;
+        //} else {
             parentArea.addBlock((Block) childArea);
             flush(); // hand off current area to parent
             // Probably need something like max BPD so we don't get into
@@ -104,7 +125,7 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager {
             //addChild(splitContext.nextArea);
             //addChild(childArea);
             return true;
-        }
+        //}
     }
 
 
index 4d4dc0e02a6822a1377a222ca9a6d6418af2cf0d..7ef5044819f09577f6db347ae12cc19095329cd2 100644 (file)
@@ -75,12 +75,12 @@ public class FlowLayoutManager extends BlockStackingLayoutManager {
             // 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) {
+            if(stackSize.opt > context.getStackLimit().opt) {
                 breakPage = true;
             }
             if(breakPage) {
                 return new BreakPoss(
-                            new LeafPosition(this, blockBreaks.size() - 1));
+                      new LeafPosition(this, blockBreaks.size() - 1));
             }
         }
         setFinished(true);
index 8616353e577a4bc963e3cd3f6d58685fde685dfd..4788edf9cc3bdd75b7cbd2d67b1f6803c3f14551 100644 (file)
@@ -447,7 +447,9 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager {
             context.setTrailingSpace(getContext().getTrailingSpace());
         }
         // Add own trailing space to parent context (or set on area?)
-        context.getTrailingSpace().addSpace(m_inlineProps.spaceEnd);
+        if(context.getTrailingSpace() != null) {
+            context.getTrailingSpace().addSpace(m_inlineProps.spaceEnd);
+        }
 
         // Add border and padding to current area and set flags (FIRST, LAST ...)
         TraitSetter.setBorderPaddingTraits(getCurrentArea(),
@@ -511,5 +513,5 @@ public class InlineStackingLayoutManager extends AbstractLayoutManager {
         }
     }
 
-
 }
+
index c24b99a7835d9cbaddf6bb571c4a9236e086328d..17df76309b1e48c246cf8150c534a031243cd09c 100644 (file)
@@ -128,7 +128,7 @@ public class LeafNodeLayoutManager extends AbstractLayoutManager {
                                      | BreakPoss.ISLAST);
         ipd = getAllocationIPD(context.getRefIPD());
         bp.setStackingSize(ipd);
-        bp.setNonStackingSize(curArea.getAllocationBPD());
+        bp.setNonStackingSize(new MinOptMax(curArea.getHeight()));
         bp.setTrailingSpace(new SpaceSpecifier(false));
 
         int bpd = curArea.getHeight();
index 81e9839001adc2eacad2158657052760dd0cc8a9..36b798d5994ecc4cdcb91e01caac5cd3ff973b44 100644 (file)
@@ -166,7 +166,8 @@ public class LineLayoutManager extends InlineStackingLayoutManager {
                 if (bBreakOK) {
                     /* Add any non-conditional trailing space, assuming we
                      * end the line here. If we can't break here, we just
-                     * check if the content fits. */
+                     * check if the content fits.
+                     */
                     bpDim.add(bp.resolveTrailingSpace(true));
                 }
                 // TODO: stop if linebreak is forced (NEWLINE)
index c22bc589e5482adc17dbfb6890c39b08c639e96f..b1d3e3cba29cfc9c529546a5ade9f78f759e4116 100644 (file)
@@ -60,7 +60,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
     private AreaTree areaTree;
     private PageSequence pageSequence;
 
-    private int pageCount = 0;
+    private int pageCount = 1;
 
     /**
      * This is the top level layout manager.
@@ -98,7 +98,6 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
         BreakPoss bp;
         LayoutContext childLC = new LayoutContext(0);
         while (!isFinished()) {
-            pageCount++;
             if ((bp = getNextBreakPoss(childLC)) != null) {
                 addAreas((BlockBreakPosition)bp.getPosition());
                 // add static areas and resolve any new id areas
@@ -106,6 +105,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
                 // finish page and add to area tree
                 finishPage();
             }
+            pageCount++;
         }
 
     }
@@ -214,14 +214,14 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
         // Alternatively the child LM indicates to parent that it's full?
         //System.out.println("size: " + area.getAllocationBPD().max +
         //                   ":" + curSpan.getMaxBPD().min);
-        if (area.getAllocationBPD().max >= curSpan.getMaxBPD().min) {
+        /*if (area.getAllocationBPD().max >= curSpan.getMaxBPD().min) {
             // Consider it filled
             if (curSpan.getColumnCount() == curSpanColumns) {
                 finishPage();
                 return true;
             } else
                 curFlow = null; // Create new flow on next getParentArea()
-        }
+        }*/
         return false;
     }
 
index 902c14bea123766822bb310d2fe6dd1d6e345d23..ff69e1d0518bbe1150882c23ba75030d78cbd5dd 100644 (file)
@@ -146,11 +146,13 @@ public class Body extends BlockStackingLayoutManager {
               new BreakPossPosIter(childBreaks, iStartPos,
                                    lfp.getLeafPos() + 1);
             iStartPos = lfp.getLeafPos() + 1;
+            int lastheight = 0;
             while ((childLM = (Row)breakPosIter.getNextChildLM()) != null) {
                 childLM.setYOffset(yoffset + rowoffset);
                 childLM.addAreas(breakPosIter, lc);
-                rowoffset += childLM.getRowHeight();
+                lastheight = childLM.getRowHeight();
             }
+            rowoffset += lastheight;
         }
         bodyHeight = rowoffset;
 
index 57dd6b2cfe492171bab194656d12a6abc25e27b7..4f0ed25ba0703166152b6b8cf8c283b4e876a1c6 100644 (file)
@@ -63,6 +63,11 @@ public class Cell extends BlockStackingLayoutManager {
         cellIPD = context.getRefIPD();
 
         while ((curLM = getChildLM()) != null) {
+            if(curLM.generatesInlineAreas()) {
+                // error
+                curLM.setFinished(true);
+                continue;
+            }
             // Set up a LayoutContext
             int ipd = context.getRefIPD();
             BreakPoss bp;
index 9dda2869712b4f43863ced7bf6871f812442c220..70840a629a35712a9c4ec4114d138a27f701a89e 100644 (file)
@@ -131,7 +131,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager {
             while (!curLM.isFinished()) {
                 if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
                     stackSize.add(bp.getStackingSize());
-                    if (stackSize.min > context.getStackLimit().max) {
+                    if (stackSize.opt > context.getStackLimit().max) {
                         // reset to last break
                         if (lastPos != null) {
                             reset(lastPos.getPosition());