From 9715ae547a6da42aaf42ccbdd9a4cf2917c6e7ba Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Mon, 5 Jan 2004 00:44:59 +0000 Subject: [PATCH] More String-->int conversions. Work primarily from Finn Bock's patch. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197114 13f79535-47bb-0310-9956-ffa450edef68 --- src/codegen/properties.xsl | 166 +++++++++++++++--- src/java/org/apache/fop/fo/Property.java | 3 +- src/java/org/apache/fop/fo/PropertyList.java | 49 ++++-- .../apache/fop/fo/expr/LabelEndFunction.java | 2 +- .../fop/fo/expr/NearestSpecPropFunction.java | 4 +- .../render/rtf/TableAttributesConverter.java | 14 +- 6 files changed, 188 insertions(+), 50 deletions(-) diff --git a/src/codegen/properties.xsl b/src/codegen/properties.xsl index 73c9cdedc..d4646237d 100644 --- a/src/codegen/properties.xsl +++ b/src/codegen/properties.xsl @@ -563,9 +563,10 @@ public class return super.getSubpropMaker(subprop); } - protected Property setSubprop(Property baseProp, String subpropName, + protected Property setSubprop(Property baseProp, int subpropId, Property subProp) { + String subpropName = FOPropertyMapping.getPropertyName(subpropId); val = baseProp.get @@ -769,14 +770,12 @@ public class public boolean isCorrespondingForced(PropertyList propertyList) { - FObj parentFO = propertyList.getParentFObj(); - StringBuffer sbExpr=new StringBuffer(); + FObj parentFO = propertyList.getParentFObj(); - sbExpr.setLength(0); + if (propertyList.getExplicit( - - if (propertyList.getExplicit(sbExpr.toString()) != null) + ) != null) return true; @@ -788,24 +787,26 @@ public class public Property compute(PropertyList propertyList) throws FOPException { FObj parentFO = propertyList.getParentFObj(); - StringBuffer sbExpr=new StringBuffer(); Property p=null; - // Make sure the property is set before calculating it! - if (propertyList.getExplicitOrShorthand(sbExpr.toString()) == null) + if (propertyList.getExplicitOrShorthand( + + ) == null) return p; + StringBuffer sbExpr=new StringBuffer(); sbExpr.setLength(0); p = make(propertyList, sbExpr.toString(), propertyList.getParentFObj()); - - p= propertyList.getExplicitOrShorthand(sbExpr.toString()); + p= propertyList.getExplicitOrShorthand( + + ); @@ -818,8 +819,6 @@ public class Property subprop; - - sbExpr.setLength(0); @@ -830,16 +829,19 @@ public class make(propertyList, sbExpr.toString(), parentFO); - - subprop = propertyList.getExplicitOrShorthand(sbExpr.toString()); + subprop = propertyList.getExplicitOrShorthand( + + ); if (subprop != null) { - setSubprop(p, " - - ", subprop); + setSubprop(p, Constants.CP_ + + + + , subprop); } @@ -860,9 +862,11 @@ public class if (p == null) { listprop = - (ListProperty)propertyList.getExplicit(" - - "); + (ListProperty)propertyList.getExplicit(Constants.PR_ + + + + ); if (listprop != null) { // Get a parser for the shorthand to set the individual properties ShorthandParser shparser = @@ -899,6 +903,83 @@ public class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + UNKNOWN + + + @@ -909,6 +990,34 @@ public class + + + + + propertyList.wmMap(Constants.PR_ + + + + , Constants.PR_ + + + + , Constants.PR_ + + + + ) + + + + + + + + + + + sbExpr.append(propertyList.wmRelToAbs(PropertyList. @@ -930,6 +1039,21 @@ public class )); + + + + + + + + + + + + + + + diff --git a/src/java/org/apache/fop/fo/Property.java b/src/java/org/apache/fop/fo/Property.java index a21480f9a..ed01900c3 100644 --- a/src/java/org/apache/fop/fo/Property.java +++ b/src/java/org/apache/fop/fo/Property.java @@ -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(); diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java index bce087696..08b44bf4f 100644 --- a/src/java/org/apache/fop/fo/PropertyList.java +++ b/src/java/org/apache/fop/fo/PropertyList.java @@ -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) { diff --git a/src/java/org/apache/fop/fo/expr/LabelEndFunction.java b/src/java/org/apache/fop/fo/expr/LabelEndFunction.java index 29e40d51e..8306857d2 100644 --- a/src/java/org/apache/fop/fo/expr/LabelEndFunction.java +++ b/src/java/org/apache/fop/fo/expr/LabelEndFunction.java @@ -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)) { diff --git a/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java b/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java index 7dc64a31c..4f389e6f1 100644 --- a/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java +++ b/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java @@ -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); } } diff --git a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java index 9aa1ae403..f790e1d9a 100644 --- a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java @@ -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, -- 2.39.5