On Dec 24, 2006, at 09:53, Andreas L Delmelle wrote:

<snip />
Just had another look, and it currently only works correctly in case there is no column-spanning going on in any of the cells in the first row.


<fo:table>
  <fo:table-body>
    <fo:table-cell width="2in" number-columns-spanned="2">
...

In this case, two implicit columns are created, but the cell's width is not yet distributed over the two columns.

I'll add a testcase demonstrating what still goes wrong, but the issue probably needs to put in a slightly different wording, indicating that it works apart from the above reservation.

In the meantime, I've locally patched FOP to correctly deal with this.

Patch consists of a few changes in TableBody, TableRow and PercentLength. The latter only because I needed to have some way to be able to get the percentage value of the cell-width, divide it by the number of columns spanned, and construct a new PercentLength with the percentage distributed over the number of columns.

Full patch below.

If no one objects, I'll commit this to the trunk and the release branch, so this issue is out of the way.

Cheers,

Andreas

Index: src/java/org/apache/fop/fo/flow/TableBody.java
===================================================================
--- src/java/org/apache/fop/fo/flow/TableBody.java (revision 489884)
+++ src/java/org/apache/fop/fo/flow/TableBody.java      (working copy)
@@ -40,6 +40,9 @@
import org.apache.fop.fo.properties.CommonAural;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.fo.properties.CommonRelativePosition;
+import org.apache.fop.fo.properties.FixedLength;
+import org.apache.fop.fo.properties.LengthProperty;
+import org.apache.fop.fo.properties.PercentLength;
/**
  * Class modelling the fo:table-body object.
@@ -80,7 +83,7 @@
     /**
      * @see FObj#bind(PropertyList)
      */
-    public void bind(PropertyList pList) throws FOPException {
+    protected void bind(PropertyList pList) throws FOPException {
commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
         super.bind(pList);
         //Used by convertCellsToRows()
@@ -201,9 +204,16 @@
                     int colSpan = cell.getNumberColumnsSpanned();
                     Length colWidth = null;
-                    if (cell.getWidth().getEnum() != EN_AUTO
-                            && colSpan == 1) {
-                        colWidth = cell.getWidth();
+                    if (cell.getWidth().getEnum() != EN_AUTO) {
+ LengthProperty p = (LengthProperty) cell.getWidth();
+                        if (p instanceof FixedLength) {
+ colWidth = new FixedLength(p.getValue () / colSpan);
+                        } else if (p instanceof PercentLength) {
+ PercentLength pctLength = (PercentLength) p; + double factor = pctLength.getPercentage () / 100; + colWidth = new PercentLength(factor / colSpan,
+                                            pctLength.getBaseLength());
+                        }
                     }

                     for (int i = colNr; i < colNr + colSpan; ++i) {
Index: src/java/org/apache/fop/fo/flow/TableRow.java
===================================================================
--- src/java/org/apache/fop/fo/flow/TableRow.java (revision 489884)
+++ src/java/org/apache/fop/fo/flow/TableRow.java       (working copy)
@@ -34,8 +34,11 @@
import org.apache.fop.fo.properties.CommonAural;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.fo.properties.CommonRelativePosition;
+import org.apache.fop.fo.properties.FixedLength;
import org.apache.fop.fo.properties.KeepProperty;
+import org.apache.fop.fo.properties.LengthProperty;
import org.apache.fop.fo.properties.LengthRangeProperty;
+import org.apache.fop.fo.properties.PercentLength;
/**
  * Class modelling the fo:table-row object.
@@ -74,7 +77,7 @@
     /**
      * @see org.apache.fop.fo.FObj#bind(PropertyList)
      */
-    public void bind(PropertyList pList) throws FOPException {
+    protected void bind(PropertyList pList) throws FOPException {
         blockProgressionDimension
= pList.get (PR_BLOCK_PROGRESSION_DIMENSION).getLengthRange(); commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps();
@@ -133,9 +136,16 @@
                 int colSpan = cell.getNumberColumnsSpanned();
                 Length colWidth = null;
-                if (cell.getWidth().getEnum() != EN_AUTO
-                        && colSpan == 1) {
-                    colWidth = cell.getWidth();
+                if (cell.getWidth().getEnum() != EN_AUTO) {
+ LengthProperty p = (LengthProperty) cell.getWidth ();
+                    if (p instanceof FixedLength) {
+ colWidth = new FixedLength(p.getValue() / colSpan);
+                    } else if (p instanceof PercentLength) {
+                        PercentLength pctLength = (PercentLength) p;
+ double factor = pctLength.getPercentage() / 100;
+                        colWidth = new PercentLength(factor / colSpan,
+                                        pctLength.getBaseLength());
+                    }
                 }

                 for (int i = colNr; i < colNr + colSpan; ++i) {
Index: src/java/org/apache/fop/fo/properties/PercentLength.java
===================================================================
--- src/java/org/apache/fop/fo/properties/PercentLength.java (revision 489884) +++ src/java/org/apache/fop/fo/properties/PercentLength.java (working copy)
@@ -68,8 +68,8 @@
      *
      * @return the percentage value
      */
-    protected double getPercentage() {
-        return factor * 100;
+    public double getPercentage() {
+        return factor * 100.0;
     }
     /**

Reply via email to