You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by vh...@apache.org on 2008/01/23 16:22:11 UTC

svn commit: r614566 [1/3] - in /xmlgraphics/fop/trunk: ./ src/java/org/apache/fop/fo/flow/table/ src/java/org/apache/fop/layoutmgr/ src/java/org/apache/fop/layoutmgr/table/ test/fotree/unittests/table/ test/java/org/apache/fop/fo/flow/table/ test/java/...

Author: vhennebert
Date: Wed Jan 23 07:22:05 2008
New Revision: 614566

URL: http://svn.apache.org/viewvc?rev=614566&view=rev
Log:
Added support for conditional borders (and paddings) in tables.
The proper borders are not selected yet between the header/footer and the body. There might still be a few glitches in some cases

Added:
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table_border-collapse_collapse_conditionals.xml   (with props)
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table_border-collapse_separate_conditionals.xml   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/CollapsingBorderResolver.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/ConditionalBorder.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/FixedColRowGroupBuilder.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/GridUnit.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/Table.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TraitSetter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/CellPart.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowPainter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/TableStepper.java
    xmlgraphics/fop/trunk/status.xml
    xmlgraphics/fop/trunk/test/fotree/unittests/table/collapsed-conditional-borders_test-generator.py
    xmlgraphics/fop/trunk/test/java/org/apache/fop/fo/flow/table/CollapsedConditionalBorderTestCase.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_block_break-after.xml
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_span-combinations.xml
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-row_break-before_break-after_2.xml
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table_border-collapse_collapse_spans_1.xml
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table_border-collapse_separate_border-spacing_2.xml
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table_break-before_break-after.xml
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table_bug36403.xml
    xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table_empty-cells.xml

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/CollapsingBorderResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/CollapsingBorderResolver.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/CollapsingBorderResolver.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/CollapsingBorderResolver.java Wed Jan 23 07:22:05 2008
@@ -47,12 +47,21 @@
 
     private Resolver delegate;
 
+    // Re-use the same ResolverInBody for every table-body
+    // Important to properly handle firstInBody!!
+    private Resolver resolverInBody = new ResolverInBody();
+
     private Resolver resolverInFooter;
 
     private List/*<ConditionalBorder>*/ leadingBorders;
 
     private List/*<ConditionalBorder>*/ trailingBorders;
 
+    /* TODO Temporary hack for resolved borders in header */
+    /* Currently the normal border is always used. */
+    private List/*<GridUnit>*/ headerLastRow = null;
+    /* End of temporary hack */
+
     /**
      * Base class for delegate resolvers. Implementation of the State design pattern: the
      * treatment differs slightly whether we are in the table's header, footer or body. To
@@ -184,14 +193,12 @@
                 TableRow tableRow = (TableRow) container;
                 for (Iterator iter = row.iterator(); iter.hasNext();) {
                     GridUnit gu = (GridUnit) iter.next();
-                    if (gu.getRowSpanIndex() == 0) {
-                        gu.integrateBorderSegment(CommonBorderPaddingBackground.BEFORE, tableRow,
-                                true, true, true);
-                    }
-                    if (gu.isLastGridUnitRowSpan()) {
-                        gu.integrateBorderSegment(CommonBorderPaddingBackground.AFTER, tableRow,
-                                true, true, true);
-                    }
+                    boolean first = (gu.getRowSpanIndex() == 0);
+                    boolean last = gu.isLastGridUnitRowSpan();
+                    gu.integrateBorderSegment(CommonBorderPaddingBackground.BEFORE, tableRow,
+                            first, first, true);
+                    gu.integrateBorderSegment(CommonBorderPaddingBackground.AFTER, tableRow,
+                            last, last, true);
                 }
             }
             if (firstInPart) {
@@ -249,7 +256,7 @@
                  */
                 for (Iterator guIter = row.iterator(); guIter.hasNext();) {
                     ConditionalBorder borderBefore = ((GridUnit) guIter.next()).borderBefore;
-                    borderBefore.leadingTrailing = null;
+                    borderBefore.leadingTrailing = borderBefore.nonLeadingTrailing;
                     borderBefore.rest = borderBefore.nonLeadingTrailing;
                 }
                 resolveBordersFirstRowInTable(row, false, true, true);
@@ -275,6 +282,9 @@
                 borderAfter.rest = borderAfter.nonLeadingTrailing;
                 leadingBorders.add(borderAfter);
             }
+            /* TODO Temporary hack for resolved borders in header */
+            headerLastRow = previousRow;
+            /* End of temporary hack */
         }
 
         void endTable() {
@@ -314,7 +324,7 @@
             // See endRow method in ResolverInHeader for an explanation of the hack
             for (Iterator guIter = footerLastRow.iterator(); guIter.hasNext();) {
                 ConditionalBorder borderAfter = ((GridUnit) guIter.next()).borderAfter;
-                borderAfter.leadingTrailing = null;
+                borderAfter.leadingTrailing = borderAfter.nonLeadingTrailing;
                 borderAfter.rest = borderAfter.nonLeadingTrailing;
             }
             resolveBordersLastRowInTable(footerLastRow, false, true, true);
@@ -323,6 +333,8 @@
 
     private class ResolverInBody extends Resolver {
 
+        private boolean firstInBody = true;
+
         void endRow(List/*<GridUnit>*/ row, TableCellContainer container) {
             super.endRow(row, container);
             if (firstInTable) {
@@ -335,6 +347,13 @@
             }
             integrateTrailingBorders(row);
             previousRow = row;
+            if (firstInBody) {
+                firstInBody = false;
+                for (Iterator iter = row.iterator(); iter.hasNext();) {
+                    GridUnit gu = (GridUnit) iter.next();
+                    gu.borderBefore.leadingTrailing = gu.borderBefore.nonLeadingTrailing;
+                }
+            }
         }
 
         void endTable() {
@@ -343,6 +362,10 @@
             } else {
                 // Trailing and rest borders already resolved with integrateTrailingBorders
                 resolveBordersLastRowInTable(previousRow, false, true, false);
+                for (Iterator iter = previousRow.iterator(); iter.hasNext();) {
+                    GridUnit gu = (GridUnit) iter.next();
+                    gu.borderAfter.leadingTrailing = gu.borderAfter.nonLeadingTrailing;
+                }
             }
         }
     }
@@ -386,7 +409,7 @@
                         trailingBorders.add(border);
                     }
                 }
-                delegate = new ResolverInBody();
+                delegate = resolverInBody;
             }
         }
         delegate.startPart(part);
@@ -401,5 +424,19 @@
     public void endTable() {
         delegate.endTable();
         delegate = null;
+        /* TODO Temporary hack for resolved borders in header */
+        if (headerLastRow != null) {
+            for (Iterator iter = headerLastRow.iterator(); iter.hasNext();) {
+                GridUnit gu = (GridUnit) iter.next();
+                gu.borderAfter.leadingTrailing = gu.borderAfter.nonLeadingTrailing;
+            }
+        }
+        if (footerLastRow != null) {
+            for (Iterator iter = footerLastRow.iterator(); iter.hasNext();) {
+                GridUnit gu = (GridUnit) iter.next();
+                gu.borderAfter.leadingTrailing = gu.borderAfter.nonLeadingTrailing;
+            }
+        }
+        /* End of temporary hack */
     }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/ConditionalBorder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/ConditionalBorder.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/ConditionalBorder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/ConditionalBorder.java Wed Jan 23 07:22:05 2008
@@ -36,6 +36,12 @@
  */
 public class ConditionalBorder {
 
+    public static final int NORMAL = 0;
+
+    public static final int LEADING_TRAILING = 1;
+
+    public static final int REST = 2;
+
     /** Special case: the cell is at the top or the bottom of the page. */
     BorderSpecification leadingTrailing;
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/FixedColRowGroupBuilder.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/FixedColRowGroupBuilder.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/FixedColRowGroupBuilder.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/FixedColRowGroupBuilder.java Wed Jan 23 07:22:05 2008
@@ -43,8 +43,6 @@
     /** The rows belonging to this row group. List of List of {@link GridUnit}s. */
     private List/*<List<GridUnit>>*/ rows;
 
-    private boolean firstInTable = true;
-
     private boolean firstInPart = true;
 
     /** The last encountered row. This is the last row of the table if it has no footer. */
@@ -52,10 +50,6 @@
 
     private BorderResolver borderResolver;
 
-    private boolean inFooter;
-
-    private List lastFooterRow;
-
     FixedColRowGroupBuilder(Table t) {
         super(t);
         numberOfColumns = t.getNumberOfColumns();
@@ -134,14 +128,6 @@
             }
         }
         borderResolver.endRow(currentRow, container);
-        ((GridUnit) currentRow.get(0)).setFlag(GridUnit.IN_FIRST_COLUMN);
-        ((GridUnit) currentRow.get(numberOfColumns - 1)).setFlag(GridUnit.IN_LAST_COLUMN);
-        if (inFooter) {
-            lastFooterRow = currentRow;
-        } else if (firstInTable) {
-            setFlagForCols(GridUnit.FIRST_IN_TABLE, currentRow);
-            firstInTable = false;
-        }
         if (firstInPart) {
             setFlagForCols(GridUnit.FIRST_IN_PART, currentRow);
             firstInPart = false;
@@ -159,7 +145,6 @@
     /** {@inheritDoc} */
     void startTablePart(TableBody part) {
         firstInPart = true;
-        inFooter = part.isTableFooter();
         borderResolver.startPart(part);
     }
 
@@ -171,18 +156,10 @@
         }
         setFlagForCols(GridUnit.LAST_IN_PART, lastRow);
         borderResolver.endPart();
-        inFooter = false;
     }
 
     /** {@inheritDoc} */
     void endTable(TableBody lastTablePart) {
-        List lastTableRow;
-        if (lastFooterRow != null) {
-            lastTableRow = lastFooterRow;
-        } else {
-            lastTableRow = lastRow;
-        }
-        setFlagForCols(GridUnit.LAST_IN_TABLE, lastTableRow);
         borderResolver.endTable();
     }
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/GridUnit.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/GridUnit.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/GridUnit.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/GridUnit.java Wed Jan 23 07:22:05 2008
@@ -19,8 +19,6 @@
 
 package org.apache.fop.fo.flow.table;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
@@ -31,37 +29,23 @@
  */
 public class GridUnit {
 
-    private static Log log = LogFactory.getLog(GridUnit.class);
-
-    /** Indicates that the grid unit is in the first column. */
-    public static final int IN_FIRST_COLUMN = 0;
-
-    /** Indicates that the grid unit is in the last column. */
-    public static final int IN_LAST_COLUMN = 1;
-
-    /** Indicates that the grid unit is in the first row of the table. */
-    public static final int FIRST_IN_TABLE = 2;
-
     /**
      * Indicates that the grid unit is in the first row of the table part (header, footer,
      * body).
      */
-    public static final int FIRST_IN_PART = 3;
+    public static final int FIRST_IN_PART = 0;
 
     /**
      * Indicates that the grid unit is in the last row of the table part (header, footer,
      * body).
      */
-    public static final int LAST_IN_PART = 4;
-
-    /** Indicates that the grid unit is in the last row of the table. */
-    public static final int LAST_IN_TABLE = 5;
+    public static final int LAST_IN_PART = 1;
 
     /** Indicates that the primary grid unit has a pending keep-with-next. */
-    public static final int KEEP_WITH_NEXT_PENDING = 6;
+    public static final int KEEP_WITH_NEXT_PENDING = 2;
 
     /** Indicates that the primary grid unit has a pending keep-with-previous. */
-    public static final int KEEP_WITH_PREVIOUS_PENDING = 7;
+    public static final int KEEP_WITH_PREVIOUS_PENDING = 3;
 
     /** Primary grid unit */
     private PrimaryGridUnit primary;
@@ -84,9 +68,6 @@
     /** index of grid unit within cell in row direction */
     private int rowSpanIndex;
 
-    /** effective borders for a cell slot */
-    private CommonBorderPaddingBackground effectiveBorders;
-
     /** flags for the grid unit */
     private byte flags = 0;
 
@@ -156,29 +137,35 @@
     }
 
     private void setBorders(Table table/*TODO*/) {
-        if (table.isSeparateBorderModel()) {
-            assignBorderForSeparateBorderModel();
-        } else {
+        if (!table.isSeparateBorderModel()) {
             collapsingBorderModel = CollapsingBorderModel.getBorderModelFor(table
                     .getBorderCollapse());
             setBordersFromCell();
         }
     }
 
+    /**
+     * Prepares the borders of this grid unit for upcoming resolution, in the collapsing
+     * model.
+     */
     protected void setBordersFromCell() {
         borderBefore = cell.borderBefore.copy();
         if (rowSpanIndex > 0) {
-            borderBefore.nonLeadingTrailing = null;
+            borderBefore.nonLeadingTrailing = BorderSpecification.getDefaultBorder();
         }
         borderAfter = cell.borderAfter.copy();
         if (!isLastGridUnitRowSpan()) {
-            borderAfter.nonLeadingTrailing = null;
+            borderAfter.nonLeadingTrailing = BorderSpecification.getDefaultBorder();
         }
         if (colSpanIndex == 0) {
             borderStart = cell.borderStart;
+        } else {
+            borderStart = BorderSpecification.getDefaultBorder();
         }
         if (isLastGridUnitColSpan()) {
             borderEnd = cell.borderEnd;
+        } else {
+            borderEnd = BorderSpecification.getDefaultBorder();
         }
     }
 
@@ -235,6 +222,11 @@
         return cell == null;
     }
 
+    /**
+     * Returns the index of the column this grid unit belongs to.
+     * 
+     * @return the column index, 0-based
+     */
     public int getStartCol() {
         return startCol;
     }
@@ -264,89 +256,67 @@
     }
 
     /**
-     * Returns a BorderInfo instance for a side of the currently applicable cell before
-     * border resolution (i.e. the value from the FO). A return value of null indicates an
-     * empty cell. See CollapsingBorderModel(EyeCatching) where this method is used.
-     * 
-     * @param side for which side to return the BorderInfo
-     * @return the requested BorderInfo instance or null if the grid unit is an empty cell
-     */
-    public BorderInfo getOriginalBorderInfoForCell(int side) {
-        if (cell != null) {
-            return cell.getCommonBorderPaddingBackground().getBorderInfo(side);
-        } else {
+     * Returns the resolved border-before of this grid unit, in the collapsing-border
+     * model.
+     * 
+     * @param which one of {@link ConditionalBorder#NORMAL},
+     * {@link ConditionalBorder#LEADING_TRAILING} or {@link ConditionalBorder#REST}
+     * @return the corresponding border
+     */
+    public BorderInfo getBorderBefore(int which) {
+        switch (which) {
+        case ConditionalBorder.NORMAL:
+            return borderBefore.nonLeadingTrailing.getBorderInfo();
+        case ConditionalBorder.LEADING_TRAILING:
+            return borderBefore.leadingTrailing.getBorderInfo();
+        case ConditionalBorder.REST:
+            return borderBefore.rest.getBorderInfo();
+        default:
+            assert false;
             return null;
         }
     }
 
     /**
-     * @return the resolved normal borders for this grid unit
-     */
-    public CommonBorderPaddingBackground getBorders() {
-        // TODO
-        if (effectiveBorders == null) {
-            effectiveBorders = new CommonBorderPaddingBackground();
-            setBorderInfo(CommonBorderPaddingBackground.BEFORE);
-            setBorderInfo(CommonBorderPaddingBackground.AFTER);
-            setBorderInfo(CommonBorderPaddingBackground.START);
-            setBorderInfo(CommonBorderPaddingBackground.END);
-            if (cell != null) {
-                effectiveBorders.setPadding(cell.getCommonBorderPaddingBackground());
-            }
-            if (log.isDebugEnabled()) {
-                log.debug(this + " resolved borders: " + "before="
-                        + effectiveBorders.getBorderBeforeWidth(false) + ", " + "after="
-                        + effectiveBorders.getBorderAfterWidth(false) + ", " + "start="
-                        + effectiveBorders.getBorderStartWidth(false) + ", " + "end="
-                        + effectiveBorders.getBorderEndWidth(false));
-            }
-        }
-        return effectiveBorders;
-    }
-
-    private void setBorderInfo(int side) {
-        switch (side) {
-        case CommonBorderPaddingBackground.BEFORE:
-            if (borderBefore.nonLeadingTrailing/*TODO*/ != null) {
-                effectiveBorders.setBorderInfo(borderBefore.nonLeadingTrailing.getBorderInfo(),
-                        side);
-            }
-            break;
-        case CommonBorderPaddingBackground.AFTER:
-            if (borderAfter.nonLeadingTrailing/*TODO*/ != null) {
-                effectiveBorders.setBorderInfo(borderAfter.nonLeadingTrailing.getBorderInfo(),
-                        side);
-            }
-            break;
-        case CommonBorderPaddingBackground.START:
-            if (borderStart != null) {
-                effectiveBorders.setBorderInfo(borderStart.getBorderInfo(), side);
-            }
-            break;
-        case CommonBorderPaddingBackground.END:
-            if (borderEnd != null) {
-                effectiveBorders.setBorderInfo(borderEnd.getBorderInfo(), side);
-            }
-            break;
-        default: assert false;
+     * Returns the resolved border-after of this grid unit, in the collapsing-border
+     * model.
+     * 
+     * @param which one of {@link ConditionalBorder#NORMAL},
+     * {@link ConditionalBorder#LEADING_TRAILING} or {@link ConditionalBorder#REST}
+     * @return the corresponding border
+     */
+    public BorderInfo getBorderAfter(int which) {
+        switch (which) {
+        case ConditionalBorder.NORMAL:
+            return borderAfter.nonLeadingTrailing.getBorderInfo();
+        case ConditionalBorder.LEADING_TRAILING:
+            return borderAfter.leadingTrailing.getBorderInfo();
+        case ConditionalBorder.REST:
+            return borderAfter.rest.getBorderInfo();
+        default:
+            assert false;
+            return null;
         }
     }
 
     /**
-     * @return true if the grid unit has any borders.
+     * Returns the resolved border-start of this grid unit, in the collapsing-border
+     * model.
+     * 
+     * @return the corresponding border
      */
-    public boolean hasBorders() {
-        return (getBorders() != null) && getBorders().hasBorder();
+    public BorderInfo getBorderStart() {
+        return borderStart.getBorderInfo();
     }
 
     /**
-     * Assigns the borders from the given cell to this cell info. Used in case of separate
-     * border model.
+     * Returns the resolved border-end of this grid unit, in the collapsing-border
+     * model.
+     * 
+     * @return the corresponding border
      */
-    void assignBorderForSeparateBorderModel() {
-        if (cell != null) {
-            effectiveBorders = cell.getCommonBorderPaddingBackground();
-        }
+    public BorderInfo getBorderEnd() {
+        return borderEnd.getBorderInfo();
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java Wed Jan 23 07:22:05 2008
@@ -24,6 +24,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.layoutmgr.ElementListUtils;
 import org.apache.fop.layoutmgr.table.TableCellLayoutManager;
 
@@ -46,6 +47,9 @@
     /** The calculated size of the cell's content. (cached value) */
     private int contentLength = -1;
 
+    private boolean isSeparateBorderModel;
+    private int halfBorderSeparationBPD;
+
     /**
      * Creates a new primary grid unit.
      *
@@ -57,6 +61,9 @@
      */
     PrimaryGridUnit(TableCell cell, TableRow row, TableColumn column, int startCol) {
         super(cell, row, column, startCol, 0, 0);
+        this.isSeparateBorderModel = column.getTable().isSeparateBorderModel(); // TODO
+        this.halfBorderSeparationBPD = column.getTable().getBorderSeparation().getBPD().getLength()
+                .getValue() / 2;  // TODO
         log.trace("PrimaryGridUnit created, row " + startRow + " col " + startCol);
     }
 
@@ -89,58 +96,120 @@
     }
 
     /**
-     * @return half the maximum before border width of this cell.
+     * Returns the widths of the border-before and -after for this cell. In the separate
+     * border model the border-separation is included. In the collapsing model only half
+     * of them is counted, since the other halves belong to the neighbouring cells; also,
+     * the returned value is the maximum of the segments of each applicable grid unit.
+     * 
+     * @return the sum of the before and after border widths
      */
-    public int getHalfMaxBeforeBorderWidth() {
-        int value = 0;
-        if (getRows() != null) {
-            int before = 0;
-            //first row for before borders
-            GridUnit[] row = (GridUnit[])getRows().get(0);
-            for (int i = 0; i < row.length; i++) {
-                if (row[i].hasBorders()) {
-                    before = Math.max(before,
-                            row[i].getBorders().getBorderBeforeWidth(false));
+    public int getBeforeAfterBorderWidth() {
+        return getBeforeBorderWidth(0, ConditionalBorder.NORMAL)
+                + getAfterBorderWidth(ConditionalBorder.NORMAL);
+    }
+
+    /**
+     * Returns the width of the before-border for the given row-span of this cell. In the
+     * separate border model half of the border-separation is included. In the collapsing
+     * model only half of the border is counted, since the other half belongs to the
+     * preceding cell; also, the returned value is the maximum of the segments of each
+     * applicable grid unit.
+     * 
+     * @param rowIndex index of the span for which the border must be computed, 0-based
+     * @param which one of {@link ConditionalBorder#NORMAL},
+     * {@link ConditionalBorder#LEADING_TRAILING} or {@link ConditionalBorder#REST}
+     * @return the before border width
+     */
+    public int getBeforeBorderWidth(int rowIndex, int which) {
+        if (isSeparateBorderModel) {
+            if (getCell() == null) {
+                return 0;
+            } else {
+                CommonBorderPaddingBackground cellBorders = getCell()
+                        .getCommonBorderPaddingBackground();
+                switch (which) {
+                case ConditionalBorder.NORMAL:
+                case ConditionalBorder.LEADING_TRAILING:
+                    return cellBorders.getBorderBeforeWidth(false) + halfBorderSeparationBPD;
+                case ConditionalBorder.REST:
+                    if (cellBorders.getBorderInfo(CommonBorderPaddingBackground.BEFORE).getWidth()
+                            .isDiscard()) {
+                        return 0;
+                    } else {
+                        return cellBorders.getBorderBeforeWidth(true) + halfBorderSeparationBPD;
+                    }
+                default:
+                    assert false;
+                    return 0;
                 }
             }
-            value += before / 2;
         } else {
-            if (hasBorders()) {
-                value += getBorders().getBorderBeforeWidth(false) / 2;
+            int width = 0;
+            GridUnit[] row = (GridUnit[]) rows.get(rowIndex);
+            for (int i = 0; i < row.length; i++) {
+                width = Math.max(width,
+                        row[i].getBorderBefore(which).getRetainedWidth());
             }
+            return width / 2;
         }
-        return value;
     }
 
     /**
-     * @return half the maximum after border width of this cell.
+     * Returns the width of the before-after for the given row-span of this cell. In the
+     * separate border model half of the border-separation is included. In the collapsing
+     * model only half of the border is counted, since the other half belongs to the
+     * following cell; also, the returned value is the maximum of the segments of each
+     * applicable grid unit.
+     * 
+     * @param rowIndex index of the span for which the border must be computed, 0-based
+     * @param which one of {@link ConditionalBorder#NORMAL},
+     * {@link ConditionalBorder#LEADING_TRAILING} or {@link ConditionalBorder#REST}
+     * @return the after border width
      */
-    public int getHalfMaxAfterBorderWidth() {
-        int value = 0;
-        if (getRows() != null) {
-            //Last row for after borders
-            int after = 0;
-            GridUnit[] row = (GridUnit[])getRows().get(getRows().size() - 1);
-            for (int i = 0; i < row.length; i++) {
-                if (row[i].hasBorders()) {
-                    after = Math.max(after, row[i].getBorders().getBorderAfterWidth(false));
+    public int getAfterBorderWidth(int rowIndex, int which) {
+        if (isSeparateBorderModel) {
+            if (getCell() == null) {
+                return 0;
+            } else {
+                CommonBorderPaddingBackground cellBorders = getCell()
+                        .getCommonBorderPaddingBackground();
+                switch (which) {
+                case ConditionalBorder.NORMAL:
+                case ConditionalBorder.LEADING_TRAILING:
+                    return cellBorders.getBorderAfterWidth(false) + halfBorderSeparationBPD;
+                case ConditionalBorder.REST:
+                    if (cellBorders.getBorderInfo(CommonBorderPaddingBackground.AFTER).getWidth()
+                            .isDiscard()) {
+                        return 0;
+                    } else {
+                        return cellBorders.getBorderAfterWidth(true) + halfBorderSeparationBPD;
+                    }
+                default:
+                    assert false;
+                    return 0;
                 }
             }
-            value += after / 2;
         } else {
-            if (hasBorders()) {
-                value += getBorders().getBorderAfterWidth(false) / 2;
+            int width = 0;
+            GridUnit[] row = (GridUnit[]) rows.get(rowIndex);
+            for (int i = 0; i < row.length; i++) {
+                width = Math.max(width,
+                        row[i].getBorderAfter(which).getRetainedWidth());
             }
+            return width / 2;
         }
-        return value;
     }
 
     /**
-     * @return the sum of half the maximum before and after border
-     * widths of this cell.
+     * Returns the width of the before-after for the last row-span of this cell. See
+     * {@link #getAfterBorderWidth(int, int)}.
+     * 
+     * @param which one of {@link ConditionalBorder#NORMAL},
+     * {@link ConditionalBorder#LEADING_TRAILING} or {@link ConditionalBorder#REST}
+     * @return the after border width
      */
-    public int getHalfMaxBorderWidth() {
-        return getHalfMaxBeforeBorderWidth() + getHalfMaxAfterBorderWidth();
+    public int getAfterBorderWidth(int which) {
+        return getAfterBorderWidth(getCell().getNumberRowsSpanned() - 1, which);
     }
 
     /** @return the length of the cell content. */
@@ -201,18 +270,18 @@
      */
     public int[] getStartEndBorderWidths() {
         int[] widths = new int[2];
-        if (rows == null) {
-            widths[0] = getBorders().getBorderStartWidth(false);
-            widths[1] = getBorders().getBorderEndWidth(false);
+        if (getCell() == null) {
+            return widths;
+        } else if (getCell().getTable().isSeparateBorderModel()) {
+            widths[0] = getCell().getCommonBorderPaddingBackground().getBorderStartWidth(false);
+            widths[1] = getCell().getCommonBorderPaddingBackground().getBorderEndWidth(false);
         } else {
             for (int i = 0; i < rows.size(); i++) {
                 GridUnit[] gridUnits = (GridUnit[])rows.get(i);
                 widths[0] = Math.max(widths[0],
-                        (gridUnits[0]).
-                            getBorders().getBorderStartWidth(false));
-                widths[1] = Math.max(widths[1],
-                        (gridUnits[gridUnits.length - 1]).
-                            getBorders().getBorderEndWidth(false));
+                        gridUnits[0].borderStart.getBorderInfo().getRetainedWidth());
+                widths[1] = Math.max(widths[1], gridUnits[gridUnits.length - 1].borderEnd
+                        .getBorderInfo().getRetainedWidth());
             }
         }
         return widths;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/Table.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/Table.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/Table.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/flow/table/Table.java Wed Jan 23 07:22:05 2008
@@ -395,7 +395,7 @@
      * @param index index of the column to be retrieved, 0-based
      * @return the corresponding column (may be an implicitly created column)
      */
-    TableColumn getColumn(int index) {
+    public TableColumn getColumn(int index) {
         return (TableColumn) columns.get(index);
     }
 
@@ -404,7 +404,7 @@
      * 
      * @return the number of columns, implicit or explicit, in this table
      */
-    int getNumberOfColumns() {
+    public int getNumberOfColumns() {
         return columns.size();
     }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TraitSetter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TraitSetter.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TraitSetter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/TraitSetter.java Wed Jan 23 07:22:05 2008
@@ -21,7 +21,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.fop.area.Area;
 import org.apache.fop.area.Trait;
 import org.apache.fop.datatypes.LengthBase;
@@ -31,6 +30,7 @@
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.fo.properties.CommonMarginBlock;
 import org.apache.fop.fo.properties.CommonTextDecoration;
+import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.traits.BorderProps;
 import org.apache.fop.traits.MinOptMax;
@@ -178,32 +178,30 @@
      * Layout managers that create areas with borders can use this to
      * add the borders to the area.
      * @param area the area to set the traits on.
-     * @param bordProps border properties
+     * @param borderBefore the resolved before border
+     * @param borderAfter the resolved after border
+     * @param borderStart the resolved start border
+     * @param borderEnd the resolved end border
      * @param outer 4 boolean values indicating if the side represents the 
      *     table's outer border. Order: before, after, start, end
-     * @param context Property evaluation context
      */
-    public static void addCollapsingBorders(Area area, 
-            CommonBorderPaddingBackground bordProps,
-            boolean[] outer,
-            PercentBaseContext context) {
-        BorderProps bps = getCollapsingBorderProps(bordProps, 
-                CommonBorderPaddingBackground.BEFORE, outer[0]);
+    public static void addCollapsingBorders(Area area,
+            BorderInfo borderBefore, BorderInfo borderAfter,
+            BorderInfo borderStart, BorderInfo borderEnd,
+            boolean[] outer) {
+        BorderProps bps = getCollapsingBorderProps(borderBefore, outer[0]);
         if (bps != null) {
             area.addTrait(Trait.BORDER_BEFORE, bps);
         }
-        bps = getCollapsingBorderProps(bordProps, 
-                CommonBorderPaddingBackground.AFTER, outer[1]);
+        bps = getCollapsingBorderProps(borderAfter, outer[1]);
         if (bps != null) {
             area.addTrait(Trait.BORDER_AFTER, bps);
         }
-        bps = getCollapsingBorderProps(bordProps, 
-                CommonBorderPaddingBackground.START, outer[2]);
+        bps = getCollapsingBorderProps(borderStart, outer[2]);
         if (bps != null) {
             area.addTrait(Trait.BORDER_START, bps);
         }
-        bps = getCollapsingBorderProps(bordProps, 
-                CommonBorderPaddingBackground.END, outer[3]);
+        bps = getCollapsingBorderProps(borderEnd, outer[3]);
         if (bps != null) {
             area.addTrait(Trait.BORDER_END, bps);
         }
@@ -270,13 +268,11 @@
         }
     }
 
-    private static BorderProps getCollapsingBorderProps(
-            CommonBorderPaddingBackground bordProps, int side, boolean outer) {
-        int width = bordProps.getBorderWidth(side, false);
+    private static BorderProps getCollapsingBorderProps(BorderInfo borderInfo, boolean outer) {
+        assert borderInfo != null;
+        int width = borderInfo.getRetainedWidth();
         if (width != 0) {
-            BorderProps bps;
-            bps = new BorderProps(bordProps.getBorderStyle(side),
-                    width, bordProps.getBorderColor(side),
+            BorderProps bps = new BorderProps(borderInfo.getStyle(), width, borderInfo.getColor(),
                     (outer ? BorderProps.COLLAPSE_OUTER : BorderProps.COLLAPSE_INNER));
             return bps;
         } else {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ActiveCell.java Wed Jan 23 07:22:05 2008
@@ -22,9 +22,11 @@
 import java.util.List;
 import java.util.ListIterator;
 
+import org.apache.fop.fo.flow.table.ConditionalBorder;
 import org.apache.fop.fo.flow.table.EffRow;
 import org.apache.fop.fo.flow.table.GridUnit;
 import org.apache.fop.fo.flow.table.PrimaryGridUnit;
+import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.layoutmgr.ElementListUtils;
 import org.apache.fop.layoutmgr.KnuthBox;
 import org.apache.fop.layoutmgr.KnuthElement;
@@ -39,15 +41,8 @@
     private List elementList;
     /** Iterator over the Knuth element list. */
     private ListIterator knuthIter;
-    private boolean prevIsBox = false;
     /** Number of the row where the row-span ends, zero-based. */
     private int endRowIndex;
-    /** Index, in the list of Knuth elements, of the element starting the current step. */
-    private int start;
-    /** Index, in the list of Knuth elements, of the element ending the current step. */
-    private int end;
-    /** Length of the Knuth elements up to the next feasible break. */
-    private int nextStepLength;
     /** Length of the Knuth elements not yet included in the steps. */
     private int remainingLength;
     /** Heights of the rows (in the row-group) preceding the one where this cell starts. */
@@ -56,17 +51,81 @@
     private int totalLength;
     /** Length of the Knuth elements already included in the steps. */
     private int includedLength;
-    private int borderBefore;
-    private int borderAfter;
-    private int paddingBefore;
-    private int paddingAfter;
+
+    private int borderBeforeNormal;
+    private int borderBeforeLeading;
+    private int borderAfterNormal;
+    private int borderAfterTrailing;
+    private int paddingBeforeNormal;
+    private int paddingBeforeLeading;
+    private int paddingAfterNormal;
+    private int paddingAfterTrailing;
+
     private boolean keepWithNextSignal;
-    /** Length of the penalty ending the last step, if any. */
-    private int lastPenaltyLength;
+
+    private int spanIndex = 0;
+    private CellPart lastCellPart;
+
+    private Step previousStep;
+    private Step nextStep;
+
+    /**
+     * Auxiliary class to store all the informations related to a breaking step.
+     */
+    private static class Step {
+        /** Index, in the list of Knuth elements, of the element starting this step. */
+        private int start;
+        /** Index, in the list of Knuth elements, of the element ending this step. */
+        private int end;
+        /** Length of the Knuth elements up to this step. */
+        private int contentLength;
+        /** Total length up to this step, including paddings and borders. */
+        private int totalLength;
+        /** Length of the penalty ending this step, if any. */
+        private int penaltyLength;
+        /**
+         * Length of the optional content for the next step. That is, content that will
+         * not appear if the next step starts a new page.
+         */
+        private int nextCondBeforeContentLength;
+
+        Step(int contentLength) {
+            this.contentLength = contentLength;
+            // TODO necessary if a cell part must be created while this cell hasn't
+            // contributed any content yet. To be removed along with the 900-penalty
+            // mechanism
+            this.end = -1;
+        }
+
+        Step(Step other) {
+            set(other);
+        }
+
+        void set(Step other) {
+            this.start         = other.start;
+            this.end           = other.end;
+            this.contentLength = other.contentLength;
+            this.totalLength   = other.totalLength;
+            this.penaltyLength = other.penaltyLength;
+            this.nextCondBeforeContentLength = other.nextCondBeforeContentLength;
+        }
+    }
 
     ActiveCell(PrimaryGridUnit pgu, EffRow row, int rowIndex, int previousRowsLength,
             TableLayoutManager tableLM) {
         this.pgu = pgu;
+        CommonBorderPaddingBackground bordersPaddings = pgu.getCell()
+                .getCommonBorderPaddingBackground();
+        borderBeforeNormal = pgu.getBeforeBorderWidth(0, ConditionalBorder.NORMAL);
+        borderBeforeLeading = pgu.getBeforeBorderWidth(0, ConditionalBorder.REST);
+        borderAfterNormal = pgu.getAfterBorderWidth(ConditionalBorder.NORMAL);
+        borderAfterTrailing = pgu.getAfterBorderWidth(0, ConditionalBorder.REST);
+        TableCellLayoutManager cellLM = pgu.getCellLM();
+        paddingBeforeNormal = bordersPaddings.getPaddingBefore(false, cellLM);
+        paddingBeforeLeading = bordersPaddings.getPaddingBefore(true, cellLM);
+        paddingAfterNormal = bordersPaddings.getPaddingAfter(false, cellLM);
+        paddingAfterTrailing = bordersPaddings.getPaddingAfter(true, cellLM);
+
         boolean makeBoxForWholeRow = false;
         if (row.getExplicitHeight().min > 0) {
             boolean contentsSmaller = ElementListUtils.removeLegalBreaks(
@@ -81,38 +140,24 @@
         }
         if (makeBoxForWholeRow) {
             elementList = new java.util.ArrayList(1);
-            int height = row.getExplicitHeight().opt;
-            if (height == 0) {
-                height = row.getHeight().opt;
-            }
+            int height = row.getHeight().opt;
+            height -= 2 * tableLM.getHalfBorderSeparationBPD();
+            height -= borderBeforeNormal + borderAfterNormal;  // TODO conditionals
+            height -= paddingBeforeNormal + paddingAfterNormal;
             elementList.add(new KnuthBoxCellWithBPD(height));
         } else {
             elementList = pgu.getElements();
-//          if (log.isTraceEnabled()) {
-//  log.trace("column " + (column+1) + ": recording " + elementLists.size() + " element(s)");
-//          }
         }
         knuthIter = elementList.listIterator();
         includedLength = -1;  // Avoid troubles with cells having content of zero length
         this.previousRowsLength = previousRowsLength;
-        nextStepLength = previousRowsLength;
         totalLength = previousRowsLength + ElementListUtils.calcContentLength(elementList);
-        if (tableLM.getTable().isSeparateBorderModel()) {
-            borderBefore = pgu.getBorders().getBorderBeforeWidth(false)
-                    + tableLM.getHalfBorderSeparationBPD();
-            borderAfter = pgu.getBorders().getBorderAfterWidth(false)
-                    + tableLM.getHalfBorderSeparationBPD();
-        } else {
-            borderBefore = pgu.getHalfMaxBeforeBorderWidth();
-            borderAfter = pgu.getHalfMaxAfterBorderWidth();
-        }
-        paddingBefore = pgu.getBorders().getPaddingBefore(false, pgu.getCellLM());
-        paddingAfter = pgu.getBorders().getPaddingAfter(false, pgu.getCellLM());
-        start = 0;
-        end = -1;
         endRowIndex = rowIndex + pgu.getCell().getNumberRowsSpanned() - 1;
         keepWithNextSignal = false;
         remainingLength = totalLength - previousRowsLength;
+
+        nextStep = new Step(previousRowsLength);
+        previousStep = new Step(nextStep);
         goToNextLegalBreak();
     }
 
@@ -139,36 +184,48 @@
         } else if (includedLength == totalLength) {
             return 0;
         } else {
-            return remainingLength + borderBefore + borderAfter + paddingBefore + paddingAfter;
+            return borderBeforeLeading + paddingBeforeLeading + remainingLength
+                    + paddingAfterNormal + borderAfterNormal;
         }
     }
 
     private void goToNextLegalBreak() {
-        lastPenaltyLength = 0;
+        nextStep.penaltyLength = 0;
         boolean breakFound = false;
+        boolean prevIsBox = false;
         while (!breakFound && knuthIter.hasNext()) {
             KnuthElement el = (KnuthElement) knuthIter.next();
             if (el.isPenalty()) {
                 prevIsBox = false;
                 if (el.getP() < KnuthElement.INFINITE) {
-                    //First legal break point
-                    lastPenaltyLength = el.getW();
+                    // First legal break point
+                    nextStep.penaltyLength = el.getW();
                     breakFound = true;
                 }
             } else if (el.isGlue()) {
                 if (prevIsBox) {
-                    //Second legal break point
+                    // Second legal break point
                     breakFound = true;
                 } else {
-                    nextStepLength += el.getW();
+                    nextStep.contentLength += el.getW();
                 }
                 prevIsBox = false;
             } else {
                 prevIsBox = true;
-                nextStepLength += el.getW();
+                nextStep.contentLength += el.getW();
             }
         }
-        end = knuthIter.nextIndex() - 1;
+        nextStep.end = knuthIter.nextIndex() - 1;
+        if (nextStep.end == elementList.size() - 1) {
+            // TODO wait that every cell on the row has finished before including border-after!!
+            nextStep.totalLength = borderBeforeNormal + paddingBeforeNormal
+                    + nextStep.contentLength + nextStep.penaltyLength
+                    + paddingAfterNormal + borderAfterNormal;
+        } else {
+            nextStep.totalLength = borderBeforeNormal + paddingBeforeNormal
+                    + nextStep.contentLength + nextStep.penaltyLength
+                    + paddingAfterTrailing + borderAfterTrailing; 
+        }
     }
 
     /**
@@ -177,23 +234,20 @@
      * @return the total length up to the next legal break (-1 signals no further step)
      */
     int getNextStep() {
-        if (!includedInLastStep()) {
-            return nextStepLength + lastPenaltyLength 
-                    + borderBefore + borderAfter + paddingBefore + paddingAfter;
-        } else {
-            start = end + 1;
-            if (knuthIter.hasNext()) {
-                goToNextLegalBreak();
-                return nextStepLength + lastPenaltyLength 
-                        + borderBefore + borderAfter + paddingBefore + paddingAfter; 
-            } else {
+        if (includedInLastStep()) {
+            previousStep.set(nextStep);
+            nextStep.start = nextStep.end + 1;
+            if (!knuthIter.hasNext()) {
                 return -1;
+            } else {
+                goToNextLegalBreak();
             }
         }
+        return nextStep.totalLength;
     }
 
     private boolean includedInLastStep() {
-        return includedLength == nextStepLength;
+        return includedLength == nextStep.contentLength;
     }
 
     /**
@@ -204,14 +258,26 @@
      * @return
      */
     boolean signalMinStep(int minStep) {
-        if (nextStepLength + lastPenaltyLength 
-                + borderBefore + borderAfter + paddingBefore + paddingAfter <= minStep) {
-            includedLength = nextStepLength;
+        if (nextStep.totalLength <= minStep) {
+            includedLength = nextStep.contentLength;
             computeRemainingLength();
             return false;
         } else {
-            return previousRowsLength + borderBefore 
-                    + borderAfter + paddingBefore + paddingAfter > minStep;
+            return borderBeforeNormal + paddingBeforeNormal + previousRowsLength
+                    + paddingAfterTrailing + borderAfterTrailing > minStep;
+        }
+    }
+
+    void endRow(int rowIndex) {
+        if (endsOnRow(rowIndex)) {
+            int bpAfterNormal = paddingAfterNormal + borderAfterNormal;
+            int bpAfterLast = paddingAfterNormal
+                    + pgu.getAfterBorderWidth(ConditionalBorder.LEADING_TRAILING);
+            lastCellPart.setLast(bpAfterNormal, bpAfterLast);
+        } else {
+            spanIndex++;
+            borderBeforeLeading = pgu.getBeforeBorderWidth(spanIndex, ConditionalBorder.REST);
+            borderAfterTrailing = pgu.getAfterBorderWidth(spanIndex, ConditionalBorder.REST);
         }
     }
 
@@ -221,13 +287,15 @@
      * paddings are not considered here.
      */
     private void computeRemainingLength() {
-        remainingLength = totalLength - nextStepLength;
+        remainingLength = totalLength - nextStep.contentLength;
+        nextStep.nextCondBeforeContentLength = 0;
         // Save the current location in the element list
         int oldIndex = knuthIter.nextIndex();
         KnuthElement el;
         while (knuthIter.hasNext() && !(el = (KnuthElement) knuthIter.next()).isBox()) {
             if (el.isGlue()) {
                 remainingLength -= el.getW();
+                nextStep.nextCondBeforeContentLength += el.getW();
             }
         }
         // Reset the iterator to the current location
@@ -244,7 +312,7 @@
     boolean contributesContent() {
         // return includedInLastStep() && the cell hasn't finished yet, otherwise there's
         // nothing more to contribute
-        return includedInLastStep() && end >= start;
+        return includedInLastStep() && nextStep.end >= nextStep.start;
     }
 
     /**
@@ -262,7 +330,7 @@
      * @return true if the end of this cell is reached
      */
     boolean isFinished() {
-        return includedInLastStep() && (end == elementList.size() - 1);
+        return includedInLastStep() && (nextStep.end == elementList.size() - 1);
     }
 
     /**
@@ -272,7 +340,7 @@
      * @return a CellPart instance
      */
     CellPart createCellPart() {
-        if (end + 1 == elementList.size()) {
+        if (nextStep.end + 1 == elementList.size()) {
             if (pgu.getFlag(GridUnit.KEEP_WITH_NEXT_PENDING)) {
                 keepWithNextSignal = true;
             }
@@ -280,22 +348,47 @@
                 keepWithNextSignal = true;
             }
         }
-        if (start == 0 && end == 0
+        int bpBeforeNormal;
+        int bpBeforeFirst;
+        int bpAfterNormal;
+        int bpAfterLast;
+        if (nextStep.start == 0) {
+            bpBeforeNormal = borderBeforeNormal + paddingBeforeNormal;
+            bpBeforeFirst = pgu.getBeforeBorderWidth(0, ConditionalBorder.LEADING_TRAILING)
+                    + paddingBeforeNormal;
+        } else {
+            bpBeforeNormal = 0;
+            bpBeforeFirst = borderBeforeLeading + paddingBeforeLeading;
+        }
+        bpAfterNormal = 0;
+        bpAfterLast = paddingAfterTrailing + borderAfterTrailing;
+        int length = nextStep.contentLength - previousStep.contentLength
+                - previousStep.nextCondBeforeContentLength;
+        if (!includedInLastStep() || nextStep.start == elementList.size()) {
+            lastCellPart = new CellPart(pgu, nextStep.start, previousStep.end,
+                    0, 0, previousStep.penaltyLength,
+                    bpBeforeNormal, bpBeforeFirst, bpAfterNormal, bpAfterLast);
+        } else if (nextStep.start == 0 && nextStep.end == 0
                 && elementList.size() == 1
                 && elementList.get(0) instanceof KnuthBoxCellWithBPD) {
             //Special case: Cell with fixed BPD
-            return new CellPart(pgu, 0, pgu.getElements().size() - 1);
+            lastCellPart = new CellPart(pgu, 0, pgu.getElements().size() - 1,
+                    previousStep.nextCondBeforeContentLength, length, nextStep.penaltyLength,
+                    bpBeforeNormal, bpBeforeFirst, bpAfterNormal, bpAfterLast);
         } else {
-            return new CellPart(pgu, start, end);
+            lastCellPart = new CellPart(pgu, nextStep.start, nextStep.end,
+                    previousStep.nextCondBeforeContentLength, length, nextStep.penaltyLength,
+                    bpBeforeNormal, bpBeforeFirst, bpAfterNormal, bpAfterLast);
         }
+        return lastCellPart;
     }
 
     boolean isLastForcedBreak() {
-        return ((KnuthElement)elementList.get(end)).isForcedBreak();
+        return ((KnuthElement)elementList.get(nextStep.end)).isForcedBreak();
     }
 
     int getLastBreakClass() {
-        return ((KnuthPenalty)elementList.get(end)).getBreakClass();
+        return ((KnuthPenalty)elementList.get(nextStep.end)).getBreakClass();
     }
 
     boolean keepWithNextSignal() {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/CellPart.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/CellPart.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/CellPart.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/CellPart.java Wed Jan 23 07:22:05 2008
@@ -23,7 +23,7 @@
 import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 
 /**
- * Represents a non-dividable part of a grid unit. Used by the table stepper.
+ * Represents a non-divisible part of a grid unit. Used by the table stepper.
  */
 class CellPart {
 
@@ -34,16 +34,47 @@
     /** Index of the ending element of this part */
     protected int end;
 
+    private int condBeforeContentLength;
+    private int length;
+    private int condAfterContentLength;
+    private int bpBeforeNormal;
+    private int bpBeforeFirst;
+    private int bpAfterNormal;
+    private int bpAfterLast;
+    private boolean isLast;
+
     /**
      * Creates a new CellPart.
+     * 
      * @param pgu Primary grid unit
      * @param start starting element
      * @param end ending element
+     * @param condBeforeContentLength length of the additional content that will have to
+     * be displayed if this part will be the first one on the page
+     * @param length length of the content represented by this cell part
+     * @param condAfterContentLength length of the additional content that will have to be
+     * displayed if this part will be the last one on the page
+     * @param bpBeforeNormal width of border- and padding-before in the normal case
+     * @param bpBeforeFirst width of (possibly optional) border- and padding-before if
+     * this part will be the first one on the page
+     * @param bpAfterNormal width of border- and padding-after in the normal case
+     * @param bpAfterFirst width of (possibly optional) border- and padding-after if this
+     * part will be the last one on the page
      */
-    protected CellPart(PrimaryGridUnit pgu, int start, int end) {
+    protected CellPart(PrimaryGridUnit pgu, int start, int end,
+            int condBeforeContentLength, int length, int condAfterContentLength,
+            int bpBeforeNormal, int bpBeforeFirst,
+            int bpAfterNormal, int bpAfterLast) {
         this.pgu = pgu;
         this.start = start;
         this.end = end;
+        this.condBeforeContentLength = condBeforeContentLength;
+        this.length = length;
+        this.condAfterContentLength = condAfterContentLength;
+        this.bpBeforeNormal = bpBeforeNormal;
+        this.bpBeforeFirst = bpBeforeFirst;
+        this.bpAfterNormal = bpAfterNormal;
+        this.bpAfterLast = bpAfterLast;
     }
 
     /** @return true if this part is the first part of a cell */
@@ -52,8 +83,42 @@
     }
 
     /** @return true if this part is the last part of a cell */
-    public boolean isLastPart() {
-        return (end >= 0 && end == pgu.getElements().size() - 1);
+    boolean isLastPart() {
+        return isLast;
+    }
+
+    void setLast(int bpNormal, int bpLast) {
+        isLast = true;
+        bpAfterNormal = bpNormal;
+        bpAfterLast = bpLast;
+    }
+
+    int getBorderPaddingBefore(boolean firstOnPage) {
+        if (firstOnPage) {
+            return bpBeforeFirst;
+        } else {
+            return bpBeforeNormal;
+        }
+    }
+
+    int getBorderPaddingAfter(boolean lastOnPage) {
+        if (lastOnPage) {
+            return bpAfterLast;
+        } else {
+            return bpAfterNormal;
+        }
+    }
+
+    int getConditionalBeforeContentLength() {
+        return condBeforeContentLength;
+    }
+
+    int getLength() {
+        return length;
+    }
+
+    int getConditionalAfterContentLength() {
+        return condAfterContentLength;
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowGroupLayoutManager.java Wed Jan 23 07:22:05 2008
@@ -34,7 +34,6 @@
 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.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthPenalty;
 import org.apache.fop.layoutmgr.LayoutContext;
@@ -239,13 +238,7 @@
                         effectiveCellBPD = Math.max(effectiveCellBPD, 
                                 primary.getContentLength());
                         
-                        int borderWidths;
-                        if (tableLM.getTable().isSeparateBorderModel()) {
-                            borderWidths = primary.getBorders().getBorderBeforeWidth(false)
-                                    + primary.getBorders().getBorderAfterWidth(false);
-                        } else {
-                            borderWidths = primary.getHalfMaxBorderWidth();
-                        }
+                        int borderWidths = primary.getBeforeAfterBorderWidth();
                         int padding = 0;
                         maxCellBPD = Math.max(maxCellBPD, effectiveCellBPD);
                         CommonBorderPaddingBackground cbpb 
@@ -253,8 +246,7 @@
                         padding += cbpb.getPaddingBefore(false, primary.getCellLM());
                         padding += cbpb.getPaddingAfter(false, primary.getCellLM());
                         int effRowHeight = effectiveCellBPD 
-                                + padding + borderWidths
-                                + 2 * tableLM.getHalfBorderSeparationBPD();
+                                + padding + borderWidths;
                         for (int previous = 0; previous < gu.getRowSpanIndex(); previous++) {
                             effRowHeight -= rowHeights[rgi - previous - 1].opt;
                         }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowPainter.java?rev=614566&r1=614565&r2=614566&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowPainter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/RowPainter.java Wed Jan 23 07:22:05 2008
@@ -26,16 +26,17 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.fop.fo.flow.table.ConditionalBorder;
 import org.apache.fop.fo.flow.table.EffRow;
 import org.apache.fop.fo.flow.table.GridUnit;
 import org.apache.fop.fo.flow.table.PrimaryGridUnit;
 import org.apache.fop.fo.flow.table.TableRow;
-import org.apache.fop.fo.properties.LengthRangeProperty;
 import org.apache.fop.layoutmgr.ElementListUtils;
 import org.apache.fop.layoutmgr.KnuthElement;
 import org.apache.fop.layoutmgr.KnuthPossPosIter;
 import org.apache.fop.layoutmgr.LayoutContext;
 import org.apache.fop.layoutmgr.SpaceResolver;
+import org.apache.fop.traits.BorderProps;
 
 class RowPainter {
     private static Log log = LogFactory.getLog(RowPainter.class);
@@ -50,6 +51,14 @@
      * Index of the first row of the current part present on the current page.
      */
     private int firstRowIndex;
+
+    /**
+     * Index of the very first row on the current page. Needed to properly handle
+     * {@link BorderProps#COLLAPSE_OUTER}. This is not the same as {@link #firstRowIndex}
+     * when the table has headers!
+     */
+    private int firstRowOnPageIndex;
+
     /**
      * Keeps track of the y-offsets of each row on a page.
      * This is particularly needed for spanned cells where you need to know the y-offset
@@ -57,36 +66,23 @@
      */
     private List rowOffsets = new ArrayList();
 
-    //These three variables are our buffer to recombine the individual steps into cells
-    /** Primary grid units corresponding to the currently handled grid units, per row. */
-    private PrimaryGridUnit[] primaryGridUnits;
-    /**
-     * Index, in the corresponding table cell's list of Knuth elements, of the first
-     * element present on the current page, per column.
-     */
-    private int[] start;
-    /**
-     * Index, in the corresponding table cell's list of Knuth elements, of the last
-     * element present on the current page, per column.
-     */
-    private int[] end;
-    /**
-     * Length, for each column, of the elements from the current cell put on the
-     * current page. This is the corresponding area's bpd.
-     */
-    private int[] partBPD;
+    private int[] cellHeights;
+    private boolean[] firstCellOnPage;
+    private CellPart[] firstCellParts;
+    private CellPart[] lastCellParts;
+
     private TableContentLayoutManager tclm;
 
     RowPainter(TableContentLayoutManager tclm, LayoutContext layoutContext) {
         this.tclm = tclm;
         this.layoutContext = layoutContext;
         this.colCount = tclm.getColumns().getColumnCount();
-        this.primaryGridUnits = new PrimaryGridUnit[colCount];
-        this.start = new int[colCount];
-        this.end = new int[colCount];
-        this.partBPD = new int[colCount];
+        this.cellHeights = new int[colCount];
+        this.firstCellOnPage = new boolean[colCount];
+        this.firstCellParts = new CellPart[colCount];
+        this.lastCellParts = new CellPart[colCount];
         this.firstRowIndex = -1;
-        Arrays.fill(end, -1);
+        this.firstRowOnPageIndex = -1;
     }
 
     int getAccumulatedBPD() {
@@ -101,7 +97,7 @@
      */
     void handleTableContentPosition(TableContentPosition tcpos) {
         if (tcpos.row != currentRow && currentRow != null) {
-            addAreasAndFlushRow(false);
+            addAreasAndFlushRow(false, false);
         }
         if (log.isDebugEnabled()) {
             log.debug("===handleTableContentPosition(" + tcpos);
@@ -110,6 +106,9 @@
         currentRow = tcpos.row;
         if (firstRowIndex < 0) {
             firstRowIndex = currentRow.getIndex();
+            if (firstRowOnPageIndex < 0) {
+                firstRowOnPageIndex = firstRowIndex;
+            }
         }
         Iterator partIter = tcpos.cellParts.iterator();
         //Iterate over all grid units in the current step
@@ -119,173 +118,153 @@
                 log.debug(">" + cellPart);
             }
             int colIndex = cellPart.pgu.getStartCol();
-            if (primaryGridUnits[colIndex] != cellPart.pgu) {
-                if (primaryGridUnits[colIndex] != null) {
-                    log.warn("Replacing GU in slot " + colIndex
-                            + ". Some content may not be painted.");
-                }
-                primaryGridUnits[colIndex] = cellPart.pgu;
-                start[colIndex] = cellPart.start;
-                end[colIndex] = cellPart.end;
+            if (firstCellParts[colIndex] == null) {
+                firstCellParts[colIndex] = cellPart;
+                cellHeights[colIndex] = cellPart.getBorderPaddingBefore(firstCellOnPage[colIndex]);
             } else {
-                if (cellPart.end < end[colIndex]) {
-                    throw new IllegalStateException("Internal Error: stepper problem");
-                }
-                end[colIndex] = cellPart.end;
+                assert firstCellParts[colIndex].pgu == cellPart.pgu; 
+                cellHeights[colIndex] += cellPart.getConditionalBeforeContentLength();
             }
+            cellHeights[colIndex] += cellPart.getLength();
+            lastCellParts[colIndex] = cellPart;
         }
     }
 
     /**
-     * Create the areas corresponding to the last row. This method is called either
-     * because the row is finished (all of the elements present on this row have been
-     * added), or because this is the last row on the current page, and the part of it
-     * lying on the current page must be drawn.
+     * Creates the areas corresponding to the last row. That is, an area with background
+     * for the row, plus areas for all the cells that finish on the row (not spanning over
+     * further rows).
      * 
-     * @param forcedFlush true if the elements must be drawn even if the row isn't
-     * finished yet (last row on the page), or if the row is the last of the current table
-     * part
+     * @param lastInPart true if the row is the last from its table part to be displayed
+     * on the current page. In which case all the cells must be flushed even if they
+     * aren't finished, plus the proper collapsed borders must be selected (trailing
+     * instead of normal, or rest if the cell is unfinished)
+     * @param lastOnPage true if the row is the very last row of the table that will be
+     * displayed on the current page. In which case collapsed after borders must be drawn
+     * in the outer mode
      */
-    void addAreasAndFlushRow(boolean forcedFlush) {
-        int actualRowHeight = 0;
-
+    void addAreasAndFlushRow(boolean lastInPart, boolean lastOnPage) {
         if (log.isDebugEnabled()) {
             log.debug("Remembering yoffset for row " + currentRow.getIndex() + ": "
                     + currentRowOffset);
         }
         recordRowOffset(currentRow.getIndex(), currentRowOffset);
 
-        for (int i = 0; i < primaryGridUnits.length; i++) {
-            if ((primaryGridUnits[i] != null)
-                    && (forcedFlush || (end[i] == primaryGridUnits[i].getElements().size() - 1))) {
-                actualRowHeight = Math.max(actualRowHeight, computeSpanHeight(
-                        primaryGridUnits[i], start[i], end[i], i));
+        // Need to compute the actual row height first
+        int actualRowHeight = 0;
+        for (int i = 0; i < colCount; i++) {
+            GridUnit currentGU = currentRow.getGridUnit(i);            
+            if (!currentGU.isEmpty() && currentGU.getColSpanIndex() == 0
+                    && (lastInPart || currentGU.isLastGridUnitRowSpan())) {
+                int cellHeight = cellHeights[i];
+                cellHeight += lastCellParts[i].getConditionalAfterContentLength();
+                cellHeight += lastCellParts[i].getBorderPaddingAfter(lastInPart);
+                int cellOffset = getRowOffset(Math.max(firstCellParts[i].pgu.getStartRow(),
+                        firstRowIndex));
+                actualRowHeight = Math.max(actualRowHeight, cellOffset + cellHeight
+                        - currentRowOffset);
             }
         }
-        actualRowHeight += 2 * tclm.getTableLM().getHalfBorderSeparationBPD();
 
-        //Add areas for row
+        // Then add areas for cells finishing on the current row
         tclm.addRowBackgroundArea(rowFO, actualRowHeight, layoutContext.getRefIPD(),
                 currentRowOffset);
-        for (int i = 0; i < primaryGridUnits.length; i++) {
+        for (int i = 0; i < colCount; i++) {
             GridUnit currentGU = currentRow.getGridUnit(i);            
             if (!currentGU.isEmpty() && currentGU.getColSpanIndex() == 0
-                    && (forcedFlush || currentGU.isLastGridUnitRowSpan())) {
-                addAreasForCell(currentGU.getPrimary(), start[i], end[i], currentRow, partBPD[i],
-                        actualRowHeight);
-                primaryGridUnits[i] = null;
-                start[i] = 0;
-                end[i] = -1;
-                partBPD[i] = 0;
+                    && (lastInPart || currentGU.isLastGridUnitRowSpan())) {
+                assert firstCellParts[i].pgu == currentGU.getPrimary();
+                int borderBeforeWhich;
+                if (firstCellParts[i].start == 0) {
+                    if (firstCellOnPage[i]) {
+                        borderBeforeWhich = ConditionalBorder.LEADING_TRAILING;
+                    } else {
+                        borderBeforeWhich = ConditionalBorder.NORMAL;
+                    }
+                } else {
+                    assert firstCellOnPage[i];
+                    borderBeforeWhich = ConditionalBorder.REST;
+                }
+                int borderAfterWhich;
+                if (lastCellParts[i].isLastPart()) {
+                    if (lastInPart) {
+                        borderAfterWhich = ConditionalBorder.LEADING_TRAILING;
+                    } else {
+                        borderAfterWhich = ConditionalBorder.NORMAL;
+                    }
+                } else {
+                    borderAfterWhich = ConditionalBorder.REST;
+                }
+                addAreasForCell(firstCellParts[i].pgu,
+                        firstCellParts[i].start, lastCellParts[i].end,
+                        actualRowHeight, borderBeforeWhich, borderAfterWhich,
+                        lastOnPage);
+                firstCellParts[i] = null;
+                firstCellOnPage[i] = false;
             }
         }
         currentRowOffset += actualRowHeight;
-        if (forcedFlush) {
-            // Either the end of the page is reached, then this was the last call of this
-            // method and we no longer care about currentRow; or the end of a table-part
-            // (header, footer, body) has been reached, and the next row will anyway be
-            // different from the current one, and this is unnecessary to recall this
-            // method in the first lines of handleTableContentPosition, so we may reset
-            // the following variables
+        if (lastInPart) {
+            /*
+             * Either the end of the page is reached, then this was the last call of this
+             * method and we no longer care about currentRow; or the end of a table-part
+             * (header, footer, body) has been reached, and the next row will anyway be
+             * different from the current one, and this is unnecessary to call this method
+             * again in the first lines of handleTableContentPosition, so we may reset the
+             * following variables.
+             */
             currentRow = null;
             firstRowIndex = -1;
             rowOffsets.clear();
+            /*
+             * The current table part has just been handled. Be it the first one or not,
+             * the header or the body, in any case the borders-before of the next row
+             * (i.e., the first row of the next part if any) must be painted in
+             * COLLAPSE_INNER mode. So the firstRowOnPageIndex indicator must be kept
+             * disabled. The following way is not the most elegant one but will be good
+             * enough.
+             */
+            firstRowOnPageIndex = Integer.MAX_VALUE;
         }
     }
 
-    /**
-     * Computes the total height of the part of the given cell spanning on the current
-     * active row, including borders and paddings. The bpd is also stored in partBPD, and
-     * it is ensured that the cell's or row's explicit height is respected.
-     * 
-     * @param pgu primary grid unit corresponding to the cell
-     * @param start index of the first element of the cell occuring on the current page
-     * @param end index of the last element of the cell occuring on the current page
-     * @param columnIndex column index of the cell
-     * @param bodyType {@link TableRowIterator#HEADER}, {@link TableRowIterator#FOOTER}, or
-     * {@link TableRowIterator#BODY}
-     * @return the cell's height
-     */
-    private int computeSpanHeight(PrimaryGridUnit pgu, int start, int end, int columnIndex) {
-        if (log.isTraceEnabled()) {
-            log.trace("getting len for " + columnIndex + " "
-                    + start + "-" + end);
-        }
-        int actualStart = start;
-        // Skip from the content length calculation glues and penalties occuring at the
+    // TODO this is not very efficient and should probably be done another way
+    // this method is only necessary when display-align = center or after, in which case
+    // the exact content length is needed to compute the size of the empty block that will
+    // be used as padding.
+    // This should be handled automatically by a proper use of Knuth elements
+    private int computeContentLength(PrimaryGridUnit pgu, int startIndex, int endIndex) {
+        int actualStart = startIndex;
+        // Skip from the content length calculation glues and penalties occurring at the
         // beginning of the page
-        while (actualStart <= end && !((KnuthElement)pgu.getElements().get(actualStart)).isBox()) {
+        while (actualStart <= endIndex
+                && !((KnuthElement) pgu.getElements().get(actualStart)).isBox()) {
             actualStart++;
         }
         int len = ElementListUtils.calcContentLength(
-                pgu.getElements(), actualStart, end);
-        KnuthElement el = (KnuthElement)pgu.getElements().get(end);
+                pgu.getElements(), actualStart, endIndex);
+        KnuthElement el = (KnuthElement)pgu.getElements().get(endIndex);
         if (el.isPenalty()) {
             len += el.getW();
         }
-        partBPD[columnIndex] = len;
-        if (log.isTraceEnabled()) {
-            log.trace("len of part: " + len);
-        }
-
-        if (start == 0) {
-            LengthRangeProperty bpd = pgu.getCell()
-                    .getBlockProgressionDimension();
-            if (!bpd.getMinimum(tclm.getTableLM()).isAuto()) {
-                int min = bpd.getMinimum(tclm.getTableLM())
-                            .getLength().getValue(tclm.getTableLM());
-                if (min > 0) {
-                    len = Math.max(len, min);
-                }
-            }
-            if (!bpd.getOptimum(tclm.getTableLM()).isAuto()) {
-                int opt = bpd.getOptimum(tclm.getTableLM())
-                            .getLength().getValue(tclm.getTableLM());
-                if (opt > 0) {
-                    len = Math.max(len, opt);
-                }
-            }
-            if (pgu.getRow() != null) {
-                bpd = pgu.getRow().getBlockProgressionDimension();
-                if (!bpd.getMinimum(tclm.getTableLM()).isAuto()) {
-                    int min = bpd.getMinimum(tclm.getTableLM()).getLength()
-                                .getValue(tclm.getTableLM());
-                    if (min > 0) {
-                        len = Math.max(len, min);
-                    }
-                }
-            }
-        }
-
-        // Add the padding if any
-        len += pgu.getBorders()
-                        .getPaddingBefore(false, pgu.getCellLM());
-        len += pgu.getBorders()
-                        .getPaddingAfter(false, pgu.getCellLM());
-
-        //Now add the borders to the contentLength
-        if (tclm.isSeparateBorderModel()) {
-            len += pgu.getBorders().getBorderBeforeWidth(false);
-            len += pgu.getBorders().getBorderAfterWidth(false);
-        } else {
-            len += pgu.getHalfMaxBeforeBorderWidth();
-            len += pgu.getHalfMaxAfterBorderWidth();
-        }
-        int cellOffset = getRowOffset(Math.max(pgu.getStartRow(), firstRowIndex));
-        len -= currentRowOffset - cellOffset;
         return len;
     }
 
     private void addAreasForCell(PrimaryGridUnit pgu, int startPos, int endPos,
-            EffRow row, int contentHeight, int rowHeight) {
-        //Determine the first row in this sequence
+            int rowHeight, int borderBeforeWhich, int borderAfterWhich, boolean lastOnPage) {
+        /*
+         * Determine the index of the first row of this cell that will be displayed on the
+         * current page.
+         */
         int startRowIndex = Math.max(pgu.getStartRow(), firstRowIndex);
         int currentRowIndex = currentRow.getIndex();
 
-        // In collapsing-border model, if the cell spans over several columns/rows then
-        // dedicated areas will be created for each grid unit to hold the corresponding
-        // borders. For that we need to know the height of each grid unit, that is of each
-        // grid row spanned over by the cell
+        /*
+         * In collapsing-border model, if the cell spans over several columns/rows then
+         * dedicated areas will be created for each grid unit to hold the corresponding
+         * borders. For that we need to know the height of each grid unit, that is of each
+         * grid row spanned over by the cell
+         */
         int[] spannedGridRowHeights = null;
         if (!tclm.getTableLM().getTable().isSeparateBorderModel() && pgu.hasSpanning()) {
             spannedGridRowHeights = new int[currentRowIndex - startRowIndex + 1];
@@ -297,24 +276,19 @@
             }
             spannedGridRowHeights[currentRowIndex - startRowIndex] = rowHeight;
         }
-
         int cellOffset = getRowOffset(startRowIndex);
-        int effCellHeight = rowHeight;
-        effCellHeight += currentRowOffset - cellOffset;
+        int cellTotalHeight = rowHeight + currentRowOffset - cellOffset;
         if (log.isDebugEnabled()) {
             log.debug("Creating area for cell:");
-            log.debug("  current row: " + row.getIndex());
             log.debug("  start row: " + pgu.getStartRow() + " " + currentRowOffset + " "
                     + cellOffset);
-            log.debug("  contentHeight: " + contentHeight + " rowHeight=" + rowHeight
-                    + " effCellHeight=" + effCellHeight);
+            log.debug(" rowHeight=" + rowHeight + " cellTotalHeight=" + cellTotalHeight);
         }
         TableCellLayoutManager cellLM = pgu.getCellLM();
         cellLM.setXOffset(tclm.getXOffsetOfGridUnit(pgu));
         cellLM.setYOffset(cellOffset);
-        cellLM.setContentHeight(contentHeight);
-        cellLM.setRowHeight(effCellHeight);
-        //cellLM.setRowHeight(row.getHeight().opt);
+        cellLM.setContentHeight(computeContentLength(pgu, startPos, endPos));
+        cellLM.setTotalHeight(cellTotalHeight);
         int prevBreak = ElementListUtils.determinePreviousBreak(pgu.getElements(), startPos);
         if (endPos >= 0) {
             SpaceResolver.performConditionalsNotification(pgu.getElements(),
@@ -322,7 +296,8 @@
         }
         cellLM.addAreas(new KnuthPossPosIter(pgu.getElements(), startPos, endPos + 1),
                 layoutContext, spannedGridRowHeights, startRowIndex - pgu.getStartRow(),
-                currentRowIndex - pgu.getStartRow() + 1);
+                currentRowIndex - pgu.getStartRow(), borderBeforeWhich, borderAfterWhich,
+                startRowIndex == firstRowOnPageIndex, lastOnPage);
     }
 
     /**
@@ -357,5 +332,15 @@
      */
     private int getRowOffset(int rowIndex) {
         return ((Integer) rowOffsets.get(rowIndex - firstRowIndex)).intValue();
+    }
+
+    // TODO get rid of that
+    void startBody() {
+        Arrays.fill(firstCellOnPage, true);
+    }
+
+    // TODO get rid of that
+    void endBody() {
+        Arrays.fill(firstCellOnPage, false);
     }
 }



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