From: Andreas L. Delmelle Date: Thu, 7 Feb 2008 22:32:27 +0000 (+0000) Subject: Tweak: early percentage resolution by the parser (if the base is known and absolute... X-Git-Tag: fop-0_95beta~99 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e3d7d048142f35bf93b0ba9f1294124de49be34e;p=xmlgraphics-fop.git Tweak: early percentage resolution by the parser (if the base is known and absolute). Reduces the number of PercentLength instances in favor of cached FixedLengths. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@619670 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/datatypes/LengthBase.java b/src/java/org/apache/fop/datatypes/LengthBase.java index 684685509..8a321f2c6 100644 --- a/src/java/org/apache/fop/datatypes/LengthBase.java +++ b/src/java/org/apache/fop/datatypes/LengthBase.java @@ -130,5 +130,17 @@ public class LengthBase implements PercentBase { return baseLen; } + /** {@inheritDoc} */ + public String toString() { + return super.toString() + + "[fo=" + fobj + "," + + "baseType=" + baseType + "," + + "baseLength=" + baseLength + "]"; + } + + /**@return the base length as a {@link Length} */ + public Length getBaseLength() { + return baseLength; + } } diff --git a/src/java/org/apache/fop/fo/expr/PropertyParser.java b/src/java/org/apache/fop/fo/expr/PropertyParser.java index d8f45790e..cd3393ef3 100644 --- a/src/java/org/apache/fop/fo/expr/PropertyParser.java +++ b/src/java/org/apache/fop/fo/expr/PropertyParser.java @@ -19,6 +19,8 @@ package org.apache.fop.fo.expr; +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.LengthBase; import org.apache.fop.datatypes.Numeric; import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.properties.ColorProperty; @@ -43,7 +45,7 @@ public final class PropertyParser extends PropertyTokenizer { private static final String RELUNIT = "em"; private static final HashMap FUNCTION_TABLE = new HashMap(); - + static { // Initialize the HashMap of XSL-defined functions FUNCTION_TABLE.put("ceiling", new CeilingFunction()); @@ -272,6 +274,16 @@ public final class PropertyParser extends PropertyTokenizer { if (pcBase.getDimension() == 0) { prop = NumberProperty.getInstance(pcval * pcBase.getBaseValue()); } else if (pcBase.getDimension() == 1) { + if (pcBase instanceof LengthBase) { + //If the base of the percentage is known + //and absolute, it can be resolved by the + //parser + Length base = ((LengthBase)pcBase).getBaseLength(); + if (base != null && base.isAbsolute()) { + prop = FixedLength.getInstance(pcval * base.getValue()); + break; + } + } prop = new PercentLength(pcval, pcBase); } else { throw new PropertyException("Illegal percent dimension value"); diff --git a/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java b/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java index dcb8fd176..dd57502d8 100644 --- a/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java @@ -19,6 +19,8 @@ package org.apache.fop.fo.properties; +import org.apache.fop.datatypes.Length; +import org.apache.fop.datatypes.LengthBase; import org.apache.fop.datatypes.Numeric; import org.apache.fop.fo.Constants; import org.apache.fop.fo.FObj; @@ -85,7 +87,16 @@ public class LineHeightPropertyMaker extends SpaceProperty.Maker { FObj fo) throws PropertyException { Numeric numval = p.getNumeric(); if (numval != null && numval.getDimension() == 0) { - p = new PercentLength(numval.getNumericValue(), getPercentBase(propertyList)); + if (getPercentBase(propertyList) instanceof LengthBase) { + Length base = ((LengthBase)getPercentBase(propertyList)).getBaseLength(); + if (base != null && base.isAbsolute()) { + p = FixedLength.getInstance( + numval.getNumericValue() * base.getNumericValue()); + } else { + p = new PercentLength( + numval.getNumericValue(), getPercentBase(propertyList)); + } + } Property spaceProp = super.convertProperty(p, propertyList, fo); spaceProp.setSpecifiedValue(String.valueOf(numval.getNumericValue())); return spaceProp; diff --git a/test/fotree/testcases/font-shorthand-test.fo b/test/fotree/testcases/font-shorthand-test.fo index b6666087f..e574b3b24 100644 --- a/test/fotree/testcases/font-shorthand-test.fo +++ b/test/fotree/testcases/font-shorthand-test.fo @@ -29,7 +29,7 @@ - + @@ -37,7 +37,7 @@ - + Test font shorthand @@ -46,7 +46,7 @@ - + Test font shorthand @@ -55,7 +55,7 @@ - + Test font shorthand @@ -65,7 +65,7 @@ - + Test font shorthand inheritance