]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Space and conditional length handling on fo:table.
authorJeremias Maerki <jeremias@apache.org>
Tue, 18 Oct 2005 08:05:29 +0000 (08:05 +0000)
committerJeremias Maerki <jeremias@apache.org>
Tue, 18 Oct 2005 08:05:29 +0000 (08:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_SpaceResolution@326048 13f79535-47bb-0310-9956-ffa450edef68

16 files changed:
src/java/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java
src/java/org/apache/fop/layoutmgr/BreakElement.java
src/java/org/apache/fop/layoutmgr/ElementListUtils.java
src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
src/java/org/apache/fop/layoutmgr/SpaceResolver.java
src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java
src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java
src/java/org/apache/fop/layoutmgr/table/TableStepper.java
test/layoutengine/disabled-testcases.txt
test/layoutengine/testcases/block-container_space-before_space-after_3.xml
test/layoutengine/testcases/list-block_space-before_space-after_1.xml
test/layoutengine/testcases/table_border_padding_2.xml [new file with mode: 0644]
test/layoutengine/testcases/table_margin_space-before_space-after.xml
test/layoutengine/testcases/table_space-before_space-after_1.xml [new file with mode: 0644]
test/layoutengine/testcases/table_space-before_space-after_2.xml [new file with mode: 0644]
test/layoutengine/testcases/table_table-layout_fixed_1.xml

index fb0df12cf52e010b81e961f7ca606089af827b68..a6446ca512691e071fc80531e9011195e7b8e03f 100644 (file)
@@ -811,6 +811,15 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
         } else if (fobj instanceof org.apache.fop.fo.flow.BlockContainer) {
             return ((org.apache.fop.fo.flow.BlockContainer)fobj)
                 .getCommonBorderPaddingBackground();
+        } else if (fobj instanceof org.apache.fop.fo.flow.ListBlock) {
+            return ((org.apache.fop.fo.flow.ListBlock)fobj)
+                .getCommonBorderPaddingBackground();
+        } else if (fobj instanceof org.apache.fop.fo.flow.ListItem) {
+            return ((org.apache.fop.fo.flow.ListItem)fobj)
+                .getCommonBorderPaddingBackground();
+        } else if (fobj instanceof org.apache.fop.fo.flow.Table) {
+            return ((org.apache.fop.fo.flow.Table)fobj)
+                .getCommonBorderPaddingBackground();
         } else {
             return null;
         }
@@ -830,6 +839,9 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
         } else if (fobj instanceof org.apache.fop.fo.flow.ListItem) {
             return ((org.apache.fop.fo.flow.ListItem)fobj)
                 .getCommonMarginBlock().spaceBefore;
+        } else if (fobj instanceof org.apache.fop.fo.flow.Table) {
+            return ((org.apache.fop.fo.flow.Table)fobj)
+                .getCommonMarginBlock().spaceBefore;
         } else {
             return null;
         }
@@ -849,6 +861,9 @@ public abstract class BlockStackingLayoutManager extends AbstractLayoutManager
         } else if (fobj instanceof org.apache.fop.fo.flow.ListItem) {
             return ((org.apache.fop.fo.flow.ListItem)fobj)
                 .getCommonMarginBlock().spaceAfter;
+        } else if (fobj instanceof org.apache.fop.fo.flow.Table) {
+            return ((org.apache.fop.fo.flow.Table)fobj)
+                .getCommonMarginBlock().spaceAfter;
         } else {
             return null;
         }
index d47e021480a3d329fa1c6931b8505ef389428b18..db9246fbff3fd8d9420a81a21ed569fda2dc007b 100644 (file)
@@ -66,6 +66,12 @@ public class BreakElement extends UnresolvedListElement {
         return false; //Does not really apply here
     }
 
+    /** @see org.apache.fop.layoutmgr.ListElement#isPenalty() */
+    /*
+    public boolean isPenalty() {
+        return true; //not entirely true but a BreakElement will generate a penalty later
+    }*/
+
     /** @return the penalty width */
     public int getPenaltyWidth() {
         return this.penaltyWidth;
@@ -76,6 +82,14 @@ public class BreakElement extends UnresolvedListElement {
         return this.penaltyValue;
     }
     
+    /**
+     * Sets the penalty value.
+     * @param p the new penalty value
+     */
+    public void setPenaltyValue(int p) {
+        this.penaltyValue = p;
+    }
+    
     /** @see org.apache.fop.layoutmgr.ListElement#isForcedBreak() */
     public boolean isForcedBreak() {
         return penaltyValue == -KnuthElement.INFINITE;
@@ -86,6 +100,14 @@ public class BreakElement extends UnresolvedListElement {
         return breakClass;
     }
     
+    /**
+     * Sets the break class.
+     * @param breakClass the new break class
+     */
+    public void setBreakClass(int breakClass) {
+        this.breakClass = breakClass;
+    }
+    
     /** @return the pending border and padding elements at the before edge */
     public List getPendingBeforeMarks() {
         return this.pendingBeforeMarks;
index a606879baa0c76753f8901031e82bbc4e00249da..c4fd42a353deac3d32b821ee1e32a75aa1edfe5e 100644 (file)
@@ -36,13 +36,16 @@ public class ElementListUtils {
     public static void removeLegalBreaks(LinkedList elements) {
         ListIterator i = elements.listIterator();
         while (i.hasNext()) {
-            KnuthElement el = (KnuthElement)i.next();
+            ListElement el = (ListElement)i.next();
             if (el.isPenalty()) {
-                KnuthPenalty penalty = (KnuthPenalty)el;
+                BreakElement breakPoss = (BreakElement)el;
                 //Convert all penalties no break inhibitors
-                if (penalty.getP() < KnuthPenalty.INFINITE) {
+                if (breakPoss.getPenaltyValue() < KnuthPenalty.INFINITE) {
+                    breakPoss.setPenaltyValue(KnuthPenalty.INFINITE);
+                    /*
                     i.set(new KnuthPenalty(penalty.getW(), KnuthPenalty.INFINITE, 
                             penalty.isFlagged(), penalty.getPosition(), penalty.isAuxiliary()));
+                    */
                 }
             } else if (el.isGlue()) {
                 i.previous();
@@ -106,11 +109,11 @@ public class ElementListUtils {
         int count = end - start + 1;
         int len = 0;
         while (iter.hasNext()) {
-            KnuthElement el = (KnuthElement)iter.next();
+            ListElement el = (ListElement)iter.next();
             if (el.isBox()) {
-                len += el.getW();
+                len += ((KnuthElement)el).getW();
             } else if (el.isGlue()) {
-                len += el.getW();
+                len += ((KnuthElement)el).getW();
             } else {
                 //log.debug("Ignoring penalty: " + el);
                 //ignore penalties
index 0b157c0504af7bcc80428b1eefd534f6165b4285..3cd2c9e69f887455e3c93d4185e6ac7458d2dd34 100644 (file)
@@ -65,15 +65,15 @@ public class KnuthPossPosIter extends PositionIterator {
         return super.next();
     }
 
-    public KnuthElement getKE() {
-        return (KnuthElement) peekNext();
+    public ListElement getKE() {
+        return (ListElement) peekNext();
     }
 
     protected LayoutManager getLM(Object nextObj) {
-        return ((KnuthElement) nextObj).getLayoutManager();
+        return ((ListElement) nextObj).getLayoutManager();
     }
 
     protected Position getPos(Object nextObj) {
-        return ((KnuthElement) nextObj).getPosition();
+        return ((ListElement) nextObj).getPosition();
     }
 }
index 9611ec57c8f8f41c3f2a1ccf46467f150e15bd2f..2304d5ac53b31f6c35d24dd7d000b821e1ea1c56 100644 (file)
@@ -412,7 +412,7 @@ public class SpaceResolver {
             }
             iter.add(new KnuthPenalty(breakPoss.getPenaltyWidth(), breakPoss.getPenaltyValue(), 
                     false, breakPoss.getBreakClass(), 
-                    new SpaceHandlingBreakPosition(this), false));
+                    new SpaceHandlingBreakPosition(this, breakPoss), false));
             //if (glue2.isNonZero()) {
             if (glue2w != 0 || glue2stretch != 0 || glue2shrink != 0) {
                 /*
@@ -453,14 +453,20 @@ public class SpaceResolver {
     public class SpaceHandlingBreakPosition extends Position {
 
         private SpaceResolver resolver;
+        private Position originalPosition;
         
         /**
          * Main constructor.
          * @param resolver the space resolver that provides the info about the actual situation
          */
-        public SpaceHandlingBreakPosition(SpaceResolver resolver) {
+        public SpaceHandlingBreakPosition(SpaceResolver resolver, BreakElement breakPoss) {
             super(null);
             this.resolver = resolver;
+            this.originalPosition = breakPoss.getPosition();
+            //Unpack since the SpaceHandlingBreakPosition is a non-wrapped Position, too
+            while (this.originalPosition instanceof NonLeafPosition) {
+                this.originalPosition = this.originalPosition.getPosition();
+            }
         }
         
         /** @return the space resolver */
@@ -498,9 +504,19 @@ public class SpaceResolver {
         /** @see java.lang.Object#toString() */
         public String toString() {
             StringBuffer sb = new StringBuffer();
-            sb.append("SpaceHandlingBreakPosition");
+            sb.append("SpaceHandlingBreakPosition(");
+            sb.append(this.originalPosition);
+            sb.append(")");
             return sb.toString();
         }
+
+        /** 
+         * @return the original Position instance set at the BreakElement that this Position was
+         *         created for.
+         */
+        public Position getOriginalBreakPosition() {
+            return this.originalPosition;
+        }
     }
     
     /**
index f5c28dfe48015f30c3c36964e7075d15fdfc76a2..6c8b9e05bc088a71e24bc2eaf4ce3ae7a2b07a4f 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.fop.fo.flow.TableBody;
 import org.apache.fop.fo.flow.TableRow;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.fo.properties.LengthRangeProperty;
+import org.apache.fop.layoutmgr.BreakElement;
 import org.apache.fop.layoutmgr.ElementListObserver;
 import org.apache.fop.layoutmgr.ElementListUtils;
 import org.apache.fop.layoutmgr.KnuthBox;
@@ -44,6 +45,7 @@ import org.apache.fop.layoutmgr.KnuthPenalty;
 import org.apache.fop.layoutmgr.KnuthPossPosIter;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.LayoutManager;
+import org.apache.fop.layoutmgr.ListElement;
 import org.apache.fop.layoutmgr.MinOptMaxUtil;
 import org.apache.fop.layoutmgr.Position;
 import org.apache.fop.layoutmgr.PositionIterator;
@@ -200,16 +202,22 @@ public class TableContentLayoutManager implements PercentBaseContext {
             if (rowFO != null && rowFO.getBreakBefore() != Constants.EN_AUTO) {
                 log.info("break-before found");
                 if (returnList.size() > 0) {
-                    KnuthElement last = (KnuthElement)returnList.getLast();
+                    ListElement last = (ListElement)returnList.getLast();
                     if (last.isPenalty()) {
                         KnuthPenalty pen = (KnuthPenalty)last;
                         pen.setP(-KnuthPenalty.INFINITE);
                         pen.setBreakClass(rowFO.getBreakBefore());
+                    } else if (last instanceof BreakElement) {
+                        BreakElement breakPoss = (BreakElement)last;
+                        breakPoss.setPenaltyValue(-KnuthPenalty.INFINITE);
+                        breakPoss.setBreakClass(rowFO.getBreakBefore());
                     }
                 } else {
                     if (!firstBreakBeforeServed) {
-                        returnList.add(new KnuthPenalty(0, -KnuthPenalty.INFINITE, 
-                                false, rowFO.getBreakBefore(), new Position(getTableLM()), true));
+                        //returnList.add(new KnuthPenalty(0, -KnuthPenalty.INFINITE, 
+                        //        false, rowFO.getBreakBefore(), new Position(getTableLM()), true));
+                        returnList.add(new BreakElement(new Position(getTableLM()),
+                                0, -KnuthPenalty.INFINITE, rowFO.getBreakBefore(), context));
                         iter.backToPreviousRow();
                         firstBreakBeforeServed = true;
                         break;
@@ -235,12 +243,12 @@ public class TableContentLayoutManager implements PercentBaseContext {
                 log.debug("child LM (row group) signals pending keep-with-previous");
                 if (returnList.size() > 0) {
                     //Modify last penalty
-                    KnuthElement last = (KnuthElement)returnList.getLast();
+                    ListElement last = (ListElement)returnList.getLast();
                     if (last.isPenalty()) {
-                        KnuthPenalty pen = (KnuthPenalty)last;
+                        BreakElement breakPoss = (BreakElement)last;
                         //Only honor keep if there's no forced break
-                        if (!pen.isForcedBreak()) {
-                            pen.setP(KnuthPenalty.INFINITE);
+                        if (!breakPoss.isForcedBreak()) {
+                            breakPoss.setPenaltyValue(KnuthPenalty.INFINITE);
                         }
                     }
                 }
@@ -251,11 +259,15 @@ public class TableContentLayoutManager implements PercentBaseContext {
             if (rowFO != null && rowFO.getBreakAfter() != Constants.EN_AUTO) {
                 log.info("break-after found");
                 if (returnList.size() > 0) {
-                    KnuthElement last = (KnuthElement)returnList.getLast();
-                    if (last.isPenalty()) {
+                    ListElement last = (ListElement)returnList.getLast();
+                    if (last instanceof KnuthPenalty) {
                         KnuthPenalty pen = (KnuthPenalty)last;
                         pen.setP(-KnuthPenalty.INFINITE);
                         pen.setBreakClass(rowFO.getBreakAfter());
+                    } else if (last instanceof BreakElement) {
+                        BreakElement breakPoss = (BreakElement)last;
+                        breakPoss.setPenaltyValue(-KnuthPenalty.INFINITE);
+                        breakPoss.setBreakClass(rowFO.getBreakAfter());
                     }
                 }
             }
@@ -263,10 +275,9 @@ public class TableContentLayoutManager implements PercentBaseContext {
         
         if (returnList.size() > 0) {
             //Remove last penalty
-            KnuthElement last = (KnuthElement)returnList.getLast();
-            if (last.isPenalty()) {
-                KnuthPenalty pen = (KnuthPenalty)last;
-                if (!pen.isForcedBreak()) {
+            ListElement last = (ListElement)returnList.getLast();
+            if (last.isPenalty() || last instanceof BreakElement) {
+                if (!last.isForcedBreak()) {
                     //Only remove if we don't signal a forced break
                     returnList.removeLast();
                 }
@@ -462,9 +473,7 @@ public class TableContentLayoutManager implements PercentBaseContext {
                         ElementListObserver.observe(elems, "table-cell", primary.getCell().getId());
 
                         if ((elems.size() > 0) 
-                                && ((KnuthElement)elems.getLast()).isPenalty()
-                                && ((KnuthPenalty)elems.getLast()).getP() 
-                                        == -KnuthElement.INFINITE) {
+                                && ((KnuthElement)elems.getLast()).isForcedBreak()) {
                             // a descendant of this block has break-after
                             log.warn("Descendant of table-cell signals break: " 
                                     + primary.getCellLM().isFinished());
@@ -588,13 +597,23 @@ public class TableContentLayoutManager implements PercentBaseContext {
         List footerElements = null;
         Position firstPos = null;
         Position lastPos = null;
+        Position lastCheckPos = null;
         while (parentIter.hasNext()) {
             Position pos = (Position)parentIter.next();
-            if (!(pos instanceof SpaceHandlingBreakPosition)) {
-                if (firstPos == null) {
-                    firstPos = pos;
-                }
-                lastPos = pos;
+            if (pos instanceof SpaceHandlingBreakPosition) {
+                //This position has only been needed before addAreas was called, now we need the
+                //original one created by the layout manager.
+                pos = ((SpaceHandlingBreakPosition)pos).getOriginalBreakPosition();
+            }
+            if (pos == null) {
+                continue;
+            }
+            if (firstPos == null) {
+                firstPos = pos;
+            }
+            lastPos = pos;
+            if (pos.getIndex() >= 0) {
+                lastCheckPos = pos;
             }
             if (pos instanceof TableHeaderFooterPosition) {
                 TableHeaderFooterPosition thfpos = (TableHeaderFooterPosition)pos;
@@ -630,7 +649,7 @@ public class TableContentLayoutManager implements PercentBaseContext {
         Map markers = getTableLM().getTable().getMarkers();
         if (markers != null) {
             getTableLM().getCurrentPV().addMarkers(markers, 
-                    true, getTableLM().isFirst(firstPos), getTableLM().isLast(lastPos));
+                    true, getTableLM().isFirst(firstPos), getTableLM().isLast(lastCheckPos));
         }
         
         if (headerElements != null) {
@@ -658,7 +677,7 @@ public class TableContentLayoutManager implements PercentBaseContext {
 
         if (markers != null) {
             getTableLM().getCurrentPV().addMarkers(markers, 
-                    false, getTableLM().isFirst(firstPos), getTableLM().isLast(lastPos));
+                    false, getTableLM().isFirst(firstPos), getTableLM().isLast(lastCheckPos));
         }
     }
     
index feedf8acfad8b40c9364c30271a5ff2be42a8f58..8a280880f01f91c65637fdcf1c4a9c6111c1a3de 100644 (file)
@@ -24,13 +24,14 @@ import org.apache.fop.fo.flow.TableColumn;
 import org.apache.fop.fo.properties.TableColLength;
 import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
 import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
+import org.apache.fop.layoutmgr.ConditionalElementListener;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthGlue;
-import org.apache.fop.layoutmgr.KnuthPenalty;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.ListElement;
 import org.apache.fop.layoutmgr.PositionIterator;
 import org.apache.fop.layoutmgr.Position;
+import org.apache.fop.layoutmgr.RelSide;
 import org.apache.fop.layoutmgr.TraitSetter;
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
@@ -51,7 +52,8 @@ import org.apache.fop.fo.FObj;
  * the render background.
  */
 public class TableLayoutManager extends BlockStackingLayoutManager 
-                implements BlockLevelLayoutManager {
+                implements ConditionalElementListener {
+    
     private Table fobj;
     
     private TableContentLayoutManager contentLM; 
@@ -68,6 +70,13 @@ public class TableLayoutManager extends BlockStackingLayoutManager
     private MinOptMax spaceBefore;
     private MinOptMax spaceAfter;
     
+    private boolean discardBorderBefore;
+    private boolean discardBorderAfter;
+    private boolean discardPaddingBefore;
+    private boolean discardPaddingAfter;
+    private MinOptMax effSpaceBefore;
+    private MinOptMax effSpaceAfter;
+    
     /**
      * Create a new table layout manager.
      * @param node the table FO
@@ -101,6 +110,15 @@ public class TableLayoutManager extends BlockStackingLayoutManager
         }
     }
 
+    private void resetSpaces() {
+        this.discardBorderBefore = false;        
+        this.discardBorderAfter = false;        
+        this.discardPaddingBefore = false;        
+        this.discardPaddingAfter = false;
+        this.effSpaceBefore = foSpaceBefore;
+        this.effSpaceAfter = foSpaceAfter;
+    }
+    
     private int getIPIndents() {
         int iIndents = 0;
         iIndents += fobj.getCommonMarginBlock().startIndent.getValue(this);
@@ -142,14 +160,15 @@ public class TableLayoutManager extends BlockStackingLayoutManager
             log.warn("Allocated IPD exceeds available reference IPD");
         }
 
-        MinOptMax stackSize = new MinOptMax();
+        //MinOptMax stackSize = new MinOptMax();
         //Add spacing
+        /*
         if (spaceAfter != null) {
             stackSize.add(spaceAfter);
         }
         if (spaceBefore != null) {
             stackSize.add(spaceBefore);
-        }
+        }*/
 
         // either works out table of column widths or if proportional-column-width function
         // is used works out total factor, so that value of single unit can be computed.
@@ -173,16 +192,27 @@ public class TableLayoutManager extends BlockStackingLayoutManager
             }
         }
 
+        addKnuthElementsForSpaceBefore(returnList, alignment);
+        
+        if (fobj.isSeparateBorderModel()) {
+            addKnuthElementsForBorderPaddingBefore(returnList);
+        }
+
+        //Spaces, border and padding to be repeated at each break
+        addPendingMarks(context);
+
         LinkedList returnedList = null;
         LinkedList contentList = new LinkedList();
         //Position returnPosition = new NonLeafPosition(this, null);
         //Body prevLM = null;
 
         LayoutContext childLC = new LayoutContext(0);
+        /*
         childLC.setStackLimit(
               MinOptMax.subtract(context.getStackLimit(),
-                                 stackSize));
+                                 stackSize));*/
         childLC.setRefIPD(context.getRefIPD());
+        childLC.copyPendingMarksFrom(context);
 
         if (contentLM == null) {
             contentLM = new TableContentLayoutManager(this);
@@ -200,7 +230,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager
         //Set index values on elements coming from the content LM
         Iterator iter = returnedList.iterator();
         while (iter.hasNext()) {
-            KnuthElement el = (KnuthElement)iter.next();
+            ListElement el = (ListElement)iter.next();
             notifyPos(el.getPosition());
         }
         log.debug(returnedList);
@@ -266,8 +296,13 @@ public class TableLayoutManager extends BlockStackingLayoutManager
             }
         }
         wrapPositionElements(contentList, returnList);
+        if (fobj.isSeparateBorderModel()) {
+            addKnuthElementsForBorderPaddingAfter(returnList);
+        }
+        addKnuthElementsForSpaceAfter(returnList, alignment);
         addKnuthElementsForBreakAfter(returnList, context);
         setFinished(true);
+        resetSpaces();
         return returnList;
     }
     
@@ -284,9 +319,9 @@ public class TableLayoutManager extends BlockStackingLayoutManager
         getPSLM().addIDToPage(fobj.getId());
 
         // if adjusted space before
-        double adjust = layoutContext.getSpaceAdjust();
-        addBlockSpacing(adjust, spaceBefore);
-        spaceBefore = null;
+        //double adjust = layoutContext.getSpaceAdjust();
+        //addBlockSpacing(adjust, spaceBefore);
+        //spaceBefore = null;
 
         int startXOffset = fobj.getCommonMarginBlock().startIndent.getValue(this);
         
@@ -305,7 +340,12 @@ public class TableLayoutManager extends BlockStackingLayoutManager
         curBlockArea.setBPD(tableHeight);
 
         if (fobj.isSeparateBorderModel()) {
-            TraitSetter.addBorders(curBlockArea, fobj.getCommonBorderPaddingBackground(), this);
+            TraitSetter.addBorders(curBlockArea, 
+                    getTable().getCommonBorderPaddingBackground(), 
+                    discardBorderBefore, discardBorderAfter, false, false, this);
+            TraitSetter.addPadding(curBlockArea, 
+                    getTable().getCommonBorderPaddingBackground(), 
+                    discardPaddingBefore, discardPaddingAfter, false, false, this);
         }
         TraitSetter.addBackground(curBlockArea, 
                 fobj.getCommonBorderPaddingBackground(),
@@ -316,13 +356,16 @@ public class TableLayoutManager extends BlockStackingLayoutManager
                 this);
         TraitSetter.addBreaks(curBlockArea, 
                 fobj.getBreakBefore(), fobj.getBreakAfter());
+        TraitSetter.addSpaceBeforeAfter(curBlockArea, layoutContext.getSpaceAdjust(), 
+                effSpaceBefore, effSpaceAfter);
 
         flush();
 
         // if adjusted space after
-        addBlockSpacing(adjust, spaceAfter);
+        //addBlockSpacing(adjust, spaceAfter);
 
         //bodyBreaks.clear();
+        resetSpaces();
         curBlockArea = null;
     }
 
@@ -377,17 +420,13 @@ public class TableLayoutManager extends BlockStackingLayoutManager
         }
     }
 
-    /**
-     * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#negotiateBPDAdjustment(int, org.apache.fop.layoutmgr.KnuthElement)
-     */
+    /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager */
     public int negotiateBPDAdjustment(int adj, KnuthElement lastElement) {
         // TODO Auto-generated method stub
         return 0;
     }
 
-    /**
-     * @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#discardSpace(org.apache.fop.layoutmgr.KnuthGlue)
-     */
+    /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager */
     public void discardSpace(KnuthGlue spaceGlue) {
         // TODO Auto-generated method stub
         
@@ -460,4 +499,49 @@ public class TableLayoutManager extends BlockStackingLayoutManager
         return referenceBPD;
     }
     
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifySpace(RelSide side, MinOptMax effectiveLength) {
+        if (RelSide.BEFORE == side) {
+            if (log.isDebugEnabled()) {
+                log.debug(this + ": Space " + side + ", " 
+                        + this.effSpaceBefore + "-> " + effectiveLength);
+            }
+            this.effSpaceBefore = effectiveLength;
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug(this + ": Space " + side + ", " 
+                        + this.effSpaceAfter + "-> " + effectiveLength);
+            }
+            this.effSpaceAfter = effectiveLength;
+        }
+    }
+
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifyBorder(RelSide side, MinOptMax effectiveLength) {
+        if (effectiveLength == null) {
+            if (RelSide.BEFORE == side) {
+                this.discardBorderBefore = true;
+            } else {
+                this.discardBorderAfter = true;
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug(this + ": Border " + side + " -> " + effectiveLength);
+        }
+    }
+
+    /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
+    public void notifyPadding(RelSide side, MinOptMax effectiveLength) {
+        if (effectiveLength == null) {
+            if (RelSide.BEFORE == side) {
+                this.discardPaddingBefore = true;
+            } else {
+                this.discardPaddingAfter = true;
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug(this + ": Padding " + side + " -> " + effectiveLength);
+        }
+    }
+    
 }
\ No newline at end of file
index f7a381a3e877ff44a81d259cb9d2482c0df9d3c8..00eeae4bab6661a3a7916ac3a1f1ddca7c38c89f 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.flow.TableRow;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
+import org.apache.fop.layoutmgr.BreakElement;
 import org.apache.fop.layoutmgr.ElementListUtils;
 import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
@@ -162,7 +163,7 @@ public class TableStepper {
     private void setupElementList(int column) {
         GridUnit gu = getActiveGridUnit(column);
         EffRow row = getActiveRow();
-        if (gu.isEmpty()){
+        if (gu.isEmpty()) {
             elementLists[column] = null;
             start[column] = 0;
             end[column] = -1;
@@ -296,14 +297,6 @@ public class TableStepper {
             
             //Create elements for step
             int effPenaltyLen = penaltyLen;
-            if (isSeparateBorderModel()) {
-                CommonBorderPaddingBackground borders 
-                    = getTableLM().getTable().getCommonBorderPaddingBackground(); 
-                effPenaltyLen += borders.getBorderBeforeWidth(false); 
-                effPenaltyLen += borders.getBorderAfterWidth(false); 
-                effPenaltyLen += borders.getPaddingBefore(false, getTableLM()); 
-                effPenaltyLen += borders.getPaddingAfter(false, getTableLM()); 
-            }
             TableContentPosition tcpos = new TableContentPosition(getTableLM(), 
                     gridUnitParts, getActiveRow());
             if (returnList.size() == 0) {
@@ -345,7 +338,8 @@ public class TableStepper {
                 p = -KnuthPenalty.INFINITE; //Overrides any keeps (see 4.8 in XSL 1.0)
                 clearBreakCondition();
             }
-            returnList.add(new KnuthPenalty(effPenaltyLen, p, false, penaltyPos, false));
+            //returnList.add(new KnuthPenalty(effPenaltyLen, p, false, penaltyPos, false));
+            returnList.add(new BreakElement(penaltyPos, effPenaltyLen, p, 0, context));
 
             log.debug("step=" + step + " (+" + increase + ")"
                     + " box=" + boxLen 
@@ -364,7 +358,7 @@ public class TableStepper {
             context.setFlags(LayoutContext.KEEP_WITH_NEXT_PENDING);
         }
         if (isBreakCondition()) {
-            ((KnuthPenalty)returnList.getLast()).setP(-KnuthPenalty.INFINITE);
+            ((BreakElement)returnList.getLast()).setPenaltyValue(-KnuthPenalty.INFINITE);
         }
         lastTCPos.setFlag(TableContentPosition.LAST_IN_ROWGROUP, true);
         return returnList;
index 569bd4c6e558dbf87b55d210163f719dd103b652..50ae73126dfc6bc820e4bd5783bfd10c27f50db0 100644 (file)
@@ -2,8 +2,6 @@ block-container_reference-orientation_bug36391.xml
 block-container_space-before_space-after_3.xml
 block_font-stretch.xml
 block_padding_2.xml
-block_space-before_space-after_2.xml
-block_space-before_space-after_3.xml
 block_word-spacing.xml
 block_word-spacing_text-align_justify.xml
 external-graphic_oversized.xml
index cbae2a4f678ca2a238a9b3669be09f7a401baf14..6e9d607d709a770faca6eb42998554afd4bf7b10 100644 (file)
@@ -35,7 +35,7 @@
             <fo:block>line 2</fo:block>
           </fo:block-container>
           <fo:block>A block between block-containers.</fo:block>
-          <fo:block-container background-color="yellow" id="page1-bc1">
+          <fo:block-container background-color="yellow" id="page1-bc2">
             <!-- ATM, the block-container without height behaves like a block which is wrong. It generates a viewport/reference pair. -->
             <fo:block space-before="1em">line 1</fo:block>
             <fo:block>line 2</fo:block>
index 7c5aedacd1210a78a63d00ed67476a0a621225bd..4c77cc01abd1346617cc27b57446cb8e5edcdf30 100644 (file)
@@ -18,7 +18,7 @@
 <testcase>
   <info>
     <p>
-      This test checks lists. Checks for the presence of space-before and space-after on list-items.
+      This test checks spaces on tables.
     </p>
   </info>
   <fo>
diff --git a/test/layoutengine/testcases/table_border_padding_2.xml b/test/layoutengine/testcases/table_border_padding_2.xml
new file mode 100644 (file)
index 0000000..cea5269
--- /dev/null
@@ -0,0 +1,203 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id$ -->
+<testcase>
+  <info>
+    <p>
+      This test checks border and padding conditionality on table.
+    </p>
+  </info>
+  <fo>
+    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg">
+      <fo:layout-master-set>
+        <fo:simple-page-master master-name="normal" page-width="5in" page-height="2in">
+          <fo:region-body/>
+        </fo:simple-page-master>
+      </fo:layout-master-set>
+      <fo:page-sequence master-reference="normal" id="retain">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:table table-layout="fixed" width="100%" border-collapse="separate" border-spacing="5pt" 
+                padding-before="20pt" padding-before.conditionality="retain" 
+                padding-after="20pt" padding-after.conditionality="retain" 
+                border-before-style="solid" border-before-width="5pt" border-before-width.conditionality="retain"
+                border-after-style="solid" border-after-width="5pt" border-after-width.conditionality="retain">
+            <fo:table-column column-width="proportional-column-width(1)"/>
+            <fo:table-column column-width="proportional-column-width(9)"/>
+            <fo:table-body>
+              <fo:table-row>
+                <fo:table-cell background-color="yellow">
+                  <fo:block>cell1</fo:block>
+                </fo:table-cell>
+                <fo:table-cell background-color="orange">
+                  <fo:block text-align="justify">
+In olden times when wishing still helped one, there lived a king whose daughters 
+were all beautiful; and the youngest was so beautiful that the sun itself, which 
+has seen so much, was astonished whenever it shone in her face. Close by the king's 
+castle lay a great dark forest, and under an old lime-tree in the forest was a well, 
+and when the day was very warm, the king's child went out into the forest and sat 
+down by the side of the cool fountain; and when she was bored she took a golden ball, 
+and threw it up on high and caught it; and this ball was her favorite plaything.
+                  </fo:block>
+                </fo:table-cell>
+              </fo:table-row>
+            </fo:table-body>
+          </fo:table>
+        </fo:flow>
+      </fo:page-sequence>
+      <fo:page-sequence master-reference="normal" id="discard">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:table table-layout="fixed" width="100%" border-collapse="separate" border-spacing="5pt" 
+                padding-before="20pt" padding-before.conditionality="discard" 
+                padding-after="20pt" padding-after.conditionality="discard" 
+                border-before-style="solid" border-before-width="5pt" border-before-width.conditionality="discard"
+                border-after-style="solid" border-after-width="5pt" border-after-width.conditionality="discard">
+            <fo:table-column column-width="proportional-column-width(1)"/>
+            <fo:table-column column-width="proportional-column-width(9)"/>
+            <fo:table-body>
+              <fo:table-row>
+                <fo:table-cell background-color="yellow">
+                  <fo:block>cell1</fo:block>
+                </fo:table-cell>
+                <fo:table-cell background-color="orange">
+                  <fo:block text-align="justify">
+In olden times when wishing still helped one, there lived a king whose daughters 
+were all beautiful; and the youngest was so beautiful that the sun itself, which 
+has seen so much, was astonished whenever it shone in her face. Close by the king's 
+castle lay a great dark forest, and under an old lime-tree in the forest was a well, 
+and when the day was very warm, the king's child went out into the forest and sat 
+down by the side of the cool fountain; and when she was bored she took a golden ball, 
+and threw it up on high and caught it; and this ball was her favorite plaything.
+                  </fo:block>
+                </fo:table-cell>
+              </fo:table-row>
+            </fo:table-body>
+          </fo:table>
+        </fo:flow>
+      </fo:page-sequence>
+    </fo:root>
+  </fo>
+  <checks>
+    <element-list category="breaker" id="retain">
+      <box w="0"/> <!-- Helper box bearing the SpaceHandlingPosition and making sure the glue gets processed -->
+      <penalty w="0" p="INF"/>
+      <glue w="25000"/>
+      
+      <box w="0"/>
+      
+      <penalty w="0" p="INF"/>
+      <glue w="25000"/>
+      <penalty w="14400"/> <!-- p is not of interest here -->
+      <glue w="-50000"/>
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="25000"/>
+      
+      <box w="28800"/>
+      
+      <penalty w="0" p="INF"/>
+      <glue w="25000"/>
+      <penalty w="0" p="0"/>
+      <glue w="-50000"/>
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="25000"/>
+      
+      <box w="14400"/>
+      
+      <!-- skip three more lines -->
+      <skip>8</skip>
+      <skip>8</skip>
+      <skip>8</skip>
+      <skip>8</skip>
+      <skip>8</skip>
+      
+      <penalty w="0" p="INF"/>
+      <glue w="25000"/>
+      <penalty w="0" p="0"/>
+      <glue w="-50000"/>
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="25000"/>
+      
+      <box w="28800"/> <!-- end of table -->
+      
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="25000"/>
+      
+      <box w="0"/> <!-- This is used to make sure the preceding glue is not cut off -->
+      
+      <skip>3</skip>
+    </element-list>
+    <element-list category="breaker" id="discard">
+      <box w="0"/> <!-- Helper box used to notify the LM for the addAreas stage about the discarded spaces -->
+      <penalty w="0" p="INF"/>
+      <glue w="25000"/>
+      <box w="0"/>
+      <penalty w="14400"/> <!-- p is not of interest here -->
+      <box w="28800"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="28800"/>
+      
+      <box w="0"/> <!-- SpaceHandlingPosition-bearing helper box -->
+      
+      <penalty w="0" p="INF"/>
+      <glue w="25000"/>
+      <box w="0"/> <!-- This is used to make sure the preceding glue is not cut off -->
+      
+      <skip>3</skip>
+    </element-list>
+
+    <!-- retain case -->
+    <eval expected="(solid,#000000,5000)" xpath="//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@border-before"/>
+    <eval expected="20000" xpath="//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@padding-before"/>
+
+    <eval expected="(solid,#000000,5000)" xpath="//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@border-after"/>
+    <eval expected="20000" xpath="//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@padding-after"/>
+
+    <eval expected="(solid,#000000,5000)" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@border-before"/>
+    <eval expected="20000" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@padding-before"/>
+
+    <eval expected="(solid,#000000,5000)" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@border-after"/>
+    <eval expected="20000" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@padding-after"/>
+
+    <!-- discard case -->
+    <eval expected="(solid,#000000,5000)" xpath="//pageViewport[@nr=3]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@border-before"/>
+    <eval expected="20000" xpath="//pageViewport[@nr=3]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@padding-before"/>
+    
+    <true xpath="not(boolean(//pageViewport[@nr=3]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@border-after))"/>
+    <true xpath="not(boolean(//pageViewport[@nr=3]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@padding-after))"/>
+
+    <true xpath="not(boolean(//pageViewport[@nr=4]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@border-before))"/>
+    <true xpath="not(boolean(//pageViewport[@nr=4]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@padding-before))"/>
+
+    <eval expected="(solid,#000000,5000)" xpath="//pageViewport[@nr=4]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@border-after"/>
+    <eval expected="20000" xpath="//pageViewport[@nr=4]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@padding-after"/>
+  </checks>
+</testcase>
index c1b37fafb11fcc48dfdf89e7f52a12a19e088f78..ddf51a9f2cc2991ccea51fabf0f2b8efa215f010 100644 (file)
 -->
 <!-- $Id$ -->
 <testcase>
-       <info>
-               <p>
+  <info>
+    <p>
       This test checks basic tables. Tests table spaces and margins.
     </p>
-       </info>
-       <fo>
-               <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg">
-                       <fo:layout-master-set>
-                               <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in">
-                                       <fo:region-body/>
-                               </fo:simple-page-master>
-                       </fo:layout-master-set>
-                       <fo:page-sequence master-reference="normal" white-space-collapse="true">
-                               <fo:flow flow-name="xsl-region-body">
-                                       <fo:block background-color="orange">before table</fo:block>
-                                       <fo:table table-layout="fixed" space-before="5pt" space-after="10pt" margin-left="5pt" margin-right="10pt" width="4in + 15pt" background-color="lightgray">
-                                               <fo:table-column column-width="2in"/>
-                                               <fo:table-column column-width="2in"/>
-                                               <fo:table-body start-indent="0pt" end-indent="0pt">
-                                                       <fo:table-row>
-                                                               <fo:table-cell>
-                                                                       <fo:block>cell1</fo:block>
-                                                               </fo:table-cell>
-                                                               <fo:table-cell background-color="yellow">
-                                                                       <fo:block>cell2</fo:block>
-                                                               </fo:table-cell>
-                                                       </fo:table-row>
-                                                       <fo:table-row>
-                                                               <fo:table-cell background-color="orange">
-                                                                       <fo:block text-align="end">cell3</fo:block>
-                                                               </fo:table-cell>
-                                                               <fo:table-cell>
-                                                                       <fo:block>cell4</fo:block>
-                                                               </fo:table-cell>
-                                                       </fo:table-row>
-                                               </fo:table-body>
-                                       </fo:table>
-                                       <fo:block background-color="orange">after table</fo:block>
-                                       <fo:block-container width="4in + 15pt">
-                                               <fo:block space-before="5pt" space-after="10pt" margin-left="5pt" margin-right="10pt" background-color="lightgray">
+  </info>
+  <fo>
+    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg">
+      <fo:layout-master-set>
+        <fo:simple-page-master master-name="normal" page-width="5in" page-height="5in">
+          <fo:region-body/>
+        </fo:simple-page-master>
+      </fo:layout-master-set>
+      <fo:page-sequence master-reference="normal" white-space-collapse="true">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:block background-color="orange">before table</fo:block>
+          <fo:table table-layout="fixed" space-before="5pt" space-after="10pt" margin-left="5pt" margin-right="10pt" width="4in + 15pt" background-color="lightgray">
+            <fo:table-column column-width="2in"/>
+            <fo:table-column column-width="2in"/>
+            <fo:table-body start-indent="0pt" end-indent="0pt">
+              <fo:table-row>
+                <fo:table-cell>
+                  <fo:block>cell1</fo:block>
+                </fo:table-cell>
+                <fo:table-cell background-color="yellow">
+                  <fo:block>cell2</fo:block>
+                </fo:table-cell>
+              </fo:table-row>
+              <fo:table-row>
+                <fo:table-cell background-color="orange">
+                  <fo:block text-align="end">cell3</fo:block>
+                </fo:table-cell>
+                <fo:table-cell>
+                  <fo:block>cell4</fo:block>
+                </fo:table-cell>
+              </fo:table-row>
+            </fo:table-body>
+          </fo:table>
+          <fo:block background-color="orange">after table</fo:block>
+          <fo:block-container width="4in + 15pt">
+            <fo:block space-before="5pt" space-after="10pt" margin-left="5pt" margin-right="10pt" background-color="lightgray">
               reference block
             </fo:block>
-                                       </fo:block-container>
-                               </fo:flow>
-                       </fo:page-sequence>
-               </fo:root>
-       </fo>
-       <checks>
-               <!-- spaces -->
-               <eval expected="5000" xpath="//flow/block[2]/@bpd"/>
-               <eval expected="10000" xpath="//flow/block[4]/@bpd"/>
-               <!-- table dimensions -->
-               <eval expected="303000" xpath="//flow/block[3]/@ipda"/>
-               <eval expected="303000" xpath="//flow/block[3]/@ipd"/>
-               <eval expected="28800" xpath="//flow/block[3]/@bpda"/>
-               <eval expected="28800" xpath="//flow/block[3]/@bpd"/>
-               <!-- cell 1 -->
-               <true xpath="//flow/block[3]/block[1]/@is-reference-area"/>
-               <eval expected="5000" xpath="//flow/block[3]/block[1]/@left-offset"/>
-               <true xpath="not(boolean(//flow/block[3]/block[1]/@top-offset)) or (//flow/block[3]/block[1]/@top-offset = 0)"/>
-               <eval expected="144000" xpath="//flow/block[3]/block[1]/@ipd"/>
-               <eval expected="14400" xpath="//flow/block[3]/block[1]/@bpd"/>
-               <eval expected="144000" xpath="//flow/block[3]/block[1]/block[1]/@ipd"/>
-               <eval expected="14400" xpath="//flow/block[3]/block[1]/block[1]/@bpd"/>
-               <eval expected="cell1" xpath="//flow/block[3]/block[1]/block[1]/lineArea"/>
-               <!-- cell 2 -->
-               <true xpath="//flow/block[3]/block[2]/@is-reference-area"/>
-               <eval expected="149000" xpath="//flow/block[3]/block[2]/@left-offset"/>
-               <true xpath="not(boolean(//flow/block[3]/block[2]/@top-offset)) or (//flow/block[3]/block[2]/@top-offset = 0)"/>
-               <eval expected="144000" xpath="//flow/block[3]/block[2]/@ipd"/>
-               <eval expected="14400" xpath="//flow/block[3]/block[2]/@bpd"/>
-               <eval expected="144000" xpath="//flow/block[3]/block[2]/block[1]/@ipd"/>
-               <eval expected="14400" xpath="//flow/block[3]/block[2]/block[1]/@bpd"/>
-               <eval expected="cell2" xpath="//flow/block[3]/block[2]/block[1]/lineArea"/>
-               <eval expected="color=#ffff00" xpath="//flow/block[3]/block[2]/@background"/>
-               <!-- cell 3 -->
-               <true xpath="//flow/block[3]/block[3]/@is-reference-area"/>
-               <eval expected="5000" xpath="//flow/block[3]/block[3]/@left-offset"/>
-               <eval expected="14400" xpath="//flow/block[3]/block[3]/@top-offset"/>
-               <eval expected="144000" xpath="//flow/block[3]/block[3]/@ipd"/>
-               <eval expected="14400" xpath="//flow/block[3]/block[3]/@bpd"/>
-               <eval expected="144000" xpath="//flow/block[3]/block[3]/block[1]/@ipd"/>
-               <eval expected="14400" xpath="//flow/block[3]/block[3]/block[1]/@bpd"/>
-               <eval expected="cell3" xpath="//flow/block[3]/block[3]/block[1]/lineArea"/>
-               <eval expected="color=#ffa500" xpath="//flow/block[3]/block[3]/@background"/>
-               <!-- cell 4 -->
-               <true xpath="//flow/block[3]/block[4]/@is-reference-area"/>
-               <eval expected="149000" xpath="//flow/block[3]/block[4]/@left-offset"/>
-               <eval expected="14400" xpath="//flow/block[3]/block[4]/@top-offset"/>
-               <eval expected="144000" xpath="//flow/block[3]/block[4]/@ipd"/>
-               <eval expected="14400" xpath="//flow/block[3]/block[4]/@bpd"/>
-               <eval expected="144000" xpath="//flow/block[3]/block[4]/block[1]/@ipd"/>
-               <eval expected="14400" xpath="//flow/block[3]/block[4]/block[1]/@bpd"/>
-               <eval expected="cell4" xpath="//flow/block[3]/block[4]/block[1]/lineArea"/>
-       </checks>
+          </fo:block-container>
+        </fo:flow>
+      </fo:page-sequence>
+    </fo:root>
+  </fo>
+  <checks>
+    <!-- spaces -->
+    <eval expected="5000" xpath="//flow/block[2]/@space-before"/>
+    <eval expected="10000" xpath="//flow/block[2]/@space-after"/>
+    <!-- table dimensions -->
+    <eval expected="303000" xpath="//flow/block[2]/@ipda"/>
+    <eval expected="303000" xpath="//flow/block[2]/@ipd"/>
+    <eval expected="43800" xpath="//flow/block[2]/@bpda"/>
+    <eval expected="28800" xpath="//flow/block[2]/@bpd"/>
+    <!-- cell 1 -->
+    <true xpath="//flow/block[2]/block[1]/@is-reference-area"/>
+    <eval expected="5000" xpath="//flow/block[2]/block[1]/@left-offset"/>
+    <true xpath="not(boolean(//flow/block[2]/block[1]/@top-offset)) or (//flow/block[3]/block[1]/@top-offset = 0)"/>
+    <eval expected="144000" xpath="//flow/block[2]/block[1]/@ipd"/>
+    <eval expected="14400" xpath="//flow/block[2]/block[1]/@bpd"/>
+    <eval expected="144000" xpath="//flow/block[2]/block[1]/block[1]/@ipd"/>
+    <eval expected="14400" xpath="//flow/block[2]/block[1]/block[1]/@bpd"/>
+    <eval expected="cell1" xpath="//flow/block[2]/block[1]/block[1]/lineArea"/>
+    <!-- cell 2 -->
+    <true xpath="//flow/block[2]/block[2]/@is-reference-area"/>
+    <eval expected="149000" xpath="//flow/block[2]/block[2]/@left-offset"/>
+    <true xpath="not(boolean(//flow/block[2]/block[2]/@top-offset)) or (//flow/block[3]/block[2]/@top-offset = 0)"/>
+    <eval expected="144000" xpath="//flow/block[2]/block[2]/@ipd"/>
+    <eval expected="14400" xpath="//flow/block[2]/block[2]/@bpd"/>
+    <eval expected="144000" xpath="//flow/block[2]/block[2]/block[1]/@ipd"/>
+    <eval expected="14400" xpath="//flow/block[2]/block[2]/block[1]/@bpd"/>
+    <eval expected="cell2" xpath="//flow/block[2]/block[2]/block[1]/lineArea"/>
+    <eval expected="color=#ffff00" xpath="//flow/block[2]/block[2]/@background"/>
+    <!-- cell 3 -->
+    <true xpath="//flow/block[2]/block[3]/@is-reference-area"/>
+    <eval expected="5000" xpath="//flow/block[2]/block[3]/@left-offset"/>
+    <eval expected="14400" xpath="//flow/block[2]/block[3]/@top-offset"/>
+    <eval expected="144000" xpath="//flow/block[2]/block[3]/@ipd"/>
+    <eval expected="14400" xpath="//flow/block[2]/block[3]/@bpd"/>
+    <eval expected="144000" xpath="//flow/block[2]/block[3]/block[1]/@ipd"/>
+    <eval expected="14400" xpath="//flow/block[2]/block[3]/block[1]/@bpd"/>
+    <eval expected="cell3" xpath="//flow/block[2]/block[3]/block[1]/lineArea"/>
+    <eval expected="color=#ffa500" xpath="//flow/block[2]/block[3]/@background"/>
+    <!-- cell 4 -->
+    <true xpath="//flow/block[2]/block[4]/@is-reference-area"/>
+    <eval expected="149000" xpath="//flow/block[2]/block[4]/@left-offset"/>
+    <eval expected="14400" xpath="//flow/block[2]/block[4]/@top-offset"/>
+    <eval expected="144000" xpath="//flow/block[2]/block[4]/@ipd"/>
+    <eval expected="14400" xpath="//flow/block[2]/block[4]/@bpd"/>
+    <eval expected="144000" xpath="//flow/block[2]/block[4]/block[1]/@ipd"/>
+    <eval expected="14400" xpath="//flow/block[2]/block[4]/block[1]/@bpd"/>
+    <eval expected="cell4" xpath="//flow/block[2]/block[4]/block[1]/lineArea"/>
+  </checks>
 </testcase>
diff --git a/test/layoutengine/testcases/table_space-before_space-after_1.xml b/test/layoutengine/testcases/table_space-before_space-after_1.xml
new file mode 100644 (file)
index 0000000..2d30410
--- /dev/null
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id$ -->
+<testcase>
+  <info>
+    <p>
+      This test checks space properties on table.
+    </p>
+  </info>
+  <fo>
+    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg">
+      <fo:layout-master-set>
+        <fo:simple-page-master master-name="normal" page-width="5in" page-height="1.8in">
+          <fo:region-body/>
+        </fo:simple-page-master>
+      </fo:layout-master-set>
+      <fo:page-sequence master-reference="normal" id="retain">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:table table-layout="fixed" width="100%" border-collapse="separate" space-before="20pt" space-before.conditionality="retain" space-after="10pt" space-after.conditionality="retain">
+            <fo:table-column column-width="proportional-column-width(1)"/>
+            <fo:table-column column-width="proportional-column-width(9)"/>
+            <fo:table-body>
+              <fo:table-row>
+                <fo:table-cell>
+                  <fo:block>cell1</fo:block>
+                </fo:table-cell>
+                <fo:table-cell>
+            <fo:block text-align="justify">
+In olden times when wishing still helped one, there lived a king whose daughters 
+were all beautiful; and the youngest was so beautiful that the sun itself, which 
+has seen so much, was astonished whenever it shone in her face. Close by the king's 
+castle lay a great dark forest, and under an old lime-tree in the forest was a well, 
+and when the day was very warm, the king's child went out into the forest and sat 
+down by the side of the cool fountain; and when she was bored she took a golden ball, 
+and threw it up on high and caught it; and this ball was her favorite plaything.
+            </fo:block>
+                </fo:table-cell>
+              </fo:table-row>
+            </fo:table-body>
+          </fo:table>
+          <fo:block space-before.optimum="10pt" space-before.conditionality="retain" space-after="20pt" space-after.conditionality="retain">
+Two blocks, testing conditionality="retain".
+          </fo:block>
+        </fo:flow>
+      </fo:page-sequence>
+      <fo:page-sequence master-reference="normal" id="discard">
+        <fo:flow flow-name="xsl-region-body">
+          <fo:table table-layout="fixed" width="100%" border-collapse="separate" space-before="20pt" space-before.conditionality="discard" space-after="10pt" space-after.conditionality="discard">
+            <fo:table-column column-width="proportional-column-width(1)"/>
+            <fo:table-column column-width="proportional-column-width(9)"/>
+            <fo:table-body>
+              <fo:table-row>
+                <fo:table-cell>
+                  <fo:block>cell1</fo:block>
+                </fo:table-cell>
+                <fo:table-cell>
+            <fo:block text-align="justify">
+In olden times when wishing still helped one, there lived a king whose daughters 
+were all beautiful; and the youngest was so beautiful that the sun itself, which 
+has seen so much, was astonished whenever it shone in her face. Close by the king's 
+castle lay a great dark forest, and under an old lime-tree in the forest was a well, 
+and when the day was very warm, the king's child went out into the forest and sat 
+down by the side of the cool fountain; and when she was bored she took a golden ball, 
+and threw it up on high and caught it; and this ball was her favorite plaything.
+            </fo:block>
+                </fo:table-cell>
+              </fo:table-row>
+            </fo:table-body>
+          </fo:table>
+          <fo:block space-before="10pt" space-before.conditionality="discard" space-after="20pt" space-after.conditionality="discard">
+Two blocks, testing conditionality="discard".
+          </fo:block>
+        </fo:flow>
+      </fo:page-sequence>
+    </fo:root>
+  </fo>
+  <checks>
+    <element-list category="breaker" id="retain">
+      <box w="0"/> <!-- Helper box bearing the SpaceHandlingPosition and making sure the glue gets processed -->
+      <penalty w="0" p="INF"/>
+      <glue w="20000"/>
+      
+      <box w="0"/>
+      
+      <penalty w="0" p="INF"/>
+      <glue w="10000"/>
+      <penalty w="14400"/> <!-- p is not of interest here -->
+      <glue w="-30000"/>
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="20000"/>
+      
+      <box w="28800"/>
+      
+      <penalty w="0" p="INF"/>
+      <glue w="10000"/>
+      <penalty w="0" p="0"/>
+      <glue w="-30000"/>
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="20000"/>
+      
+      <box w="14400"/>
+      
+      <!-- skip three more lines -->
+      <skip>8</skip>
+      <skip>8</skip>
+      <skip>8</skip>
+      <skip>8</skip>
+      <skip>8</skip>
+      
+      <penalty w="0" p="INF"/>
+      <glue w="10000"/>
+      <penalty w="0" p="0"/>
+      <glue w="-30000"/>
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="20000"/>
+      
+      <box w="28800"/> <!-- end of table -->
+      
+      <penalty w="0" p="INF" aux="true"/>
+      <glue w="10000"/>
+      <penalty w="0" p="0"/>
+      <glue w="-10000"/>
+      
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="10000"/>
+      
+      <box w="14400"/> <!-- second block -->
+      
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="20000"/>
+      
+      <box w="0"/> <!-- This is used to make sure the preceding glue is not cut off -->
+      
+      <skip>3</skip>
+    </element-list>
+    <element-list category="breaker" id="discard">
+      <box w="0"/> <!-- Helper box used to notify the LM for the addAreas stage about the discarded spaces -->
+      <box w="0"/>
+      <penalty w="14400"/> <!-- p is not of interest here -->
+      <box w="28800"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="14400"/>
+      <penalty w="0" p="0"/>
+      <box w="28800"/>
+      <penalty w="0" p="0"/>
+      <glue w="10000"/>
+      
+      <box w="14400"/> <!-- second block -->
+      
+      <box w="0"/> <!-- SpaceHandlingPosition-bearing helper box -->
+      
+      <box w="0"/> <!-- This is used to make sure the preceding glue is not cut off -->
+      
+      <skip>3</skip>
+    </element-list>
+    
+    <eval expected="4" xpath="count(//pageViewport)"/>
+    
+    <!-- 1: retain -->
+    <eval expected="20000" xpath="//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-before"/>
+    <eval expected="10000" xpath="//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-after"/>
+    <eval expected="20000" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-before"/>
+    <!-- the following space is eliminated/collapsed through space resolution -->
+    <true xpath="not(boolean(//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-after))"/>
+    <eval expected="10000" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/@space-before"/>
+    <eval expected="20000" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/@space-after"/>
+    
+    <!-- 2: discard -->
+    <true xpath="not(boolean(//pageViewport[@nr=3]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-before))"/>
+    <true xpath="not(boolean(//pageViewport[@nr=3]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-before))"/>
+    <true xpath="not(boolean(//pageViewport[@nr=4]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-before))"/>
+    <true xpath="not(boolean(//pageViewport[@nr=4]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-after))"/>
+    <eval expected="10000" xpath="//pageViewport[@nr=4]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/@space-before"/>
+    <true xpath="not(boolean(//pageViewport[@nr=4]/page/regionViewport/regionBody/mainReference/span/flow/block[2]/@space-after))"/>
+  </checks>
+</testcase>
diff --git a/test/layoutengine/testcases/table_space-before_space-after_2.xml b/test/layoutengine/testcases/table_space-before_space-after_2.xml
new file mode 100644 (file)
index 0000000..310c113
--- /dev/null
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright 2005 The Apache Software Foundation
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- $Id$ -->
+<testcase>
+  <info>
+    <p>
+      This test checks space properties on table. Demonstrates that spaces are repeated on every generated area.
+    </p>
+  </info>
+  <fo>
+    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg">
+      <fo:layout-master-set>
+        <fo:simple-page-master master-name="normal" page-width="5in" page-height="30pt">
+          <fo:region-body/>
+        </fo:simple-page-master>
+      </fo:layout-master-set>
+      <fo:page-sequence master-reference="normal" white-space-collapse="true">
+        <fo:flow flow-name="xsl-region-body" line-height="10pt" font-size="9pt">
+          <fo:table table-layout="fixed" width="100%" border-collapse="separate" space-before="5pt" space-before.conditionality="retain" background-color="yellow">
+            <fo:table-column column-width="proportional-column-width(1)"/>
+            <fo:table-column column-width="proportional-column-width(9)"/>
+            <fo:table-body>
+              <fo:table-row>
+                <fo:table-cell>
+                  <fo:block>cell1</fo:block>
+                </fo:table-cell>
+                <fo:table-cell>
+                  <fo:block>line 1</fo:block>
+                  <fo:block>line 2</fo:block>
+                  <fo:block>line 3</fo:block>
+                  <fo:block>line 4</fo:block>
+                  <fo:block>line 5</fo:block>
+                </fo:table-cell>
+              </fo:table-row>
+            </fo:table-body>
+          </fo:table>
+        </fo:flow>
+      </fo:page-sequence>
+    </fo:root>
+  </fo>
+  <checks>
+    <element-list category="breaker">
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="5000"/>
+      <box w="10000"/>
+      <penalty w="0" p="0"/>
+      <glue w="-5000"/>
+      
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="5000"/>
+      <box w="10000"/>
+      <penalty w="0" p="0"/>
+      <glue w="-5000"/>
+      
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="5000"/>
+      <box w="10000"/>
+      <penalty w="0" p="0"/>
+      <glue w="-5000"/>
+      
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="5000"/>
+      <box w="10000"/>
+      <penalty w="0" p="0"/>
+      <glue w="-5000"/>
+      
+      <box w="0"/>
+      <penalty w="0" p="INF"/>
+      <glue w="5000"/>
+      <box w="10000"/>
+      
+      <skip>3</skip>
+    </element-list>
+    <eval expected="3" xpath="count(//pageViewport)"/>
+    <eval expected="5000" xpath="//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-before"/>
+    <eval expected="5000" xpath="//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-before"/>
+    <eval expected="5000" xpath="//pageViewport[@nr=3]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/@space-before"/>
+    <eval expected="1" xpath="count(//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block)"/>
+    <eval expected="1" xpath="count(//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block)"/>
+    <eval expected="1" xpath="count(//pageViewport[@nr=3]/page/regionViewport/regionBody/mainReference/span/flow/block)"/>
+    <eval expected="2" xpath="count(//pageViewport[@nr=1]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/block[2]/block)"/>
+    <eval expected="2" xpath="count(//pageViewport[@nr=2]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/block[1]/block)"/>
+    <eval expected="1" xpath="count(//pageViewport[@nr=3]/page/regionViewport/regionBody/mainReference/span/flow/block[1]/block[1]/block)"/>
+    
+  </checks>
+</testcase>
index 50c2ab834cefa2b4c8204c48f268eca965e522f5..7d1ebbaadd456310d12df6941f9ccda135b55249 100644 (file)
     <eval expected="220000" xpath="//flow/block[1]/block[2]/@ipda"/>
     <eval expected="220000" xpath="//flow/block[1]/block[2]/@ipd"/>
 
-    <eval expected="10000" xpath="//flow/block[2]/@bpda"/> <!-- space-before -->
+    <eval expected="10000" xpath="//flow/block[2]/@space-before"/>
 
     <!-- table 2 -->
-    <eval expected="310000" xpath="//flow/block[3]/@ipda"/>
-    <eval expected="300000" xpath="//flow/block[3]/@ipd"/>
-    <eval expected="100000" xpath="//flow/block[3]/block[1]/@ipda"/>
-    <eval expected="100000" xpath="//flow/block[3]/block[1]/@ipd"/>
-    <eval expected="66666" xpath="//flow/block[3]/block[2]/@ipda"/>
-    <eval expected="66666" xpath="//flow/block[3]/block[2]/@ipd"/>
-    <eval expected="133333" xpath="//flow/block[3]/block[3]/@ipda"/>
-    <eval expected="133333" xpath="//flow/block[3]/block[3]/@ipd"/>
+    <eval expected="310000" xpath="//flow/block[2]/@ipda"/>
+    <eval expected="300000" xpath="//flow/block[2]/@ipd"/>
+    <eval expected="100000" xpath="//flow/block[2]/block[1]/@ipda"/>
+    <eval expected="100000" xpath="//flow/block[2]/block[1]/@ipd"/>
+    <eval expected="66666" xpath="//flow/block[2]/block[2]/@ipda"/>
+    <eval expected="66666" xpath="//flow/block[2]/block[2]/@ipd"/>
+    <eval expected="133333" xpath="//flow/block[2]/block[3]/@ipda"/>
+    <eval expected="133333" xpath="//flow/block[2]/block[3]/@ipd"/>
   </checks>
 </testcase>