diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-09-16 08:50:14 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-09-16 08:50:14 +0000 |
commit | 29697aee2699b47a3951a266463306b88ce2c38b (patch) | |
tree | 5f6bb78b565ec84c8a342e95196809f1dbdbee61 /src/java/org | |
parent | 2fb4799fb303c4d6aeeb413cdccfd08341fb3cae (diff) | |
download | xmlgraphics-fop-29697aee2699b47a3951a266463306b88ce2c38b.tar.gz xmlgraphics-fop-29697aee2699b47a3951a266463306b88ce2c38b.zip |
Provide the TABLE_UNITS base value through the PrecentageBaseContext.
Remove the LayoutDimension mechanism entirely.
This fixes a problem with proportional-column-width() in nested tables. The LayoutDimension mechanism would look in the parent table for the base value when the base value for the actual table was only just calculated.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@289439 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
5 files changed, 29 insertions, 88 deletions
diff --git a/src/java/org/apache/fop/datatypes/LengthBase.java b/src/java/org/apache/fop/datatypes/LengthBase.java index 633643ecb..7c14d213f 100644 --- a/src/java/org/apache/fop/datatypes/LengthBase.java +++ b/src/java/org/apache/fop/datatypes/LengthBase.java @@ -51,13 +51,16 @@ public class LengthBase implements PercentBase { public static final int IMAGE_BACKGROUND_POSITION_HORIZONTAL = 9; /** constant for a image background position vertical percent-based length */ public static final int IMAGE_BACKGROUND_POSITION_VERTICAL = 10; + /** constant for a table-unit-based length */ + public static final int TABLE_UNITS = 11; /** array of valid percent-based length types */ public static final int[] PERCENT_BASED_LENGTH_TYPES = {CUSTOM_BASE, FONTSIZE, INH_FONTSIZE, PARENT_AREA_WIDTH, CONTAINING_REFAREA_WIDTH, IMAGE_INTRINSIC_WIDTH, IMAGE_INTRINSIC_HEIGHT, - IMAGE_BACKGROUND_POSITION_HORIZONTAL, IMAGE_BACKGROUND_POSITION_VERTICAL + IMAGE_BACKGROUND_POSITION_HORIZONTAL, IMAGE_BACKGROUND_POSITION_VERTICAL, + TABLE_UNITS }; /** @@ -77,7 +80,7 @@ public class LengthBase implements PercentBase { * @param parentFO parent FO for this * @param plist property list for this * @param iBaseType a member of {@link #PERCENT_BASED_LENGTH_TYPES} - * @throws PropertyException + * @throws PropertyException In case an problem occurs while evaluating values */ public LengthBase(FObj parentFO, PropertyList plist, int iBaseType) throws PropertyException { this.fobj = plist.getFObj(); diff --git a/src/java/org/apache/fop/datatypes/PercentBase.java b/src/java/org/apache/fop/datatypes/PercentBase.java index a166725b1..40814f0de 100644 --- a/src/java/org/apache/fop/datatypes/PercentBase.java +++ b/src/java/org/apache/fop/datatypes/PercentBase.java @@ -26,11 +26,6 @@ import org.apache.fop.fo.expr.PropertyException; */ public interface PercentBase { - //Types of values to store in layoutDimension on FObj - - /** table units */ - LayoutDimension TABLE_UNITS = new LayoutDimension("table-units"); - /** * Determines whether a numeric property is created or one with a percentage * base. @@ -38,6 +33,10 @@ public interface PercentBase { */ int getDimension(); + /** + * @return the base value (this will be used as the base to which a percentage will be + * applied to compute the length of the referencing item) + */ double getBaseValue(); /** @@ -50,22 +49,4 @@ public interface PercentBase { */ int getBaseLength(PercentBaseContext context) throws PropertyException; - /** Enum class for dimension types. */ - public class LayoutDimension { - - private String name; - - /** - * Constructor to add a new named item. - * @param name Name of the item. - */ - protected LayoutDimension(String name) { - this.name = name; - } - - /** @see java.lang.Object#toString() */ - public String toString() { - return super.toString() + "[" + name + "]"; - } - } } diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index c96c4ecc7..8147787b3 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -26,7 +26,6 @@ import java.util.Map; import java.util.Set; import org.apache.fop.apps.FOPException; -import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.extensions.ExtensionAttachment; import org.apache.fop.fo.flow.Marker; import org.apache.fop.fo.properties.PropertyMaker; @@ -56,9 +55,6 @@ public abstract class FObj extends FONode implements Constants { /** Markers added to this element. */ protected Map markers = null; - /** Dynamic layout dimension. Used to resolve relative lengths. */ - protected Map layoutDimension = null; - /** * Create a new formatting object. * All formatting object classes extend this class. @@ -213,53 +209,6 @@ public abstract class FObj extends FONode implements Constants { return (FObj) par; } - /* This section is the implemenation of the property context. */ - - /** - * Assign the size of a layout dimension to the key. - * @param key the Layout dimension, from PercentBase. - * @param dimension The layout length. - * TODO Remove when possible! - */ - public void setLayoutDimension(PercentBase.LayoutDimension key, int dimension) { - if (layoutDimension == null) { - layoutDimension = new java.util.HashMap(); - } - layoutDimension.put(key, new Integer(dimension)); - } - - /** - * Assign the size of a layout dimension to the key. - * @param key the Layout dimension, from PercentBase. - * @param dimension The layout length. - * TODO Remove when possible! - */ - public void setLayoutDimension(PercentBase.LayoutDimension key, float dimension) { - if (layoutDimension == null) { - layoutDimension = new java.util.HashMap(); - } - layoutDimension.put(key, new Float(dimension)); - } - - /** - * Return the size associated with the key. - * @param key The layout dimension key. - * @return the length. - * TODO Remove when possible! - */ - public Number getLayoutDimension(PercentBase.LayoutDimension key) { - if (layoutDimension != null) { - Number result = (Number) layoutDimension.get(key); - if (result != null) { - return result; - } - } - if (parent != null) { - return ((FObj) parent).getLayoutDimension(key); - } - return new Integer(0); - } - /** * Check if this formatting object generates reference areas. * @return true if generates reference areas diff --git a/src/java/org/apache/fop/fo/properties/TableColLength.java b/src/java/org/apache/fop/fo/properties/TableColLength.java index 554501c73..0b7b710f5 100644 --- a/src/java/org/apache/fop/fo/properties/TableColLength.java +++ b/src/java/org/apache/fop/fo/properties/TableColLength.java @@ -18,8 +18,8 @@ package org.apache.fop.fo.properties; +import org.apache.fop.datatypes.LengthBase; import org.apache.fop.datatypes.PercentBaseContext; -import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.FObj; /** @@ -40,13 +40,14 @@ public class TableColLength extends LengthProperty { private double tcolUnits; /** - * The column the this column-units are defined on. + * The column the column-units are defined on. */ private FObj column; /** * Construct an object with tcolUnits of proportional measure. * @param tcolUnits number of table-column proportional units + * @param column the column the column-units are defined on */ public TableColLength(double tcolUnits, FObj column) { this.tcolUnits = tcolUnits; @@ -74,14 +75,15 @@ public class TableColLength extends LengthProperty { * @see org.apache.fop.datatypes.Numeric#getNumericValue() */ public double getNumericValue() { - return tcolUnits * column.getLayoutDimension(PercentBase.TABLE_UNITS).floatValue(); + throw new UnsupportedOperationException( + "Must call getNumericValue with PercentageBaseContext"); } /** * @see org.apache.fop.datatypes.Numeric#getNumericValue(PercentBaseContext) */ public double getNumericValue(PercentBaseContext context) { - return getNumericValue(); + return tcolUnits * context.getBaseLength(LengthBase.TABLE_UNITS, column); } /** @@ -89,14 +91,15 @@ public class TableColLength extends LengthProperty { * @see org.apache.fop.datatypes.Length#getValue() */ public int getValue() { - return (int) (tcolUnits * column.getLayoutDimension(PercentBase.TABLE_UNITS).floatValue()); + throw new UnsupportedOperationException( + "Must call getValue with PercentageBaseContext"); } /** * @see org.apache.fop.datatypes.Numeric#getValue(PercentBaseContext) */ public int getValue(PercentBaseContext context) { - return getValue(); + return (int) (tcolUnits * context.getBaseLength(LengthBase.TABLE_UNITS, column)); } /** diff --git a/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java index f0084e737..1a5bf7fa5 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java @@ -19,7 +19,6 @@ package org.apache.fop.layoutmgr.table; import org.apache.fop.datatypes.Length; -import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.flow.Table; import org.apache.fop.fo.flow.TableColumn; import org.apache.fop.fo.properties.TableColLength; @@ -61,6 +60,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager private int contentIPD; private int referenceBPD; + private double tableUnits; private boolean autoLayout = true; //TODO space-before|after: handle space-resolution rules @@ -89,6 +89,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager return this.columns; } + /** @see org.apache.fop.layoutmgr.LayoutManager#initialize() */ public void initialize() { spaceBefore = new SpaceVal(fobj.getCommonMarginBlock().spaceBefore, this).getSpace(); spaceAfter = new SpaceVal(fobj.getCommonMarginBlock().spaceAfter, this).getSpace(); @@ -153,7 +154,7 @@ public class TableLayoutManager extends BlockStackingLayoutManager // is used works out total factor, so that value of single unit can be computed. int sumCols = 0; float factors = 0; - for (Iterator i = columns.iterator(); i.hasNext(); ) { + for (Iterator i = columns.iterator(); i.hasNext();) { TableColumn column = (TableColumn) i.next(); Length width = column.getColumnWidth(); sumCols += width.getValue(this); @@ -164,9 +165,8 @@ public class TableLayoutManager extends BlockStackingLayoutManager // sets TABLE_UNITS in case where one or more oldColumns is defined using // proportional-column-width if (sumCols < contentIPD) { - if (fobj.getLayoutDimension(PercentBase.TABLE_UNITS).floatValue() == 0.0) { - fobj.setLayoutDimension(PercentBase.TABLE_UNITS, - (contentIPD - sumCols) / factors); + if (tableUnits == 0.0) { + this.tableUnits = (contentIPD - sumCols) / factors; } } @@ -434,7 +434,12 @@ public class TableLayoutManager extends BlockStackingLayoutManager return 0; } } else { - return super.getBaseLength(lengthBase, fobj); + switch (lengthBase) { + case LengthBase.TABLE_UNITS: + return (int)this.tableUnits; + default: + return super.getBaseLength(lengthBase, fobj); + } } } |