]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Tweak: early percentage resolution by the parser (if the base is known and absolute...
authorAndreas L. Delmelle <adelmelle@apache.org>
Thu, 7 Feb 2008 22:32:27 +0000 (22:32 +0000)
committerAndreas L. Delmelle <adelmelle@apache.org>
Thu, 7 Feb 2008 22:32:27 +0000 (22:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@619670 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/datatypes/LengthBase.java
src/java/org/apache/fop/fo/expr/PropertyParser.java
src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java
test/fotree/testcases/font-shorthand-test.fo

index 6846855090ae3ed055a5eb3044b29806b00a26aa..8a321f2c6380ddb8151b995b175f3deaeea81e87 100644 (file)
@@ -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;
+    }
 }
 
index d8f45790e0d3c14b0c962eaedf180880efd87ea2..cd3393ef3268020d75f823d4314997670215fbc0 100644 (file)
@@ -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");
index dcb8fd176d2c687029f9c21f13a1eb331e3b1872..dd57502d8434b45f55e6352809c1d2a66fe2d5ed 100644 (file)
@@ -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;
index b6666087f8a01391f5ceabe0b808957905472d2a..e574b3b24b050fed3f224120ed7e37c5526448f3 100644 (file)
@@ -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>