diff options
author | Simon Pepping <spepping@apache.org> | 2008-04-24 17:46:31 +0000 |
---|---|---|
committer | Simon Pepping <spepping@apache.org> | 2008-04-24 17:46:31 +0000 |
commit | 5cded0d5c204d6c5a49b1915d7595b2c67a20881 (patch) | |
tree | c2ca816abddebe7eacdc6b6d3032dd1c63b7c6e1 | |
parent | ec0cb2d2d4e0aecbc066837dd62d5da8249a27e6 (diff) | |
download | xmlgraphics-fop-5cded0d5c204d6c5a49b1915d7595b2c67a20881.tar.gz xmlgraphics-fop-5cded0d5c204d6c5a49b1915d7595b2c67a20881.zip |
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
4 files changed, 116 insertions, 19 deletions
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 { @@ -196,6 +198,53 @@ public class RelativeNumericProperty extends Property implements Numeric, Length } /** + * 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; + } + + /** * 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). - * <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; 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 @@ +<?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> |