Author: adelmelle
Date: Thu Feb 7 14:32:27 2008
New Revision: 619670
URL: http://svn.apache.org/viewvc?rev=619670&view=rev
Log:
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.
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/datatypes/LengthBase.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java
xmlgraphics/fop/trunk/test/fotree/testcases/font-shorthand-test.fo
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/datatypes/LengthBase.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/datatypes/LengthBase.java?rev=619670&r1=619669&r2=619670&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/datatypes/LengthBase.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/datatypes/LengthBase.java Thu
Feb 7 14:32:27 2008
@@ -130,5 +130,17 @@
return baseLen;
}
+ /** [EMAIL PROTECTED] */
+ public String toString() {
+ return super.toString()
+ + "[fo=" + fobj + ","
+ + "baseType=" + baseType + ","
+ + "baseLength=" + baseLength + "]";
+ }
+
+ /[EMAIL PROTECTED] the base length as a [EMAIL PROTECTED] Length} */
+ public Length getBaseLength() {
+ return baseLength;
+ }
}
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java?rev=619670&r1=619669&r2=619670&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/expr/PropertyParser.java
Thu Feb 7 14:32:27 2008
@@ -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 @@
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 @@
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");
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java?rev=619670&r1=619669&r2=619670&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java
Thu Feb 7 14:32:27 2008
@@ -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 @@
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;
Modified: xmlgraphics/fop/trunk/test/fotree/testcases/font-shorthand-test.fo
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/fotree/testcases/font-shorthand-test.fo?rev=619670&r1=619669&r2=619670&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/fotree/testcases/font-shorthand-test.fo
(original)
+++ xmlgraphics/fop/trunk/test/fotree/testcases/font-shorthand-test.fo Thu Feb
7 14:32:27 2008
@@ -29,7 +29,7 @@
<test:assert property="font-size" expected="10000mpt"/>
<test:assert property="font-weight" expected="700" />
<test:assert property="font-style" expected="NORMAL" />
- <test:assert property="line-height.optimum" expected="120.0%" />
+ <test:assert property="line-height.optimum" expected="12000mpt" />
<test:assert property="font-variant" expected="NORMAL" />
</fo:block>
<fo:block font="italic small-caps 14pt 'Times New Roman', serif">
@@ -37,7 +37,7 @@
<test:assert property="font-size" expected="14000mpt"/>
<test:assert property="font-weight" expected="400" />
<test:assert property="font-style" expected="ITALIC" />
- <test:assert property="line-height.optimum" expected="120.0%" />
+ <test:assert property="line-height.optimum" expected="16800mpt" />
<test:assert property="font-variant" expected="SMALL_CAPS" />
Test font shorthand
</fo:block>
@@ -46,7 +46,7 @@
<test:assert property="font-size" expected="14000mpt"/>
<test:assert property="font-weight" expected="700" />
<test:assert property="font-style" expected="ITALIC" />
- <test:assert property="line-height.optimum" expected="80.0%" />
+ <test:assert property="line-height.optimum" expected="11200mpt" />
<test:assert property="font-variant" expected="NORMAL" />
Test font shorthand
</fo:block>
@@ -55,7 +55,7 @@
<test:assert property="font-size" expected="20736mpt"/>
<test:assert property="font-weight" expected="400" />
<test:assert property="font-style" expected="NORMAL" />
- <test:assert property="line-height.optimum" expected="140.0%" />
+ <test:assert property="line-height.optimum" expected="29030mpt" />
<test:assert property="font-variant" expected="NORMAL" />
Test font shorthand
</fo:block>
@@ -65,7 +65,7 @@
<test:assert property="font-size" expected="14000mpt"/>
<test:assert property="font-weight" expected="700" />
<test:assert property="font-style" expected="ITALIC" />
- <test:assert property="line-height.optimum" expected="80.0%" />
+ <test:assert property="line-height.optimum" expected="11200mpt" />
<test:assert property="font-variant" expected="NORMAL" />
Test font shorthand inheritance
</fo:block>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]