diff options
author | Karen Lease <klease@apache.org> | 2001-10-14 20:33:36 +0000 |
---|---|---|
committer | Karen Lease <klease@apache.org> | 2001-10-14 20:33:36 +0000 |
commit | 172e7a28be4ce53f935acfbbedc001ea8e0b177a (patch) | |
tree | 159dad83372246783b57befbafe50263dfbb5afa /src/org/apache/fop | |
parent | 654f55e1c67e127dbfac22b7e7a67add5b2ff318 (diff) | |
download | xmlgraphics-fop-172e7a28be4ce53f935acfbbedc001ea8e0b177a.tar.gz xmlgraphics-fop-172e7a28be4ce53f935acfbbedc001ea8e0b177a.zip |
Modify the Length class hierarchy
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194504 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop')
-rw-r--r-- | src/org/apache/fop/datatypes/AutoLength.java | 31 | ||||
-rw-r--r-- | src/org/apache/fop/datatypes/FixedLength.java | 76 | ||||
-rw-r--r-- | src/org/apache/fop/datatypes/Length.java | 98 | ||||
-rw-r--r-- | src/org/apache/fop/datatypes/LinearCombinationLength.java | 6 | ||||
-rw-r--r-- | src/org/apache/fop/datatypes/MixedLength.java | 89 | ||||
-rw-r--r-- | src/org/apache/fop/datatypes/PercentLength.java | 12 | ||||
-rw-r--r-- | src/org/apache/fop/datatypes/TableColLength.java | 32 |
7 files changed, 229 insertions, 115 deletions
diff --git a/src/org/apache/fop/datatypes/AutoLength.java b/src/org/apache/fop/datatypes/AutoLength.java new file mode 100644 index 000000000..77bf78271 --- /dev/null +++ b/src/org/apache/fop/datatypes/AutoLength.java @@ -0,0 +1,31 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.Property; +import org.apache.fop.messaging.MessageHandler; + +/** + * a length quantity in XSL which is specified as "auto" + */ +public class AutoLength extends Length { + + public boolean isAuto() { + return true; + } + + // Should we do something intelligent here to set the actual size? + // Would need a reference object! + // protected void computeValue() { + // } + + public String toString() { + return "auto"; + } + +} diff --git a/src/org/apache/fop/datatypes/FixedLength.java b/src/org/apache/fop/datatypes/FixedLength.java new file mode 100644 index 000000000..f425040bb --- /dev/null +++ b/src/org/apache/fop/datatypes/FixedLength.java @@ -0,0 +1,76 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + +package org.apache.fop.datatypes; + +import org.apache.fop.fo.Property; +import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.messaging.MessageHandler; + +/** + * a length quantity in XSL + */ +public class FixedLength extends Length { + + /** + * Set the length given a number of relative units and the current + * font size in base units. + */ + public FixedLength(double numRelUnits, int iCurFontSize) { + setComputedValue((int)(numRelUnits * (double)iCurFontSize)); + } + + /** + * Set the length given a number of units and a unit name. + */ + public FixedLength(double numUnits, String units) { + convert(numUnits, units); + } + + /** + * set the length as a number of base units + */ + public FixedLength(int baseUnits) { + setComputedValue(baseUnits); + } + + /** + * Convert the given length to a dimensionless integer representing + * a whole number of base units (milli-points). + */ + protected void convert(double dvalue, String unit) { + + int assumed_resolution = 1; // points/pixel + + if (unit.equals("in")) + dvalue = dvalue * 72; + else if (unit.equals("cm")) + dvalue = dvalue * 28.3464567; + else if (unit.equals("mm")) + dvalue = dvalue * 2.83464567; + else if (unit.equals("pt")) + dvalue = dvalue; + else if (unit.equals("pc")) + dvalue = dvalue * 12; + /* + * else if (unit.equals("em")) + * dvalue = dvalue * fontsize; + */ + else if (unit.equals("px")) + dvalue = dvalue * assumed_resolution; + else { + dvalue = 0; + MessageHandler.errorln("unknown length unit '" + unit + + "'"); + } + setComputedValue((int)(dvalue * 1000)); + } + + public Numeric asNumeric() { + return new Numeric(this); + } +} diff --git a/src/org/apache/fop/datatypes/Length.java b/src/org/apache/fop/datatypes/Length.java index 334ec9153..050de80e7 100644 --- a/src/org/apache/fop/datatypes/Length.java +++ b/src/org/apache/fop/datatypes/Length.java @@ -7,6 +7,7 @@ package org.apache.fop.datatypes; +import org.apache.fop.fo.expr.Numeric; import org.apache.fop.fo.Property; import org.apache.fop.messaging.MessageHandler; @@ -14,97 +15,39 @@ import org.apache.fop.messaging.MessageHandler; * a length quantity in XSL */ public class Length { - public static final Length AUTO = new Length(0); - - static { - AUTO.bAuto = true; - } protected int millipoints = 0; protected boolean bIsComputed = false; - private boolean bAuto = false; - - /** - * Set the length given a number of relative units and the current - * font size in base units. - */ - public Length(double numRelUnits, int iCurFontSize) { - millipoints = (int)(numRelUnits * (double)iCurFontSize); - setIsComputed(true); - } - - /** - * Set the length given a number of units and a unit name. - */ - public Length(double numUnits, String units) { - convert(numUnits, units); - } - - /** - * set the length as a number of base units - */ - public Length(int baseUnits) { - millipoints = baseUnits; - setIsComputed(true); - } - - /** - * Convert the given length to a dimensionless integer representing - * a whole number of base units (milli-points). - */ - protected void convert(double dvalue, String unit) { - - int assumed_resolution = 1; // points/pixel - - if (unit.equals("in")) - dvalue = dvalue * 72; - else if (unit.equals("cm")) - dvalue = dvalue * 28.3464567; - else if (unit.equals("mm")) - dvalue = dvalue * 2.83464567; - else if (unit.equals("pt")) - dvalue = dvalue; - else if (unit.equals("pc")) - dvalue = dvalue * 12; - /* - * else if (unit.equals("em")) - * dvalue = dvalue * fontsize; - */ - else if (unit.equals("px")) - dvalue = dvalue * assumed_resolution; - else { - dvalue = 0; - MessageHandler.errorln("unknown length unit '" + unit - + "'"); - } - this.millipoints = (int)(dvalue * 1000); - setIsComputed(true); - } - - protected void setIsComputed(boolean bIsComputed) { - this.bIsComputed = bIsComputed; - } /** * return the length in 1/1000ths of a point */ public int mvalue() { - if (!bIsComputed) - millipoints = computeValue(); + if (!bIsComputed) { + computeValue(); + } return millipoints; } - protected int computeValue() { - return millipoints; + protected void computeValue() { } - protected void setValue(int millipoints) { + + protected void setComputedValue(int millipoints) { + setComputedValue(millipoints, true); + } + + protected void setComputedValue(int millipoints, boolean bSetComputed) { this.millipoints = millipoints; - setIsComputed(true); + this.bIsComputed = bSetComputed; } public boolean isAuto() { - return bAuto; + return false; + } + + public boolean isComputed() { + return this.bIsComputed; } /** @@ -123,6 +66,13 @@ public class Length { return 0.0; } + public void resolveTableUnit(double dTableUnit) { + } + + public Numeric asNumeric() { + return null; + } + public String toString() { String s = millipoints + "mpt"; return s; diff --git a/src/org/apache/fop/datatypes/LinearCombinationLength.java b/src/org/apache/fop/datatypes/LinearCombinationLength.java index 776d6f7d9..ad1ce1bd9 100644 --- a/src/org/apache/fop/datatypes/LinearCombinationLength.java +++ b/src/org/apache/fop/datatypes/LinearCombinationLength.java @@ -15,10 +15,8 @@ public class LinearCombinationLength extends Length { protected Vector lengths; public LinearCombinationLength() { - super(0); factors = new Vector(); lengths = new Vector(); - super.setIsComputed(false); } public void addTerm(double factor, Length length) { @@ -29,7 +27,7 @@ public class LinearCombinationLength extends Length { /** * Return the computed value in millipoints. */ - protected int computeValue() { + protected void computeValue() { int result = 0; int numFactors = factors.size(); for (int i = 0; i < numFactors; ++i) { @@ -37,7 +35,7 @@ public class LinearCombinationLength extends Length { (int)(((Double)factors.elementAt(i)).doubleValue() * (double)((Length)lengths.elementAt(i)).mvalue()); } - return result; + setComputedValue(result); } } diff --git a/src/org/apache/fop/datatypes/MixedLength.java b/src/org/apache/fop/datatypes/MixedLength.java index 246ebd2b0..0667d1597 100644 --- a/src/org/apache/fop/datatypes/MixedLength.java +++ b/src/org/apache/fop/datatypes/MixedLength.java @@ -7,6 +7,12 @@ package org.apache.fop.datatypes; +import java.util.Vector; +import java.util.Enumeration; + +import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.fo.expr.PropertyException; + /** * A length quantity in XSL which is specified with a mixture * of absolute and relative and/or percent components. @@ -14,36 +20,73 @@ package org.apache.fop.datatypes; */ public class MixedLength extends Length { - private PercentLength pcPart; - - /** - * construct an object based on a factor (the percent, as a - * a factor) and an object which has a method to return the - * Length which provides the "base" for this calculation. - */ - public MixedLength(int absPart, PercentLength pcPart) { - super(absPart); - this.pcPart = pcPart; - super.setIsComputed(false); + private Vector lengths ; + + public MixedLength(Vector lengths) { + this.lengths = lengths; } - protected int computeValue() { - int rslt = super.computeValue(); // absolute part - if (pcPart != null) { - rslt += pcPart.computeValue(); + protected void computeValue() { + int computedValue =0; + boolean bAllComputed = true; + Enumeration e = lengths.elements(); + while (e.hasMoreElements()) { + Length l = (Length)e.nextElement(); + computedValue += l.mvalue(); + if (! l.isComputed()) { + bAllComputed = false; + } } - return rslt; + setComputedValue(computedValue, bAllComputed); } - public String toString() { - // return the factor as a percent - // What about the base value? - StringBuffer rslt = new StringBuffer(super.toString()); - if (pcPart != null) { - rslt.append("+" + pcPart.toString()); + public double getTableUnits() { + double tableUnits = 0.0; + Enumeration e = lengths.elements(); + while (e.hasMoreElements()) { + tableUnits += ((Length)e.nextElement()).getTableUnits(); + } + return tableUnits; + } + + public void resolveTableUnit(double dTableUnit) { + Enumeration e = lengths.elements(); + while (e.hasMoreElements()) { + ((Length)e.nextElement()).resolveTableUnit(dTableUnit); } - return rslt.toString(); + } + + public String toString() { + StringBuffer sbuf = new StringBuffer(); + Enumeration e = lengths.elements(); + while (e.hasMoreElements()) { + if (sbuf.length()>0) { + sbuf.append('+'); + } + sbuf.append(e.nextElement().toString()); + } + return sbuf.toString(); + } + + public Numeric asNumeric() { + Numeric numeric = null; + for (Enumeration e = lengths.elements(); e.hasMoreElements();) { + Length l = (Length)e.nextElement(); + if (numeric == null) { + numeric = l.asNumeric(); + } + else { + try { + Numeric sum = numeric.add(l.asNumeric()); + numeric = sum; + } catch (PropertyException pe) { + System.err.println("Can't convert MixedLength to Numeric: " + + pe); + } + } + } + return numeric; } } diff --git a/src/org/apache/fop/datatypes/PercentLength.java b/src/org/apache/fop/datatypes/PercentLength.java index 35d1e2367..779115bb3 100644 --- a/src/org/apache/fop/datatypes/PercentLength.java +++ b/src/org/apache/fop/datatypes/PercentLength.java @@ -7,6 +7,8 @@ package org.apache.fop.datatypes; +import org.apache.fop.fo.expr.Numeric; + /** * a percent specified length quantity in XSL */ @@ -25,10 +27,8 @@ public class PercentLength extends Length { } public PercentLength(double factor, PercentBase lbase) { - super(0); this.factor = factor; this.lbase = lbase; - super.setIsComputed(false); } public void setBaseLength(PercentBase lbase) { @@ -43,8 +43,8 @@ public class PercentLength extends Length { * Return the computed value in millipoints. This assumes that the * base length has been resolved to an absolute length value. */ - protected int computeValue() { - return (int)(factor * (double)lbase.getBaseLength()); + protected void computeValue() { + setComputedValue((int)(factor * (double)lbase.getBaseLength())); } public double value() { @@ -57,4 +57,8 @@ public class PercentLength extends Length { return (new Double(factor * 100.0).toString()) + "%"; } + public Numeric asNumeric() { + return new Numeric(this); + } + } diff --git a/src/org/apache/fop/datatypes/TableColLength.java b/src/org/apache/fop/datatypes/TableColLength.java index 77b035b96..85832c139 100644 --- a/src/org/apache/fop/datatypes/TableColLength.java +++ b/src/org/apache/fop/datatypes/TableColLength.java @@ -7,6 +7,8 @@ package org.apache.fop.datatypes; +import org.apache.fop.fo.expr.Numeric; + /** * A table-column width specification, possibly including some * number of proportional "column-units". The absolute size of a @@ -18,7 +20,7 @@ package org.apache.fop.datatypes; * during layout. * NOTE: this is only supposed to be allowed if table-layout=fixed. */ -public class TableColLength extends MixedLength { +public class TableColLength extends Length { /** * Number of table-column proportional units @@ -29,15 +31,9 @@ public class TableColLength extends MixedLength { * Construct an object with tcolUnits of proportional measure. */ public TableColLength(double tcolUnits) { - super(0, null); this.tcolUnits = tcolUnits; } - public TableColLength(int absUnits, PercentLength pcUnits, - double tcolUnits) { - super(absUnits, pcUnits); - this.tcolUnits = tcolUnits; - } /** @@ -48,11 +44,27 @@ public class TableColLength extends MixedLength { return tcolUnits; } - // Set tcolUnits too when resolved? + /** + * Calculate the number of millipoints and set it. + */ + public void resolveTableUnit(double mpointsPerUnit) { + setComputedValue((int)(tcolUnits * mpointsPerUnit)); + } + +// If the table-unit can be resolved, set the computed value +// protected void computeValue() { +// if (tblUnitBase.canResolveUnit()) { +// rslt += (int)(tcolUnits * (double)tblUnitBase.getUnitValue()); +// setComputedValue(rslt); +// } +// } + public String toString() { - return (super.toString() + "+" + (new Double(tcolUnits).toString()) - + "table-column-units"); + return (Double.toString(tcolUnits) + " table-column-units"); } + public Numeric asNumeric() { + return new Numeric(this); + } } |