From 5cded0d5c204d6c5a49b1915d7595b2c67a20881 Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Thu, 24 Apr 2008 17:46:31 +0000 Subject: Improve table-unit computation if proportional-column-width() is used as a subexpression. Fixes bug 44658. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@651323 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/fo/expr/RelativeNumericProperty.java | 53 ++++++++++++++++++- .../apache/fop/fo/properties/LengthProperty.java | 16 ------ .../apache/fop/layoutmgr/table/ColumnSetup.java | 5 +- .../table-cell_table-units_mixed.xml | 61 ++++++++++++++++++++++ 4 files changed, 116 insertions(+), 19 deletions(-) create mode 100644 test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml diff --git a/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java b/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java index ae140b6b7..dc7ab902f 100755 --- a/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java +++ b/src/java/org/apache/fop/fo/expr/RelativeNumericProperty.java @@ -23,6 +23,7 @@ import org.apache.fop.datatypes.Length; 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 @@ import org.apache.fop.fo.properties.Property; * 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 @@ public class RelativeNumericProperty extends Property implements Numeric, Length /** * The second operand. */ - private Numeric op2; + private Numeric op2 = null; /** * The dimension of the result. */ @@ -99,6 +100,7 @@ public class RelativeNumericProperty extends Property implements Numeric, Length /** * Return a resolved (calculated) Numeric with the value of the expression. * @param context Evaluation context + * @return the resolved {@link Numeric} corresponding to the value of the expression * @throws PropertyException when an exception occur during evaluation. */ private Numeric getResolved(PercentBaseContext context) throws PropertyException { @@ -195,6 +197,53 @@ public class RelativeNumericProperty extends Property implements Numeric, Length 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). + *

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; + } + /** * Return a string represention of the expression. Only used for debugging. * @return the string representation. diff --git a/src/java/org/apache/fop/fo/properties/LengthProperty.java b/src/java/org/apache/fop/fo/properties/LengthProperty.java index 495e8d8ea..697aa75a7 100644 --- a/src/java/org/apache/fop/fo/properties/LengthProperty.java +++ b/src/java/org/apache/fop/fo/properties/LengthProperty.java @@ -71,22 +71,6 @@ public abstract class LengthProperty extends Property } - /** - * 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). - *

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; diff --git a/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java b/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java index bd032e610..9dbd31653 100644 --- a/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java +++ b/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; 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 @@ public class ColumnSetup { 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(); } } diff --git a/test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml b/test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml new file mode 100644 index 000000000..868b14388 --- /dev/null +++ b/test/layoutengine/standard-testcases/table-cell_table-units_mixed.xml @@ -0,0 +1,61 @@ + + + + + +

+ This test checks the calculation of table units when the column + widths are a mixture of fixed and proportional widths. +

+ + + + + + + + + + + + + + + + + Cell 1.1 + + + Cell 2.2 + + + Cell 3.3 + + + + + + + + + + + + + -- cgit v1.2.3