klease 01/10/14 13:33:36 Modified: src/org/apache/fop/datatypes Length.java TableColLength.java PercentLength.java LinearCombinationLength.java MixedLength.java Added: src/org/apache/fop/datatypes AutoLength.java FixedLength.java Log: Modify the Length class hierarchy Revision Changes Path 1.14 +25 -75 xml-fop/src/org/apache/fop/datatypes/Length.java Index: Length.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/Length.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- Length.java 2001/09/11 10:04:24 1.13 +++ Length.java 2001/10/14 20:33:36 1.14 @@ -1,5 +1,5 @@ /* - * $Id: Length.java,v 1.13 2001/09/11 10:04:24 keiron Exp $ + * $Id: Length.java,v 1.14 2001/10/14 20:33:36 klease Exp $ * 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. @@ -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 @@ * 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 setComputedValue(int millipoints) { + setComputedValue(millipoints, true); } - protected void setValue(int millipoints) { + 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; } /** @@ -121,6 +64,13 @@ */ public double getTableUnits() { return 0.0; + } + + public void resolveTableUnit(double dTableUnit) { + } + + public Numeric asNumeric() { + return null; } public String toString() { 1.4 +23 -11 xml-fop/src/org/apache/fop/datatypes/TableColLength.java Index: TableColLength.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/TableColLength.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TableColLength.java 2001/08/20 11:19:22 1.3 +++ TableColLength.java 2001/10/14 20:33:36 1.4 @@ -1,5 +1,5 @@ /* - * $Id: TableColLength.java,v 1.3 2001/08/20 11:19:22 keiron Exp $ + * $Id: TableColLength.java,v 1.4 2001/10/14 20:33:36 klease Exp $ * 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. @@ -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 @@ * 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 @@ * 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 @@ 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); + } } 1.4 +9 -5 xml-fop/src/org/apache/fop/datatypes/PercentLength.java Index: PercentLength.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/PercentLength.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PercentLength.java 2001/08/20 11:19:22 1.3 +++ PercentLength.java 2001/10/14 20:33:36 1.4 @@ -1,5 +1,5 @@ /* - * $Id: PercentLength.java,v 1.3 2001/08/20 11:19:22 keiron Exp $ + * $Id: PercentLength.java,v 1.4 2001/10/14 20:33:36 klease Exp $ * 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. @@ -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 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 @@ * 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() { @@ -55,6 +55,10 @@ // return the factor as a percent // What about the base value? return (new Double(factor * 100.0).toString()) + "%"; + } + + public Numeric asNumeric() { + return new Numeric(this); } } 1.3 +3 -5 xml-fop/src/org/apache/fop/datatypes/LinearCombinationLength.java Index: LinearCombinationLength.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/LinearCombinationLength.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- LinearCombinationLength.java 2001/07/30 20:29:19 1.2 +++ LinearCombinationLength.java 2001/10/14 20:33:36 1.3 @@ -1,5 +1,5 @@ /* - * $Id: LinearCombinationLength.java,v 1.2 2001/07/30 20:29:19 tore Exp $ + * $Id: LinearCombinationLength.java,v 1.3 2001/10/14 20:33:36 klease Exp $ * 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. @@ -15,10 +15,8 @@ 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 @@ /** * 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 @@ (int)(((Double)factors.elementAt(i)).doubleValue() * (double)((Length)lengths.elementAt(i)).mvalue()); } - return result; + setComputedValue(result); } } 1.4 +66 -23 xml-fop/src/org/apache/fop/datatypes/MixedLength.java Index: MixedLength.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/MixedLength.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MixedLength.java 2001/08/20 11:19:22 1.3 +++ MixedLength.java 2001/10/14 20:33:36 1.4 @@ -1,5 +1,5 @@ /* - * $Id: MixedLength.java,v 1.3 2001/08/20 11:19:22 keiron Exp $ + * $Id: MixedLength.java,v 1.4 2001/10/14 20:33:36 klease Exp $ * 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. @@ -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 @@ */ public class MixedLength extends Length { - private PercentLength pcPart; + private Vector lengths ; - /** - * 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); + 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()); + + public double getTableUnits() { + double tableUnits = 0.0; + Enumeration e = lengths.elements(); + while (e.hasMoreElements()) { + tableUnits += ((Length)e.nextElement()).getTableUnits(); + } + return tableUnits; + } - if (pcPart != null) { - rslt.append("+" + pcPart.toString()); + 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; } } 1.1 xml-fop/src/org/apache/fop/datatypes/AutoLength.java Index: AutoLength.java =================================================================== /* * $Id: AutoLength.java,v 1.1 2001/10/14 20:33:36 klease Exp $ * 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"; } } 1.1 xml-fop/src/org/apache/fop/datatypes/FixedLength.java Index: FixedLength.java =================================================================== /* * $Id: FixedLength.java,v 1.1 2001/10/14 20:33:36 klease Exp $ * 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); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]