From 69de007e0f16649d3f69f5c700f1164b12e933d5 Mon Sep 17 00:00:00 2001 From: Karen Lease Date: Fri, 10 Nov 2000 22:29:23 +0000 Subject: [PATCH] Modify for use with property expression parsing git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193773 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/datatypes/Length.java | 142 +++++++++++++---------- 1 file changed, 83 insertions(+), 59 deletions(-) diff --git a/src/org/apache/fop/datatypes/Length.java b/src/org/apache/fop/datatypes/Length.java index 763c61100..cb247709e 100644 --- a/src/org/apache/fop/datatypes/Length.java +++ b/src/org/apache/fop/datatypes/Length.java @@ -57,90 +57,114 @@ import org.apache.fop.messaging.MessageHandler; * a length quantity in XSL */ public class Length { + public static final Length AUTO ; - protected int millipoints = 0; + static { + AUTO = new Length(0); + AUTO.bAuto = true; + } - protected double fontsize = 12; - - boolean auto = false; + protected int millipoints = 0; + protected boolean bIsComputed = false; + private boolean bAuto = false; - /** - * set the length given a particular String specifying length and units - */ - public Length (String len) { - convert(len); + /** + * 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 particular String specifying length and units, - * and the font-size (necessary for an em) - */ - public Length (String len, int fontsize) { - this.fontsize = fontsize; - convert(len); + /** + * Set the length given a number of units and a unit name. + */ + public Length (double numUnits, String units) { + convert(numUnits, units); } /** - * set the length given a particular multiplier and a length property + * set the length as a number of base units */ - public Length (double multiplier, Property property) { - this.millipoints = (int)(multiplier * property.getLength().mvalue()); + public Length (int baseUnits) { + millipoints = baseUnits; + setIsComputed(true); } - protected void convert(String len) { - /* convert the given length to a dimensionless integer representing - points. */ - - int assumed_resolution = 1; // points/pixel + /** + * 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 l = len.length(); + int assumed_resolution = 1; // points/pixel - if (l == 0) { - MessageHandler.errorln("WARNING: empty length"); - this.millipoints = 0; - } else if (len.equals("auto")) { - this.auto = true; - } else { - String unit = len.substring(l-2); - double dvalue = - Double.valueOf(len.substring(0,(l-2))).doubleValue(); - - if (unit.equals("in")) - dvalue = dvalue * 72; - else if (unit.equals("cm")) - dvalue = dvalue * 28.35; - else if (unit.equals("mm")) - dvalue = dvalue * 2.84; - 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("ERROR: unknown length units in " - + len); - } - - this.millipoints = (int) (dvalue * 1000); - } + if (unit.equals("in")) + dvalue = dvalue * 72; + else if (unit.equals("cm")) + dvalue = dvalue * 28.35; + else if (unit.equals("mm")) + dvalue = dvalue * 2.84; + 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("ERROR: 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() { - return millipoints; + if (!bIsComputed) + millipoints = computeValue(); + return millipoints; } + protected int computeValue() { + return millipoints; + } + + protected void setValue(int millipoints) { + this.millipoints = millipoints; + setIsComputed(true); + } + public boolean isAuto() { - return auto; + return bAuto; } + /** + * 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; + } + public String toString() { String s = millipoints + "mpt"; return s; -- 2.39.5