]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
More String-->int conversions. Work primarily from Finn Bock's patch.
authorGlen Mazza <gmazza@apache.org>
Mon, 5 Jan 2004 00:44:59 +0000 (00:44 +0000)
committerGlen Mazza <gmazza@apache.org>
Mon, 5 Jan 2004 00:44:59 +0000 (00:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197114 13f79535-47bb-0310-9956-ffa450edef68

src/codegen/properties.xsl
src/java/org/apache/fop/fo/Property.java
src/java/org/apache/fop/fo/PropertyList.java
src/java/org/apache/fop/fo/expr/LabelEndFunction.java
src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java
src/java/org/apache/fop/render/rtf/TableAttributesConverter.java

index 73c9cdedc1189ac840eb8a890b675e4432cfdff4..d4646237d2e7699919b20c71100257226334da82 100644 (file)
@@ -563,9 +563,10 @@ public class </xsl:text>
         return super.getSubpropMaker(subprop);
     }
 
-    protected Property setSubprop(Property baseProp, String subpropName,
+    protected Property setSubprop(Property baseProp, int subpropId,
                                   Property subProp) {
         </xsl:text>
+        String subpropName = FOPropertyMapping.getPropertyName(subpropId);
         <xsl:value-of select="datatype"/>
         <xsl:text> val = baseProp.get</xsl:text>
         <xsl:value-of select="datatype"/>
@@ -769,14 +770,12 @@ public class </xsl:text>
         <xsl:if test=".//corresponding/@use-if-specified='true'">
           <xsl:text>
     public boolean isCorrespondingForced(PropertyList propertyList) {
-        FObj parentFO = propertyList.getParentFObj();
-        StringBuffer sbExpr=new StringBuffer();</xsl:text>
+        FObj parentFO = propertyList.getParentFObj();</xsl:text>
           <xsl:for-each select=".//corresponding/propval">
             <xsl:text>
-        sbExpr.setLength(0);</xsl:text>
+        if (propertyList.getExplicit(</xsl:text>
             <xsl:apply-templates select="."/>
-            <xsl:text>
-        if (propertyList.getExplicit(sbExpr.toString()) != null)
+            <xsl:text>) != null)
             return true;</xsl:text>
           </xsl:for-each>
           <xsl:text>
@@ -788,24 +787,26 @@ public class </xsl:text>
 
     public Property compute(PropertyList propertyList) throws FOPException {
         FObj parentFO = propertyList.getParentFObj();
-        StringBuffer sbExpr=new StringBuffer();
         Property p=null;</xsl:text>
       <xsl:choose>
         <xsl:when test="corresponding/propexpr">
-          <xsl:apply-templates select="corresponding/propval"/>
           <xsl:text>
         // Make sure the property is set before calculating it!
-        if (propertyList.getExplicitOrShorthand(sbExpr.toString()) == null)
+        if (propertyList.getExplicitOrShorthand(</xsl:text>
+          <xsl:apply-templates select="corresponding/propval"/>
+          <xsl:text>) == null)
             return p;
+        StringBuffer sbExpr=new StringBuffer();
         sbExpr.setLength(0);</xsl:text>
           <xsl:apply-templates select="corresponding/propexpr"/>
           <xsl:text>
         p = make(propertyList, sbExpr.toString(), propertyList.getParentFObj());</xsl:text>
         </xsl:when>
         <xsl:otherwise>
-          <xsl:apply-templates select="corresponding/propval"/>
           <xsl:text>
-        p= propertyList.getExplicitOrShorthand(sbExpr.toString());</xsl:text>
+        p= propertyList.getExplicitOrShorthand(</xsl:text>
+          <xsl:apply-templates select="corresponding/propval"/>
+          <xsl:text>);</xsl:text>
         </xsl:otherwise>
       </xsl:choose>
       <xsl:text>
@@ -818,8 +819,6 @@ public class </xsl:text>
 
         Property subprop;</xsl:text>
         <xsl:for-each select="compound/subproperty/corresponding">
-          <xsl:text>
-        sbExpr.setLength(0);</xsl:text>
           <xsl:choose>
             <xsl:when test="propexpr">
               <xsl:apply-templates select="propexpr"/>
@@ -830,16 +829,19 @@ public class </xsl:text>
                   make(propertyList, sbExpr.toString(), parentFO);</xsl:text>
           </xsl:when>
           <xsl:otherwise>
-            <xsl:apply-templates select="propval"/>
             <xsl:text>
-        subprop = propertyList.getExplicitOrShorthand(sbExpr.toString());</xsl:text>
+        subprop = propertyList.getExplicitOrShorthand(</xsl:text>
+          <xsl:apply-templates select="propval"/>
+          <xsl:text>);</xsl:text>
           </xsl:otherwise>
         </xsl:choose>
         <xsl:text>
         if (subprop != null) {
-            setSubprop(p, "</xsl:text>
-        <xsl:value-of select='../name'/>
-        <xsl:text>", subprop);
+            setSubprop(p, Constants.CP_</xsl:text>
+        <xsl:call-template name="makeEnumConstant">
+          <xsl:with-param name="propstr" select="../name"/>
+        </xsl:call-template>
+        <xsl:text>, subprop);
         }</xsl:text>
       </xsl:for-each>
     </xsl:if>
@@ -860,9 +862,11 @@ public class </xsl:text>
     <xsl:text>
         if (p == null) {
             listprop =
-                (ListProperty)propertyList.getExplicit("</xsl:text>
-    <xsl:value-of select='$shprop'/>
-    <xsl:text>");
+                (ListProperty)propertyList.getExplicit(Constants.PR_</xsl:text>
+    <xsl:call-template name="makeEnumConstant">
+      <xsl:with-param name="propstr" select="$shprop"/>
+    </xsl:call-template>
+    <xsl:text>);
             if (listprop != null) {
                // Get a parser for the shorthand to set the individual properties
                ShorthandParser shparser =
@@ -899,6 +903,83 @@ public class </xsl:text>
 </xsl:template>
 
 
+<xsl:template match="propval">
+  <xsl:choose>
+    <xsl:when test="wmabs2rel[@dir='LEFT']">
+      <xsl:call-template name="makeMap">
+        <xsl:with-param name="lrtb" select='"START"'/>
+        <xsl:with-param name="rltb" select='"END"'/>
+        <xsl:with-param name="tbrl" select='"AFTER"'/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:when test="wmabs2rel[@dir='RIGHT']">
+      <xsl:call-template name="makeMap">
+        <xsl:with-param name="lrtb" select='"END"'/>
+        <xsl:with-param name="rltb" select='"START"'/>
+        <xsl:with-param name="tbrl" select='"BEFORE"'/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:when test="wmabs2rel[@dir='TOP']">
+      <xsl:call-template name="makeMap">
+        <xsl:with-param name="lrtb" select='"BEFORE"'/>
+        <xsl:with-param name="rltb" select='"BEFORE"'/>
+        <xsl:with-param name="tbrl" select='"START"'/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:when test="wmabs2rel[@dir='BOTTOM']">
+      <xsl:call-template name="makeMap">
+        <xsl:with-param name="lrtb" select='"AFTER"'/>
+        <xsl:with-param name="rltb" select='"AFTER"'/>
+        <xsl:with-param name="tbrl" select='"END"'/>
+      </xsl:call-template>
+    </xsl:when>
+
+    <xsl:when test="wmrel2abs[@dir='START']">
+      <xsl:call-template name="makeMap">
+        <xsl:with-param name="lrtb" select='"LEFT"'/>
+        <xsl:with-param name="rltb" select='"RIGHT"'/>
+        <xsl:with-param name="tbrl" select='"TOP"'/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:when test="wmrel2abs[@dir='END']">
+      <xsl:call-template name="makeMap">
+        <xsl:with-param name="lrtb" select='"RIGHT"'/>
+        <xsl:with-param name="rltb" select='"LEFT"'/>
+        <xsl:with-param name="tbrl" select='"BOTTOM"'/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:when test="wmrel2abs[@dir='BEFORE'] or parwmrel2abs[@dir='BEFORE']">
+      <xsl:call-template name="makeMap">
+        <xsl:with-param name="lrtb" select='"TOP"'/>
+        <xsl:with-param name="rltb" select='"TOP"'/>
+        <xsl:with-param name="tbrl" select='"RIGHT"'/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:when test="wmrel2abs[@dir='AFTER'] or parwmrel2abs[@dir='AFTER']">
+      <xsl:call-template name="makeMap">
+        <xsl:with-param name="lrtb" select='"BOTTOM"'/>
+        <xsl:with-param name="rltb" select='"BOTTOM"'/>
+        <xsl:with-param name="tbrl" select='"LEFT"'/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:when test="wmrel2abs[@dir='BLOCKPROGDIM']">
+      <xsl:call-template name="makeMap">
+        <xsl:with-param name="lrtb" select='"HEIGHT"'/>
+        <xsl:with-param name="rltb" select='"HEIGHT"'/>
+        <xsl:with-param name="tbrl" select='"WIDTH"'/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:when test="wmrel2abs[@dir='INLINEPROGDIM']">
+      <xsl:call-template name="makeMap">
+        <xsl:with-param name="lrtb" select='"WIDTH"'/>
+        <xsl:with-param name="rltb" select='"WIDTH"'/>
+        <xsl:with-param name="tbrl" select='"HEIGHT"'/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>UNKNOWN <xsl:value-of select="."/></xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 <xsl:template match="corresponding//text()">
   <xsl:variable name="tval" select='normalize-space(.)'/>
   <xsl:if test="$tval != ''">
@@ -909,6 +990,34 @@ public class </xsl:text>
   </xsl:if>
 </xsl:template>
 
+<xsl:template name="makeMap">
+  <xsl:param name="lrtb"/>
+  <xsl:param name="rltb"/>
+  <xsl:param name="tbrl"/>
+  <xsl:text>propertyList.wmMap(Constants.PR_</xsl:text>
+  <xsl:apply-templates mode="x">
+    <xsl:with-param name="dir" select='$lrtb'/>
+  </xsl:apply-templates>
+  <xsl:text>, Constants.PR_</xsl:text>
+  <xsl:apply-templates mode="x">
+    <xsl:with-param name="dir" select='$rltb'/>
+  </xsl:apply-templates>
+  <xsl:text>, Constants.PR_</xsl:text>
+  <xsl:apply-templates mode="x">
+    <xsl:with-param name="dir" select='$tbrl'/>
+  </xsl:apply-templates>
+  <xsl:text>)</xsl:text>
+</xsl:template>
+
+<xsl:template match="corresponding//text()" mode="x">
+  <xsl:variable name="tval" select='normalize-space(.)'/>
+  <xsl:if test="$tval != ''">
+    <xsl:call-template name="makeEnumConstant">
+      <xsl:with-param name="propstr" select="$tval"/>
+    </xsl:call-template>
+  </xsl:if>
+</xsl:template>
+
 <xsl:template match="propval/wmrel2abs">
   <xsl:text>
         sbExpr.append(propertyList.wmRelToAbs(PropertyList.</xsl:text>
@@ -930,6 +1039,21 @@ public class </xsl:text>
   <xsl:text>));</xsl:text>
 </xsl:template>
 
+<xsl:template match="propval/wmrel2abs" mode="x">
+  <xsl:param name="dir"/>
+  <xsl:value-of select="$dir"/>
+</xsl:template>
+
+<xsl:template match="propval/parwmrel2abs" mode="x">
+  <xsl:param name="dir"/>
+  <xsl:value-of select="$dir"/>
+</xsl:template>
+
+<xsl:template match="propval/wmabs2rel" mode="x">
+  <xsl:param name="dir"/>
+  <xsl:value-of select="$dir"/>
+</xsl:template>
+
 <!-- avoid unwanted output to placeholder file -->
 <xsl:template match="localname"/>
 
index a21480f9a0780250586f06bc703febaa850a0a06..ed01900c3d8286625d54be7b31a60f0e1819f5be 100644 (file)
@@ -417,9 +417,8 @@ public class Property {
             if (inheritsSpecified()) {
                 // recalculate based on last specified value
                 // Climb up propertylist and find last spec'd value
-                String propName = FOPropertyMapping.getPropertyName(this.propId);
                 Property specProp =
-                    propertyList.getNearestSpecified(propName);
+                    propertyList.getNearestSpecified(propId);
                 if (specProp != null) {
                     // Only need to do this if the value is relative!!!
                     String specVal = specProp.getSpecifiedValue();
index bce0876968301b287ae58def6e1a2acdb454fb60..08b44bf4f9f27213fd21ab0a566408f8c6668d22 100644 (file)
@@ -68,6 +68,7 @@ public class PropertyList extends HashMap {
 
     // writing-mode values
     private byte[] wmtable = null;
+    private int writingMode;
 
     // absolute directions and dimensions
     /** constant for direction "left" */
@@ -181,9 +182,9 @@ public class PropertyList extends HashMap {
      * @return The value if the property is explicitly set or set by
      * a shorthand property, otherwise null.
      */
-    public Property getExplicitOrShorthand(String propertyName) {
+    public Property getExplicitOrShorthand(int propId) {
         /* Handle request for one part of a compound property */
-        int propId = FOPropertyMapping.getPropertyId(propertyName);
+        String propertyName = FOPropertyMapping.getPropertyName(propId);
 
         int sepchar = propertyName.indexOf('.');
         String baseName;
@@ -194,7 +195,7 @@ public class PropertyList extends HashMap {
         }
         Property p = getExplicitBaseProp(baseName);
         if (p == null) {
-            p = getShorthand(namespace, elementName, baseName);
+            p = getShorthand(propId & Constants.PROPERTY_MASK);
         }
         if (p != null && sepchar > -1) {
             return getSubpropValue(p, propId);
@@ -208,8 +209,8 @@ public class PropertyList extends HashMap {
      * It may be a compound name, such as space-before.optimum.
      * @return The value if the property is explicitly set, otherwise null.
      */
-    public Property getExplicit(String propertyName) {
-        int propId = FOPropertyMapping.getPropertyId(propertyName);
+    public Property getExplicit(int propId) {
+        String propertyName = FOPropertyMapping.getPropertyName(propId);
 
         /* Handle request for one part of a compound property */
         int sepchar = propertyName.indexOf('.');
@@ -326,7 +327,7 @@ public class PropertyList extends HashMap {
                 p = this.computeProperty(propId);
             }
             if (p == null) {    // check for shorthand specification
-                p = getShorthand(namespace, elementName, propertyName);
+                p = getShorthand(propId);
             }
             if (p == null && bTryInherit) {    
                 // else inherit (if has parent and is inheritable)
@@ -346,13 +347,13 @@ public class PropertyList extends HashMap {
      * @return The computed value if the property is explicitly set on some
      * ancestor of the current FO, else the initial value.
      */
-    public Property getNearestSpecified(String propertyName) {
-        int propId = FOPropertyMapping.getPropertyId(propertyName);
+    public Property getNearestSpecified(int propId) {
+        String propertyName = FOPropertyMapping.getPropertyName(propId);
 
         Property p = null;
         for (PropertyList plist = this; p == null && plist != null;
                 plist = plist.parentPropertyList) {
-            p = plist.getExplicit(propertyName);
+            p = plist.getExplicit(propId);
         }
         if (p == null) {
             // If no explicit setting found, return initial (default) value.
@@ -374,8 +375,7 @@ public class PropertyList extends HashMap {
      * FO is the root or is in a different namespace from its parent.
      */
     public Property getFromParent(int propId) {
-        String propertyName = FOPropertyMapping.getPropertyName(propId);
-        
+
         if (parentPropertyList != null) {
             return parentPropertyList.get(propId);
         } else {
@@ -389,6 +389,21 @@ public class PropertyList extends HashMap {
         return null;    // Exception in makeProperty!
     }
 
+    /**
+     * Uses the stored writingMode.
+     * @param absdir an absolute direction (top, bottom, left, right)
+     * @return the corresponding writing model relative direction name
+     * for the flow object.
+     */
+    public int wmMap(int lrtb, int rltb, int tbrl) {
+        switch (writingMode) {
+        case WritingMode.LR_TB: return lrtb;
+        case WritingMode.RL_TB: return lrtb;
+        case WritingMode.TB_RL: return lrtb;
+        }
+        return -1;
+    }
+
     /**
      * Uses the stored writingMode.
      * @param absdir an absolute direction (top, bottom, left, right)
@@ -424,6 +439,7 @@ public class PropertyList extends HashMap {
      * @param writingMode the writing-mode property to be set for this object
      */
     public void setWritingMode(int writingMode) {
+        this.writingMode = writingMode;
         this.wmtable = (byte[])WRITING_MODE_TABLES.get(new Integer(writingMode));
     }
 
@@ -554,7 +570,7 @@ public class PropertyList extends HashMap {
      * @param attributeName String to be atomized
      * @return the base portion of the attribute
      */
-    public static String findBasePropertyName(String attributeName) {
+    private static String findBasePropertyName(String attributeName) {
         int sepCharIndex = attributeName.indexOf('.');
         String basePropName = attributeName;
         if (sepCharIndex > -1) {
@@ -570,7 +586,7 @@ public class PropertyList extends HashMap {
      * @param attributeName String to be atomized
      * @return the sub portion of the attribute
      */
-    public static String findSubPropertyName(String attributeName) {
+    private static String findSubPropertyName(String attributeName) {
         int sepCharIndex = attributeName.indexOf('.');
         String subPropName = null;
         if (sepCharIndex > -1) {
@@ -615,13 +631,10 @@ public class PropertyList extends HashMap {
     }
 
     /**
-     * @param propertyName name of property
+     * @param propId ID of property
      * @return new Property object
      */
-    private Property getShorthand(String space, String element,
-        String propertyName) {
-        int propId = FOPropertyMapping.getPropertyId(propertyName);
-
+    private Property getShorthand(int propId) {
         Property.Maker propertyMaker = findMaker(propId);
         
         if (propertyMaker != null) {
index 29e40d51ef52725040fbc0c09bdfb95b6daf2e89..8306857d22a69b659fed28457b1792f08759545d 100644 (file)
@@ -87,7 +87,7 @@ public class LabelEndFunction extends FunctionBase {
         Length distance =
             pInfo.getPropertyList().get(Constants.PR_PROVISIONAL_DISTANCE_BETWEEN_STARTS).getLength();
         Length separation =
-            pInfo.getPropertyList().getNearestSpecified("provisional-label-separation").getLength();
+            pInfo.getPropertyList().getNearestSpecified(Constants.PR_PROVISIONAL_LABEL_SEPARATION).getLength();
 
         FONode item = pInfo.getFO();
         while (item != null && !(item instanceof ListItem)) {
index 7dc64a31ca545e4df02a44a4b1282458e057fd95..4f389e6f17e9132aad2d097b646619de72fd8c8b 100644 (file)
@@ -51,6 +51,7 @@
 package org.apache.fop.fo.expr;
 
 import org.apache.fop.fo.Property;
+import org.apache.fop.fo.properties.FOPropertyMapping;
 
 /**
  * Class modelling the from-nearest-specified-value function. See Sec. 5.10.4
@@ -82,7 +83,8 @@ public class NearestSpecPropFunction extends FunctionBase {
         }
         // NOTE: special cases for shorthand property
         // Should return COMPUTED VALUE
-        return pInfo.getPropertyList().getNearestSpecified(propName);
+        int propId = FOPropertyMapping.getPropertyId(propName);
+        return pInfo.getPropertyList().getNearestSpecified(propId);
     }
 
 }
index 9aa1ae40360b3d6b426dfe8ae4eba0372ecd7c15..f790e1d9a65e9916fb9f339d3eb224c3e71363a8 100644 (file)
@@ -156,7 +156,7 @@ public class TableAttributesConverter {
         boolean isBorderPresent = false;
 
         // Cell background color
-        if ((p = props.getNearestSpecified("background-color")) != null) {
+        if ((p = props.getNearestSpecified(Constants.PR_BACKGROUND_COLOR)) != null) {
             ColorType color = p.getColorType();
             if (color != null) {
                 if (color.getAlpha() != 0
@@ -174,8 +174,8 @@ public class TableAttributesConverter {
         }
 
         // Cell borders :
-        if ((p = props.getExplicit("border-color")) != null) {
-            ListProperty listprop = (ListProperty)p;
+        if ((p = props.getExplicit(Constants.PR_BORDER_COLOR)) != null) {
+            ListProperty listprop = (ListProperty) p;
             ColorType color = null;
             if (listprop.getList().get(0) instanceof NCnameProperty) {
                 color = new ColorType(((NCnameProperty)listprop.getList().get(0)).getNCname());
@@ -188,28 +188,28 @@ public class TableAttributesConverter {
                 colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(),
                         (int)color.getBlue()).intValue());
         }
-        if ((p = props.getExplicit("border-top-color")) != null) {
+        if ((p = props.getExplicit(Constants.PR_BORDER_TOP_COLOR)) != null) {
             ColorType color = p.getColorType();
             attrib.set(
                 BorderAttributesConverter.BORDER_COLOR,
                 colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(),
                         (int)color.getBlue()).intValue());
         }
-        if ((p = props.getExplicit("border-bottom-color")) != null) {
+        if ((p = props.getExplicit(Constants.PR_BORDER_BOTTOM_COLOR)) != null) {
             ColorType color = p.getColorType();
             attrib.set(
                 BorderAttributesConverter.BORDER_COLOR,
                 colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(),
                         (int)color.getBlue()).intValue());
         }
-        if ((p = props.getExplicit("border-left-color")) != null) {
+        if ((p = props.getExplicit(Constants.PR_BORDER_LEFT_COLOR)) != null) {
             ColorType color = p.getColorType();
             attrib.set(
                 BorderAttributesConverter.BORDER_COLOR,
                 colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(),
                         (int)color.getBlue()).intValue());
         }
-        if ((p = props.getExplicit("border-right-color")) != null) {
+        if ((p = props.getExplicit(Constants.PR_BORDER_RIGHT_COLOR)) != null) {
             ColorType color = p.getColorType();
             attrib.set(
                 BorderAttributesConverter.BORDER_COLOR,