Author: spepping
Date: Thu Apr 24 10:46:31 2008
New Revision: 651323

URL: http://svn.apache.org/viewvc?rev=651323&view=rev
Log:
Improve table-unit computation if proportional-column-width() is used
as a subexpression. Fixes bug 44658.

Added:
    
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml
   (with props)
Modified:
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LengthProperty.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java?rev=651323&r1=651322&r2=651323&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java
 Thu Apr 24 10:46:31 2008
@@ -23,6 +23,7 @@
 import org.apache.fop.datatypes.PercentBaseContext;
 import org.apache.fop.datatypes.Numeric;
 import org.apache.fop.fo.properties.Property;
+import org.apache.fop.fo.properties.TableColLength;
 
 
 /**
@@ -31,7 +32,7 @@
  * to delay evaluation of the operation until the time where getNumericValue()
  * or getValue() is called. 
  */
-public class RelativeNumericProperty extends Property implements Numeric, 
Length {
+public class RelativeNumericProperty extends Property implements Length {
     public static final int ADDITION = 1;
     public static final int SUBTRACTION = 2;
     public static final int MULTIPLY = 3;
@@ -56,7 +57,7 @@
     /**
      * The second operand.
      */
-    private Numeric op2;
+    private Numeric op2 = null;
     /**
      * The dimension of the result.
      */
@@ -99,6 +100,7 @@
     /**
      * Return a resolved (calculated) Numeric with the value of the expression.
      * @param context Evaluation context
+     * @return the resolved [EMAIL PROTECTED] Numeric} corresponding to the 
value of the expression
      * @throws PropertyException when an exception occur during evaluation.
      */
     private Numeric getResolved(PercentBaseContext context) throws 
PropertyException {
@@ -193,6 +195,53 @@
             log.error(exc);
         }
         return 0;
+    }
+
+    /**
+     * Return the number of table units which are included in this
+     * length specification.
+     * This will always be 0 unless the property specification used
+     * the proportional-column-width() function (only on table
+     * column FOs).
+     * <p>If this value is not 0, the actual value of the Length cannot
+     * be known without looking at all of the columns in the table to
+     * determine the value of a "table-unit".
+     * @return The number of table units which are included in this
+     * length specification.
+     */
+    public double getTableUnits() {
+       double tu1 = 0.0, tu2 = 0.0;
+       if (op1 instanceof RelativeNumericProperty) {
+               tu1 = ((RelativeNumericProperty) op1).getTableUnits();
+       } else if (op1 instanceof TableColLength) {
+               tu1 = ((TableColLength) op1).getTableUnits();
+       }
+       if (op2 instanceof RelativeNumericProperty) {
+               tu2 = ((RelativeNumericProperty) op2).getTableUnits();
+       } else if (op2 instanceof TableColLength) {
+               tu2 = ((TableColLength) op2).getTableUnits();
+       }
+       if (tu1 != 0.0 && tu2 != 0.0) {
+               switch (operation) {
+               case ADDITION: return tu1 + tu2;
+               case SUBTRACTION: return tu1 - tu2;
+               case MULTIPLY: return tu1 * tu2;
+               case DIVIDE: return tu1 / tu2;
+               case MODULO: return tu1 % tu2;
+               case MIN: return Math.min(tu1, tu2);
+               case MAX: return Math.max(tu1, tu2);
+               default: assert false;
+               }
+       } else if (tu1 != 0.0) {
+               switch (operation) {
+               case NEGATE: return -tu1;
+               case ABS: return Math.abs(tu1);
+               default: return tu1;
+               }
+       } else if (tu2 != 0.0){
+               return tu2;
+       }
+       return 0.0;
     }
 
     /**

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LengthProperty.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LengthProperty.java?rev=651323&r1=651322&r2=651323&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LengthProperty.java 
(original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LengthProperty.java 
Thu Apr 24 10:46:31 2008
@@ -71,22 +71,6 @@
 
     }
 
-    /**
-     * Return the number of table units which are included in this
-     * length specification.
-     * This will always be 0 unless the property specification used
-     * the proportional-column-width() function (only only table
-     * column FOs).
-     * <p>If this value is not 0, the actual value of the Length cannot
-     * be known without looking at all of the columns in the table to
-     * determine the value of a "table-unit".
-     * @return The number of table units which are included in this
-     * length specification.
-     */
-    public double getTableUnits() {
-        return 0.0;
-    }
-
     /** @return the numeric dimension. Length always a dimension of 1 */
     public int getDimension() {
         return 1;

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java?rev=651323&r1=651322&r2=651323&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java 
(original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java 
Thu Apr 24 10:46:31 2008
@@ -29,6 +29,7 @@
 import org.apache.fop.datatypes.Length;
 import org.apache.fop.datatypes.PercentBaseContext;
 import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.expr.RelativeNumericProperty;
 import org.apache.fop.fo.flow.table.Table;
 import org.apache.fop.fo.flow.table.TableColumn;
 import org.apache.fop.fo.properties.TableColLength;
@@ -196,7 +197,9 @@
             Length colWidth = (Length) i.next();
             if (colWidth != null) {
                 sumCols += colWidth.getValue(tlm);
-                if (colWidth instanceof TableColLength) {
+                if (colWidth instanceof RelativeNumericProperty) {
+                    factors += ((RelativeNumericProperty) 
colWidth).getTableUnits();
+                } else if (colWidth instanceof TableColLength) {
                     factors += ((TableColLength) colWidth).getTableUnits();
                 }
             }

Added: 
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml?rev=651323&view=auto
==============================================================================
--- 
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml
 (added)
+++ 
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml
 Thu Apr 24 10:46:31 2008
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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 the calculation of table units when the column
+      widths are a mixture of fixed and proportional widths.
+    </p>
+  </info>
+  <fo>
+    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>
+      <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:table table-layout="fixed" width="100%">
+            <fo:table-column column-number="1" column-width="2pt + 
proportional-column-width(1)" />
+            <fo:table-column column-number="2" 
column-width="proportional-column-width(1) + 2pt" />
+            <fo:table-column column-number="3"
+            column-width="proportional-column-width(.5) + 2pt + 
proportional-column-width(.5)" />
+            <fo:table-body>
+              <fo:table-cell border="solid 0.5pt black" starts-row="true">
+                <fo:block>Cell 1.1</fo:block>
+              </fo:table-cell>
+              <fo:table-cell border="solid 0.5pt red">
+                <fo:block>Cell 2.2</fo:block>
+              </fo:table-cell>
+              <fo:table-cell border="solid 0.5pt yellow" ends-row="true">
+                <fo:block>Cell 3.3</fo:block>
+              </fo:table-cell>
+            </fo:table-body>
+          </fo:table>
+        </fo:flow>
+      </fo:page-sequence>
+    </fo:root>
+  </fo>
+  <checks>
+    <eval expected="119500" xpath="//flow/block/block[1]/@ipd"/>
+    <eval expected="119500" xpath="//flow/block/block[2]/@ipd"/>
+    <eval expected="119500" xpath="//flow/block/block[3]/@ipd"/>
+  </checks>
+</testcase>

Propchange: 
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to