From: Peter Bernard West Date: Wed, 2 Oct 2002 07:19:59 +0000 (+0000) Subject: Fixed bug in numeric unit handling. X-Git-Tag: Alt-Design_pre_Properties_split~64 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=196f07b7be61f5610d3c01c07a8213ba741e42bd;p=xmlgraphics-fop.git Fixed bug in numeric unit handling. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@195268 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/fo/expr/PropertyTokenizer.java b/src/org/apache/fop/fo/expr/PropertyTokenizer.java index a7005743f..0a1410fee 100644 --- a/src/org/apache/fop/fo/expr/PropertyTokenizer.java +++ b/src/org/apache/fop/fo/expr/PropertyTokenizer.java @@ -72,8 +72,9 @@ class PropertyTokenizer { */ int currentToken = EOF; String currentTokenValue = null; - protected int currentUnitLength = 0; + protected int currentUnitIndex = 0; protected int currentUnit; + protected String unitString; protected String uri; private int currentTokenStartIndex = 0; @@ -96,6 +97,7 @@ class PropertyTokenizer { expr = s; exprLength = s.length(); this.property = property; + //System.out.println("-----Tokenizer initialized: " + expr); } /** @@ -109,6 +111,15 @@ class PropertyTokenizer { currentToken = EOF; currentTokenValue = null; property = 0; + //System.out.println("-----Tokenizer reset."); + } + + /** + * Get the current expression + * @return - the expression. + */ + public String getExpr() { + return expr; } /** @@ -194,12 +205,11 @@ class PropertyTokenizer { } } else bSawDecimal = false; + currentUnitIndex = exprIndex; if (exprIndex < exprLength && expr.charAt(exprIndex) == '%') { currentToken = PERCENT; - currentTokenValue = expr.substring(currentTokenStartIndex, - exprIndex); + unitString = "%"; exprIndex++; - return; } else { // Check for possible unit name following number currentToken = scanUnitName(); @@ -207,7 +217,7 @@ class PropertyTokenizer { currentToken = bSawDecimal ? FLOAT : INTEGER; } currentTokenValue = expr.substring(currentTokenStartIndex, - exprIndex); + currentUnitIndex); return; case '.': @@ -343,49 +353,48 @@ class PropertyTokenizer { * @exception PropertyException if an NCName not a UnitName recognized. */ private int scanUnitName() throws PropertyException { - String unit; - currentUnitLength = exprIndex; + currentUnitIndex = exprIndex; scanName(); - if ((currentUnitLength = exprIndex - currentUnitLength) > 0) { - unit = expr.substring(currentUnitLength, exprIndex); - if (unit.equals("em")) return RELATIVE_LENGTH; - if (unit.equals("cm")) { + if (currentUnitIndex < exprIndex) { + unitString = expr.substring(currentUnitIndex, exprIndex); + if (unitString.equals("em")) return RELATIVE_LENGTH; + if (unitString.equals("cm")) { currentUnit = Length.CM; return ABSOLUTE_LENGTH; } - if (unit.equals("mm")) { + if (unitString.equals("mm")) { currentUnit = Length.MM; return ABSOLUTE_LENGTH; } - if (unit.equals("in")) { + if (unitString.equals("in")) { currentUnit = Length.IN; return ABSOLUTE_LENGTH; } - if (unit.equals("pt")) { + if (unitString.equals("pt")) { currentUnit = Length.PT; return ABSOLUTE_LENGTH; } - if (unit.equals("pc")) { + if (unitString.equals("pc")) { currentUnit = Length.PC; return ABSOLUTE_LENGTH; } - if (unit.equals("px")) { + if (unitString.equals("px")) { currentUnit = Length.PX; return ABSOLUTE_LENGTH; } - if (unit.equals("s")) { + if (unitString.equals("s")) { currentUnit = Time.SEC; return TIME; } - if (unit.equals("ms")) { + if (unitString.equals("ms")) { currentUnit = Time.MSEC; return TIME; } - if (unit.equals("Hz")) { + if (unitString.equals("Hz")) { currentUnit = Frequency.HZ; return FREQ; } - if (unit.equals("kHz")) { + if (unitString.equals("kHz")) { currentUnit = Frequency.KHZ; return FREQ; }