From 75c5a4c1cdb5eea469d82660a31d7fdb90a4333d Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sat, 27 Dec 2003 22:00:38 +0000 Subject: [PATCH] *Partial* conversion of PropertyList.get(String propName) to new PropertyList.get(int propId) method. This method will remain overloaded until all calls converted to int constants. Work based on Finn Bock's patch. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197059 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/FObj.java | 7 +- .../apache/fop/fo/GenericShorthandParser.java | 4 +- src/java/org/apache/fop/fo/PropertyList.java | 29 ++++- .../org/apache/fop/fo/PropertyManager.java | 104 +++++++++--------- .../fop/fo/expr/FromParentFunction.java | 4 +- src/java/org/apache/fop/fo/flow/Block.java | 32 +++--- .../apache/fop/fo/flow/BlockContainer.java | 10 +- src/java/org/apache/fop/fo/flow/Inline.java | 2 +- src/java/org/apache/fop/fo/flow/Marker.java | 3 +- 9 files changed, 107 insertions(+), 88 deletions(-) diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index 8066ff138..d2aab998d 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -66,7 +66,7 @@ import org.xml.sax.Locator; /** * Base class for representation of formatting objects and their processing. */ -public class FObj extends FONode { +public class FObj extends FONode implements Constants { private static final String FO_URI = "http://www.w3.org/1999/XSL/Format"; public static Property.Maker[] propertyListTable = null; @@ -257,7 +257,8 @@ public class FObj extends FONode { * @return the property */ public Property getProperty(String name) { - return (propertyList.get(name)); + int propId = FOPropertyMapping.getPropertyId(name); + return (propertyList.get(propId)); } /** @@ -267,7 +268,7 @@ public class FObj extends FONode { * fo and sets the id attribute of this object. */ public void setupID() { - Property prop = this.propertyList.get("id"); + Property prop = this.propertyList.get(PR_ID); if (prop != null) { String str = prop.getString(); if (str != null && !str.equals("")) { diff --git a/src/java/org/apache/fop/fo/GenericShorthandParser.java b/src/java/org/apache/fop/fo/GenericShorthandParser.java index c00fc984c..c15fc7b47 100644 --- a/src/java/org/apache/fop/fo/GenericShorthandParser.java +++ b/src/java/org/apache/fop/fo/GenericShorthandParser.java @@ -52,7 +52,6 @@ package org.apache.fop.fo; import java.util.Vector; import java.util.Enumeration; -import org.apache.fop.fo.properties.FOPropertyMapping; public class GenericShorthandParser implements ShorthandParser { @@ -96,8 +95,7 @@ public class GenericShorthandParser implements ShorthandParser { if (count() == 1) { String sval = ((Property)list.elementAt(0)).getString(); if (sval != null && sval.equals("inherit")) { - String name = FOPropertyMapping.getPropertyName(propId); - return propertyList.getFromParent(name); + return propertyList.getFromParent(propId); } } return convertValueForProperty(propId, maker, propertyList); diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java index 2344aeea0..22feefe02 100644 --- a/src/java/org/apache/fop/fo/PropertyList.java +++ b/src/java/org/apache/fop/fo/PropertyList.java @@ -229,7 +229,8 @@ public class PropertyList extends HashMap { public Property getInherited(String propertyName) { if (parentPropertyList != null && isInherited(namespace, elementName, propertyName)) { - return parentPropertyList.get(propertyName); + int propertyId = FOPropertyMapping.getPropertyId(propertyName); + return parentPropertyList.get(propertyId); } else { // return the "initial" value try { @@ -290,13 +291,27 @@ public class PropertyList extends HashMap { * this will try to compute it based on other properties, or if it is * inheritable, to return the inherited value. If all else fails, it returns * the default value. - * @param propertyName property name + * @param propId The Constants ID of the property whose value is desired. * @return the Property corresponding to that name */ - public Property get(String propertyName) { + public Property get(int propId) { + String propertyName = FOPropertyMapping.getPropertyName(propId); return get(propertyName, true, true); } + /** + * TEMPORARY until conversion to int's complete + * Return the property on the current FlowObject. If it isn't set explicitly, + * this will try to compute it based on other properties, or if it is + * inheritable, to return the inherited value. If all else fails, it returns + * the default value. + * @param propertyName The name of the property whose value is desired. + * @return the Property corresponding to that name + */ + public Property get(String propertyName) { + return get(propertyName, true, true); + } + /** * Return the property on the current FlowObject. Depending on the passed flags, * this will try to compute it based on other properties, or if it is @@ -381,13 +396,15 @@ public class PropertyList extends HashMap { /** * Return the value of this property on the parent of this FO. * Implements the from-parent function. - * @param propertyName The name of the property whose value is desired. + * @param propId The Constants ID of the property whose value is desired. * @return The computed value on the parent or the initial value if this * FO is the root or is in a different namespace from its parent. */ - public Property getFromParent(String propertyName) { + public Property getFromParent(int propId) { + String propertyName = FOPropertyMapping.getPropertyName(propId); + if (parentPropertyList != null) { - return parentPropertyList.get(propertyName); + return parentPropertyList.get(propId); } else { try { return makeProperty(namespace, elementName, propertyName); diff --git a/src/java/org/apache/fop/fo/PropertyManager.java b/src/java/org/apache/fop/fo/PropertyManager.java index 0d8775c06..69d5b171c 100644 --- a/src/java/org/apache/fop/fo/PropertyManager.java +++ b/src/java/org/apache/fop/fo/PropertyManager.java @@ -74,7 +74,7 @@ import org.apache.fop.fo.properties.CommonHyphenation; /** * Helper class for managing groups of properties. */ -public class PropertyManager { +public class PropertyManager implements Constants { private PropertyList propertyList; private FOTreeControl foTreeControl = null; @@ -138,9 +138,9 @@ public class PropertyManager { } /**@todo this is ugly. need to improve. */ - String fontFamily = propertyList.get("font-family").getString(); - String fontStyle = propertyList.get("font-style").getString(); - String fw = propertyList.get("font-weight").getString(); + String fontFamily = propertyList.get(PR_FONT_FAMILY).getString(); + String fontStyle = propertyList.get(PR_FONT_STYLE).getString(); + String fw = propertyList.get(PR_FONT_WEIGHT).getString(); int fontWeight = 400; if (fw.equals("bolder")) { // +100 from inherited @@ -161,7 +161,7 @@ public class PropertyManager { // NOTE: this is incomplete. font-size may be specified with // various kinds of keywords too - int fontSize = propertyList.get("font-size").getLength().getValue(); + int fontSize = propertyList.get(PR_FONT_SIZE).getLength().getValue(); //int fontVariant = propertyList.get("font-variant").getEnum(); String fname = foTreeControl.fontLookup(fontFamily, fontStyle, fontWeight); @@ -213,18 +213,18 @@ public class PropertyManager { if (hyphProps == null) { this.hyphProps = new CommonHyphenation(); hyphProps.hyphenate = - this.propertyList.get("hyphenate").getEnum(); + this.propertyList.get(PR_HYPHENATE).getEnum(); hyphProps.hyphenationChar = this.propertyList.get( - "hyphenation-character").getCharacter(); + PR_HYPHENATION_CHARACTER).getCharacter(); hyphProps.hyphenationPushCharacterCount = this.propertyList.get( - "hyphenation-push-character-count").getNumber(). + PR_HYPHENATION_PUSH_CHARACTER_COUNT).getNumber(). intValue(); hyphProps.hyphenationRemainCharacterCount = this.propertyList.get( - "hyphenation-remain-character-count").getNumber(). + PR_HYPHENATION_REMAIN_CHARACTER_COUNT).getNumber(). intValue(); hyphProps.language = - this.propertyList.get("language").getString(); - hyphProps.country = this.propertyList.get("country").getString(); + this.propertyList.get(PR_LANGUAGE).getString(); + hyphProps.country = this.propertyList.get(PR_COUNTRY).getString(); } return hyphProps; } @@ -306,22 +306,22 @@ public class PropertyManager { // Common Margin Properties-Block props.marginTop = - this.propertyList.get("margin-top").getLength().getValue(); + this.propertyList.get(PR_MARGIN_TOP).getLength().getValue(); props.marginBottom = - this.propertyList.get("margin-bottom").getLength().getValue(); + this.propertyList.get(PR_MARGIN_BOTTOM).getLength().getValue(); props.marginLeft = - this.propertyList.get("margin-left").getLength().getValue(); + this.propertyList.get(PR_MARGIN_LEFT).getLength().getValue(); props.marginRight = - this.propertyList.get("margin-right").getLength().getValue(); + this.propertyList.get(PR_MARGIN_RIGHT).getLength().getValue(); // For now, we only get the optimum value for space-before and after - props.spaceBefore = this.propertyList.get("space-before"). + props.spaceBefore = this.propertyList.get(PR_SPACE_BEFORE). getSpace().getOptimum().getLength().getValue(); - props.spaceAfter = this.propertyList.get("space-after"). + props.spaceAfter = this.propertyList.get(PR_SPACE_AFTER). getSpace().getOptimum().getLength().getValue(); - props.startIndent = this.propertyList.get("start-indent"). + props.startIndent = this.propertyList.get(PR_START_INDENT). getLength().getValue(); - props.endIndent = this.propertyList.get("end-indent"). + props.endIndent = this.propertyList.get(PR_END_INDENT). getLength().getValue(); return props; @@ -334,22 +334,22 @@ public class PropertyManager { */ public CommonBackground getBackgroundProps() { CommonBackground bp = new CommonBackground(); - bp.backAttachment = propertyList.get("background-attachment").getEnum(); - bp.backColor = propertyList.get("background-color").getColorType(); + bp.backAttachment = propertyList.get(PR_BACKGROUND_ATTACHMENT).getEnum(); + bp.backColor = propertyList.get(PR_BACKGROUND_COLOR).getColorType(); if (bp.backColor.getAlpha() == 0) { bp.backColor = null; } - bp.backImage = propertyList.get("background-image").getString(); + bp.backImage = propertyList.get(PR_BACKGROUND_IMAGE).getString(); if (bp.backImage == null || NONE.equals(bp.backImage)) { bp.backImage = null; } else { - bp.backRepeat = propertyList.get("background-repeat").getEnum(); - Property prop = propertyList.get("background-position-horizontal"); + bp.backRepeat = propertyList.get(PR_BACKGROUND_REPEAT).getEnum(); + Property prop = propertyList.get(PR_BACKGROUND_POSITION_HORIZONTAL); if (prop != null) { bp.backPosHorizontal = prop.getLength(); } - prop = propertyList.get("background-position-vertical"); + prop = propertyList.get(PR_BACKGROUND_POSITION_VERTICAL); if (prop != null) { bp.backPosVertical = prop.getLength(); } @@ -375,8 +375,8 @@ public class PropertyManager { */ public InlineProps getInlineProps() { InlineProps props = new InlineProps(); - props.spaceStart = new SpaceVal(propertyList.get("space-start").getSpace()); - props.spaceEnd = new SpaceVal(propertyList.get("space-end").getSpace()); + props.spaceStart = new SpaceVal(propertyList.get(PR_SPACE_START).getSpace()); + props.spaceEnd = new SpaceVal(propertyList.get(PR_SPACE_END).getSpace()); return props; } @@ -388,11 +388,11 @@ public class PropertyManager { public CommonAccessibility getAccessibilityProps() { CommonAccessibility props = new CommonAccessibility(); String str; - str = this.propertyList.get("source-document").getString(); + str = this.propertyList.get(PR_SOURCE_DOCUMENT).getString(); if (!NONE.equals(str)) { props.sourceDoc = str; } - str = this.propertyList.get("role").getString(); + str = this.propertyList.get(PR_ROLE).getString(); if (!NONE.equals(str)) { props.role = str; } @@ -427,11 +427,11 @@ public class PropertyManager { public CommonAbsolutePosition getAbsolutePositionProps() { CommonAbsolutePosition props = new CommonAbsolutePosition(); props.absolutePosition = - this.propertyList.get("absolute-position").getEnum(); - props.top = this.propertyList.get("top").getLength().getValue(); - props.bottom = this.propertyList.get("bottom").getLength().getValue(); - props.left = this.propertyList.get("left").getLength().getValue(); - props.right = this.propertyList.get("right").getLength().getValue(); + this.propertyList.get(PR_ABSOLUTE_POSITION).getEnum(); + props.top = this.propertyList.get(PR_TOP).getLength().getValue(); + props.bottom = this.propertyList.get(PR_BOTTOM).getLength().getValue(); + props.left = this.propertyList.get(PR_LEFT).getLength().getValue(); + props.right = this.propertyList.get(PR_RIGHT).getLength().getValue(); return props; } @@ -442,12 +442,12 @@ public class PropertyManager { */ public BlockProps getBlockProps() { BlockProps props = new BlockProps(); - props.firstIndent = this.propertyList.get("text-indent").getLength().getValue(); + props.firstIndent = this.propertyList.get(PR_TEXT_INDENT).getLength().getValue(); props.lastIndent = 0; /*this.propertyList.get("last-line-end-indent").getLength().mvalue(); */ - props.textAlign = this.propertyList.get("text-align").getEnum(); - props.textAlignLast = this.propertyList.get("text-align-last").getEnum(); - props.lineStackType = this.propertyList.get("line-stacking-strategy").getEnum(); + props.textAlign = this.propertyList.get(PR_TEXT_ALIGN).getEnum(); + props.textAlignLast = this.propertyList.get(PR_TEXT_ALIGN_LAST).getEnum(); + props.lineStackType = this.propertyList.get(PR_LINE_STACKING_STRATEGY).getEnum(); return props; } @@ -459,13 +459,13 @@ public class PropertyManager { */ public LayoutProps getLayoutProps() { LayoutProps props = new LayoutProps(); - props.breakBefore = this.propertyList.get("break-before").getEnum(); - props.breakAfter = this.propertyList.get("break-after").getEnum(); - props.bIsSpan = (this.propertyList.get("span").getEnum() == Span.ALL); + props.breakBefore = this.propertyList.get(PR_BREAK_BEFORE).getEnum(); + props.breakAfter = this.propertyList.get(PR_BREAK_AFTER).getEnum(); + props.bIsSpan = (this.propertyList.get(PR_SPAN).getEnum() == Span.ALL); props.spaceBefore = new SpaceVal( - this.propertyList.get("space-before").getSpace()); + this.propertyList.get(PR_SPACE_BEFORE).getSpace()); props.spaceAfter = new SpaceVal( - this.propertyList.get("space-after").getSpace()); + this.propertyList.get(PR_SPACE_AFTER).getSpace()); return props; } @@ -480,28 +480,28 @@ public class PropertyManager { if (textInfo == null) { textInfo = new TextInfo(); textInfo.fs = getFontState(foTreeControl); - textInfo.color = propertyList.get("color").getColorType(); + textInfo.color = propertyList.get(PR_COLOR).getColorType(); textInfo.verticalAlign = - propertyList.get("vertical-align").getEnum(); + propertyList.get(PR_VERTICAL_ALIGN).getEnum(); - textInfo.wrapOption = propertyList.get("wrap-option").getEnum(); + textInfo.wrapOption = propertyList.get(PR_WRAP_OPTION).getEnum(); textInfo.bWrap = (textInfo.wrapOption == Constants.WRAP); textInfo.wordSpacing = new SpaceVal( - propertyList.get("word-spacing").getSpace()); + propertyList.get(PR_WORD_SPACING).getSpace()); /* textInfo.letterSpacing = new SpaceVal(propertyList.get("letter-spacing").getSpace());*/ textInfo.whiteSpaceCollapse = - propertyList.get("white-space-collapse").getEnum(); + propertyList.get(PR_WHITE_SPACE_COLLAPSE).getEnum(); textInfo.lineHeight = this.propertyList.get( - "line-height").getLength().getValue(); + PR_LINE_HEIGHT).getLength().getValue(); textInfo.textTransform - = this.propertyList.get("text-transform").getEnum(); + = this.propertyList.get(PR_TEXT_TRANSFORM).getEnum(); } return textInfo; @@ -512,14 +512,14 @@ public class PropertyManager { * @return the enumerated reference-orientation */ public int getAbsRefOrient() { - return propertyList.get("reference-orientation").getNumber().intValue(); + return propertyList.get(PR_REFERENCE_ORIENTATION).getNumber().intValue(); } /** * @return the enumerated writing-mode */ public int getWritingMode() { - return propertyList.get("writing-mode").getEnum(); + return propertyList.get(PR_WRITING_MODE).getEnum(); } } diff --git a/src/java/org/apache/fop/fo/expr/FromParentFunction.java b/src/java/org/apache/fop/fo/expr/FromParentFunction.java index 2cc3228b3..2cd77d576 100644 --- a/src/java/org/apache/fop/fo/expr/FromParentFunction.java +++ b/src/java/org/apache/fop/fo/expr/FromParentFunction.java @@ -51,6 +51,8 @@ package org.apache.fop.fo.expr; import org.apache.fop.fo.Property; +import org.apache.fop.fo.properties.FOPropertyMapping; + /** * Class modelling the from-parent Property Value function. See Sec. 5.10.4 of @@ -86,7 +88,7 @@ public class FromParentFunction extends FunctionBase { * non-inherited properties too. Perhaps the result is different for * a property line line-height which "inherits specified"??? */ - return pInfo.getPropertyList().getFromParent(propName); + return pInfo.getPropertyList().getFromParent(FOPropertyMapping.getPropertyId(propName)); } } diff --git a/src/java/org/apache/fop/fo/flow/Block.java b/src/java/org/apache/fop/fo/flow/Block.java index b1ae2a9f0..cb809be15 100644 --- a/src/java/org/apache/fop/fo/flow/Block.java +++ b/src/java/org/apache/fop/fo/flow/Block.java @@ -132,14 +132,14 @@ public class Block extends FObjMixed { */ public void handleAttrs(Attributes attlist) throws FOPException { super.handleAttrs(attlist); - this.span = this.propertyList.get("span").getEnum(); + this.span = this.propertyList.get(PR_SPAN).getEnum(); this.wsTreatment = - this.propertyList.get("white-space-treatment").getEnum(); + this.propertyList.get(PR_WHITE_SPACE_TREATMENT).getEnum(); this.bWScollapse = - (this.propertyList.get("white-space-collapse").getEnum() + (this.propertyList.get(PR_WHITE_SPACE_COLLAPSE).getEnum() == Constants.TRUE); this.lfTreatment = - this.propertyList.get("linefeed-treatment").getEnum(); + this.propertyList.get(PR_LINEFEED_TREATMENT).getEnum(); setupID(); @@ -199,29 +199,29 @@ public class Block extends FObjMixed { // this.propertyList.get("wrap-option"); // this.propertyList.get("z-index"); - this.align = this.propertyList.get("text-align").getEnum(); + this.align = this.propertyList.get(PR_TEXT_ALIGN).getEnum(); this.alignLast = - this.propertyList.get("text-align-last").getEnum(); - this.breakAfter = this.propertyList.get("break-after").getEnum(); + this.propertyList.get(PR_TEXT_ALIGN_LAST).getEnum(); + this.breakAfter = this.propertyList.get(PR_BREAK_AFTER).getEnum(); this.lineHeight = this.propertyList.get( - "line-height").getLength().getValue(); + PR_LINE_HEIGHT).getLength().getValue(); this.startIndent = this.propertyList.get( - "start-indent").getLength().getValue(); + PR_START_INDENT).getLength().getValue(); this.endIndent = this.propertyList.get( - "end-indent").getLength().getValue(); + PR_END_INDENT).getLength().getValue(); this.spaceBefore = this.propertyList.get( - "space-before.optimum").getLength().getValue(); + PR_SPACE_BEFORE | CP_OPTIMUM).getLength().getValue(); this.spaceAfter = this.propertyList.get( - "space-after.optimum").getLength().getValue(); + PR_SPACE_AFTER | CP_OPTIMUM).getLength().getValue(); this.textIndent = this.propertyList.get( - "text-indent").getLength().getValue(); + PR_TEXT_INDENT).getLength().getValue(); this.keepWithNext = - this.propertyList.get("keep-with-next").getEnum(); + this.propertyList.get(PR_KEEP_WITH_NEXT).getEnum(); this.blockWidows = - this.propertyList.get("widows").getNumber().intValue(); + this.propertyList.get(PR_WIDOWS).getNumber().intValue(); this.blockOrphans = - this.propertyList.get("orphans").getNumber().intValue(); + this.propertyList.get(PR_ORPHANS).getNumber().intValue(); } diff --git a/src/java/org/apache/fop/fo/flow/BlockContainer.java b/src/java/org/apache/fop/fo/flow/BlockContainer.java index 77ab61871..48ed69b70 100644 --- a/src/java/org/apache/fop/fo/flow/BlockContainer.java +++ b/src/java/org/apache/fop/fo/flow/BlockContainer.java @@ -93,7 +93,7 @@ public class BlockContainer extends FObj { */ public void handleAttrs(Attributes attlist) throws FOPException { super.handleAttrs(attlist); - this.span = this.propertyList.get("span").getEnum(); + this.span = this.propertyList.get(PR_SPAN).getEnum(); setupID(); } @@ -126,11 +126,11 @@ public class BlockContainer extends FObj { // this.propertyList.get("writing-mode"); this.backgroundColor = - this.propertyList.get("background-color").getColorType(); + this.propertyList.get(PR_BACKGROUND_COLOR).getColorType(); - this.width = this.propertyList.get("width").getLength().getValue(); - this.height = this.propertyList.get("height").getLength().getValue(); - span = this.propertyList.get("span").getEnum(); + this.width = this.propertyList.get(PR_WIDTH).getLength().getValue(); + this.height = this.propertyList.get(PR_HEIGHT).getLength().getValue(); + span = this.propertyList.get(PR_SPAN).getEnum(); } diff --git a/src/java/org/apache/fop/fo/flow/Inline.java b/src/java/org/apache/fop/fo/flow/Inline.java index 99309101c..071e02550 100644 --- a/src/java/org/apache/fop/fo/flow/Inline.java +++ b/src/java/org/apache/fop/fo/flow/Inline.java @@ -133,7 +133,7 @@ public class Inline extends FObjMixed { // this.propertyList.get("visibility"); // this.propertyList.get("z-index"); - int textDecoration = this.propertyList.get("text-decoration").getEnum(); + int textDecoration = this.propertyList.get(PR_TEXT_DECORATION).getEnum(); if (textDecoration == TextDecoration.UNDERLINE) { this.underlined = true; diff --git a/src/java/org/apache/fop/fo/flow/Marker.java b/src/java/org/apache/fop/fo/flow/Marker.java index c001016cf..e41504c77 100644 --- a/src/java/org/apache/fop/fo/flow/Marker.java +++ b/src/java/org/apache/fop/fo/flow/Marker.java @@ -55,6 +55,7 @@ import org.xml.sax.Attributes; // FOP import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.Constants; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObjMixed; import org.apache.fop.fo.FOTreeVisitor; @@ -89,7 +90,7 @@ public class Marker extends FObjMixed { super.handleAttrs(attlist); this.markerClassName = - this.propertyList.get("marker-class-name").getString(); + this.propertyList.get(Constants.PR_MARKER_CLASS_NAME).getString(); } /** -- 2.39.5