diff options
author | Andreas L. Delmelle <adelmelle@apache.org> | 2006-02-12 19:37:22 +0000 |
---|---|---|
committer | Andreas L. Delmelle <adelmelle@apache.org> | 2006-02-12 19:37:22 +0000 |
commit | c3ec6a4b5a7752fa974cf962f565a93dd69afe10 (patch) | |
tree | 7b23814aa7054beb20fc514e23f018f731599f86 /src/java/org/apache | |
parent | 49ffdc1d05cfa7ed4dd0abee7e8f7836b193e5ef (diff) | |
download | xmlgraphics-fop-c3ec6a4b5a7752fa974cf962f565a93dd69afe10.tar.gz xmlgraphics-fop-c3ec6a4b5a7752fa974cf962f565a93dd69afe10.zip |
Added implementation for the font shorthand property (+ some checkstyle cleanup)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@377222 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
14 files changed, 390 insertions, 58 deletions
diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index fd9c9a1c5..1e7095554 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,8 @@ import org.apache.fop.fo.properties.CorrespondingPropertyMaker; import org.apache.fop.fo.properties.DimensionPropertyMaker; import org.apache.fop.fo.properties.EnumProperty; import org.apache.fop.fo.properties.FontFamilyProperty; +import org.apache.fop.fo.properties.FontShorthandParser; +import org.apache.fop.fo.properties.FontShorthandProperty; import org.apache.fop.fo.properties.FontSizePropertyMaker; import org.apache.fop.fo.properties.FontStretchPropertyMaker; import org.apache.fop.fo.properties.GenericShorthandParser; @@ -1081,13 +1083,15 @@ public class FOPropertyMapping implements Constants { m = new FontFamilyProperty.Maker(PR_FONT_FAMILY); m.setInherited(true); m.setDefault("sans-serif"); + m.addShorthand(s_generics[PR_FONT]); addPropertyMaker("font-family", m); // font-selection-strategy m = new EnumProperty.Maker(PR_FONT_SELECTION_STRATEGY); m.setInherited(true); m.addEnum("auto", getEnumProperty(EN_AUTO, "AUTO")); - m.addEnum("character-by-character", getEnumProperty(EN_CHARACTER_BY_CHARACTER, "CHARACTER_BY_CHARACTER")); + m.addEnum("character-by-character", getEnumProperty( + EN_CHARACTER_BY_CHARACTER, "CHARACTER_BY_CHARACTER")); m.setDefault("auto"); addPropertyMaker("font-selection-strategy", m); @@ -1105,6 +1109,7 @@ public class FOPropertyMapping implements Constants { m.addEnum("larger", getEnumProperty(EN_LARGER, "LARGER")); m.addEnum("smaller", getEnumProperty(EN_SMALLER, "SMALLER")); m.setPercentBase(LengthBase.INH_FONTSIZE); + m.addShorthand(s_generics[PR_FONT]); addPropertyMaker("font-size", m); // font-stretch @@ -1137,8 +1142,8 @@ public class FOPropertyMapping implements Constants { m.addEnum("italic", getEnumProperty(EN_ITALIC, "ITALIC")); m.addEnum("oblique", getEnumProperty(EN_OBLIQUE, "OBLIQUE")); m.addEnum("backslant", getEnumProperty(EN_BACKSLANT, "BACKSLANT")); - m.setDefault("normal"); + m.addShorthand(s_generics[PR_FONT]); addPropertyMaker("font-style", m); // font-variant @@ -1147,6 +1152,7 @@ public class FOPropertyMapping implements Constants { m.addEnum("normal", getEnumProperty(EN_NORMAL, "NORMAL")); m.addEnum("small-caps", getEnumProperty(EN_SMALL_CAPS, "SMALL_CAPS")); m.setDefault("normal"); + m.addShorthand(s_generics[PR_FONT]); addPropertyMaker("font-variant", m); // font-weight @@ -1154,18 +1160,19 @@ public class FOPropertyMapping implements Constants { m.setInherited(true); m.addKeyword("normal", "400"); m.addKeyword("bold", "700"); - m.addEnum("bolder",getEnumProperty(EN_BOLDER, "BOLDER")); - m.addEnum("lighter",getEnumProperty(EN_LIGHTER, "LIGHTER")); - m.addEnum("100",getEnumProperty(EN_100, "100")); - m.addEnum("200",getEnumProperty(EN_200, "200")); - m.addEnum("300",getEnumProperty(EN_300, "300")); - m.addEnum("400",getEnumProperty(EN_400, "400")); - m.addEnum("500",getEnumProperty(EN_500, "500")); - m.addEnum("600",getEnumProperty(EN_600, "600")); - m.addEnum("700",getEnumProperty(EN_700, "700")); - m.addEnum("800",getEnumProperty(EN_800, "800")); - m.addEnum("900",getEnumProperty(EN_900, "900")); + m.addEnum("bolder", getEnumProperty(EN_BOLDER, "BOLDER")); + m.addEnum("lighter", getEnumProperty(EN_LIGHTER, "LIGHTER")); + m.addEnum("100", getEnumProperty(EN_100, "100")); + m.addEnum("200", getEnumProperty(EN_200, "200")); + m.addEnum("300", getEnumProperty(EN_300, "300")); + m.addEnum("400", getEnumProperty(EN_400, "400")); + m.addEnum("500", getEnumProperty(EN_500, "500")); + m.addEnum("600", getEnumProperty(EN_600, "600")); + m.addEnum("700", getEnumProperty(EN_700, "700")); + m.addEnum("800", getEnumProperty(EN_800, "800")); + m.addEnum("900", getEnumProperty(EN_900, "900")); m.setDefault("400"); + m.addShorthand(s_generics[PR_FONT]); addPropertyMaker("font-weight", m); } @@ -1614,9 +1621,10 @@ public class FOPropertyMapping implements Constants { m = new LineHeightPropertyMaker(PR_LINE_HEIGHT); m.useGeneric(genericSpace); m.setInherited(true); - m.setDefault("normal", true); m.addKeyword("normal", "1.2"); m.setPercentBase(LengthBase.FONTSIZE); + m.setDefault("normal", true); + m.addShorthand(s_generics[PR_FONT]); addPropertyMaker("line-height", m); // line-height-shift-adjustment @@ -2677,9 +2685,16 @@ public class FOPropertyMapping implements Constants { addPropertyMaker("cue", m); // font - m = new ToBeImplementedProperty.Maker(PR_FONT); - m.setInherited(true); + m = new FontShorthandProperty.Maker(PR_FONT); + m.setInherited(true); + m.addEnum("caption", getEnumProperty(EN_CAPTION, "CAPTION")); + m.addEnum("icon", getEnumProperty(EN_ICON, "ICON")); + m.addEnum("message-box", getEnumProperty(EN_MESSAGE_BOX, "MESSAGE_BOX")); + m.addEnum("menu", getEnumProperty(EN_MENU, "MENU")); + m.addEnum("small-caption", getEnumProperty(EN_SMALL_CAPTION, "SMALL_CAPTION")); + m.addEnum("status-bar", getEnumProperty(EN_STATUS_BAR, "STATUS_BAR")); m.setDefault(""); + m.setDatatypeParser(new FontShorthandParser()); addPropertyMaker("font", m); // margin diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java index 38577e383..94fe82a83 100644 --- a/src/java/org/apache/fop/fo/PropertyList.java +++ b/src/java/org/apache/fop/fo/PropertyList.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,13 +42,14 @@ import org.apache.fop.fo.properties.PropertyMaker; /** * Class containing the collection of properties for a given FObj. */ -abstract public class PropertyList { +public abstract class PropertyList { // writing-mode index private int writingMode; private static boolean[] inheritableProperty; + /** reference to the parent FO's propertyList **/ protected PropertyList parentPropertyList = null; private FObj fobj = null; @@ -56,6 +57,7 @@ abstract public class PropertyList { /** * Basic constructor. + * @param fObjToAttach the FO this PropertyList should be attached to * @param parentPropertyList the PropertyList belonging to the new objects * parent */ @@ -72,7 +74,7 @@ abstract public class PropertyList { } /** - * @return the FObj object attached to the parentPropetyList + * @return the FObj object attached to the parentPropertyList */ public FObj getParentFObj() { if (parentPropertyList != null) { @@ -94,6 +96,7 @@ abstract public class PropertyList { * @param propId The id of the property whose value is desired. * @return The value if the property is explicitly set or set by * a shorthand property, otherwise null. + * @throws PropertyException ... */ public Property getExplicitOrShorthand(int propId) throws PropertyException { /* Handle request for one part of a compound property */ @@ -109,14 +112,14 @@ abstract public class PropertyList { * @param propId The ID of the property whose value is desired. * @return The value if the property is explicitly set, otherwise null. */ - abstract public Property getExplicit(int propId); + public abstract Property getExplicit(int propId); /** * Set an value defined explicitly on this FO. * @param propId The ID of the property to set. * @param value The value of the property. */ - abstract public void putExplicit(int propId, Property value); + public abstract void putExplicit(int propId, Property value); /** * Return the value of this property inherited by this FO. @@ -124,6 +127,7 @@ abstract public class PropertyList { * The property must be inheritable! * @param propId The ID of the property whose value is desired. * @return The inherited value, otherwise null. + * @throws PropertyException ... */ public Property getInherited(int propId) throws PropertyException { @@ -142,6 +146,7 @@ abstract public class PropertyList { * the default value. * @param propId The Constants ID of the property whose value is desired. * @return the Property corresponding to that name + * @throws PropertyException ... */ public Property get(int propId) throws PropertyException { return get(propId, true, true); @@ -152,6 +157,12 @@ abstract public class PropertyList { * 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 propId the property's id + * @param bTryInherit true for inherited properties, or when the inherited + * value is needed + * @param bTryDefault true when the default value may be used as a last resort + * @return the property + * @throws PropertyException ... */ public Property get(int propId, boolean bTryInherit, boolean bTryDefault) throws PropertyException { @@ -167,6 +178,7 @@ abstract public class PropertyList { * @param propId The ID of the property whose value is desired. * @return The computed value if the property is explicitly set on some * ancestor of the current FO, else the initial value. + * @throws PropertyException ... */ public Property getNearestSpecified(int propId) throws PropertyException { Property p = null; @@ -189,6 +201,7 @@ abstract public class PropertyList { * @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. + * @throws PropertyException ... */ public Property getFromParent(int propId) throws PropertyException { if (parentPropertyList != null) { @@ -202,6 +215,7 @@ abstract public class PropertyList { * Set writing mode for this FO. * Use that from the nearest ancestor, including self, which generates * reference areas, or from root FO if no ancestor found. + * @throws PropertyException ... */ public void setWritingMode() throws PropertyException { FObj p = fobj.findNearestAncestorFObj(); @@ -235,14 +249,16 @@ abstract public class PropertyList { case Constants.EN_LR_TB: return lrtb; case Constants.EN_RL_TB: return rltb; case Constants.EN_TB_RL: return tbrl; + default: + //nop } return -1; } /** - * + * Adds the attributes, passed in by the parser to the PropertyList + * * @param attributes Collection of attributes passed to us from the parser. - * @throws FOPException If an error occurs while building the PropertyList */ public void addAttributesToList(Attributes attributes) { /* @@ -263,13 +279,20 @@ abstract public class PropertyList { * If font-size is set on this FO, must set it first, since * other attributes specified in terms of "ems" depend on it. */ - /** @todo When we do "shorthand" properties, must handle the - * "font" property as well to see if font-size is set. - */ - attributeName = "font-size"; + attributeName = "font"; attributeValue = attributes.getValue(attributeName); convertAttributeToProperty(attributes, attributeName, - attributeValue); + attributeValue); + if (attributeValue == null) { + /* + * font shorthand wasn't specified, so still need to process + * explicit font-size + */ + attributeName = "font-size"; + attributeValue = attributes.getValue(attributeName); + convertAttributeToProperty(attributes, attributeName, + attributeValue); + } for (int i = 0; i < attributes.getLength(); i++) { attributeName = attributes.getQName(i); diff --git a/src/java/org/apache/fop/fo/properties/ColumnNumberPropertyMaker.java b/src/java/org/apache/fop/fo/properties/ColumnNumberPropertyMaker.java index 71d422b30..f425b1a08 100644 --- a/src/java/org/apache/fop/fo/properties/ColumnNumberPropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/ColumnNumberPropertyMaker.java @@ -1,5 +1,5 @@ /* - * Copyright 2005 The Apache Software Foundation. + * Copyright 2005-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,13 +18,12 @@ package org.apache.fop.fo.properties; -import org.apache.fop.apps.FOPException; import org.apache.fop.fo.Constants; import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.expr.PropertyException; -import org.apache.fop.fo.flow.TableFObj; import org.apache.fop.fo.flow.TableBody; +import org.apache.fop.fo.flow.TableFObj; /** * Maker class for the column-number property on table-cells and @@ -126,7 +125,7 @@ public class ColumnNumberPropertyMaker extends NumberProperty.Maker { //if column-number was explicitly specified, force the parent's current //column index to the specified value, so that the updated index will - //be the correct initial value for the next cell (see Rec 7.26.8) + //be the correct initial value for the next cell/column (see Rec 7.26.8) if (propertyList.getExplicit(Constants.PR_COLUMN_NUMBER) != null) { parent.setCurrentColumnIndex(p.getNumeric().getValue()); } diff --git a/src/java/org/apache/fop/fo/properties/CompoundPropertyMaker.java b/src/java/org/apache/fop/fo/properties/CompoundPropertyMaker.java index e40082af4..5fe37209b 100644 --- a/src/java/org/apache/fop/fo/properties/CompoundPropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/CompoundPropertyMaker.java @@ -256,11 +256,10 @@ public class CompoundPropertyMaker extends PropertyMaker { * @param parentFO The parent FO for the FO whose property is being made. * @return a Property subclass object holding a "compound" property object * initialized to the default values for each component. - * @throws PropertyException + * @throws PropertyException ... */ protected Property makeCompound(PropertyList propertyList, FObj parentFO) - throws PropertyException - { + throws PropertyException { Property p = makeNewProperty(); CompoundDatatype data = (CompoundDatatype) p.getObject(); for (int i = 0; i < Constants.COMPOUND_COUNT; i++) { diff --git a/src/java/org/apache/fop/fo/properties/FontShorthandParser.java b/src/java/org/apache/fop/fo/properties/FontShorthandParser.java new file mode 100644 index 000000000..96b6ead86 --- /dev/null +++ b/src/java/org/apache/fop/fo/properties/FontShorthandParser.java @@ -0,0 +1,68 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.fo.properties; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.FOPropertyMapping; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.expr.PropertyException; + +/** + * A shorthand parser for the font shorthand property + */ +public class FontShorthandParser extends GenericShorthandParser { + + /** + * @see org.apache.fop.fo.properties.ShorthandParser#getValueForProperty() + */ + public Property getValueForProperty(int propId, + Property property, + PropertyMaker maker, + PropertyList propertyList) + throws PropertyException { + + int index = -1; + Property newProp; + switch (propId) { + case Constants.PR_FONT_SIZE: + index = 0; + break; + case Constants.PR_FONT_FAMILY: + index = 1; + break; + case Constants.PR_LINE_HEIGHT: + index = 2; + break; + case Constants.PR_FONT_STYLE: + index = 3; + break; + case Constants.PR_FONT_VARIANT: + index = 4; + break; + case Constants.PR_FONT_WEIGHT: + index = 5; + break; + default: + //nop + } + newProp = (Property) property.getList().get(index); + return newProp; + } +} diff --git a/src/java/org/apache/fop/fo/properties/FontShorthandProperty.java b/src/java/org/apache/fop/fo/properties/FontShorthandProperty.java new file mode 100644 index 000000000..75101c770 --- /dev/null +++ b/src/java/org/apache/fop/fo/properties/FontShorthandProperty.java @@ -0,0 +1,187 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.fo.properties; + +import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.expr.PropertyException; + +/** + * Property subclass for the font shorthand + */ +public class FontShorthandProperty extends ListProperty { + + /** + * Inner class for creating instances of FontShorthandProperty + */ + public static class Maker extends PropertyMaker { + + private static final int[] PROP_IDS = { + Constants.PR_FONT_SIZE, Constants.PR_FONT_FAMILY, + Constants.PR_LINE_HEIGHT, Constants.PR_FONT_STYLE, + Constants.PR_FONT_VARIANT, Constants.PR_FONT_WEIGHT + }; + + /** + * @param propId ID of the property for which Maker should be created + */ + public Maker(int propId) { + super(propId); + } + + /** + * @see PropertyMaker#make(PropertyList, String, FObj) + */ + public Property make(PropertyList propertyList, + String value, FObj fo) throws PropertyException { + + FontShorthandProperty newProp = new FontShorthandProperty(); + newProp.setSpecifiedValue(value); + + String specVal = value; + Property prop = null; + if ("inherit".equals(specVal)) { + for (int i = PROP_IDS.length; --i >= 0;) { + prop = propertyList.getFromParent(PROP_IDS[i]); + newProp.addProperty(prop, i); + } + } else { + /* initialize list with nulls */ + for (int pos = 6; --pos >= 0;) { + newProp.addProperty(null, pos); + } + prop = checkEnumValues(specVal); + if (prop == null) { + /* not an enum: + * value should consist at least of font-size and font-family + * separated by a space + * mind the possible spaces from quoted font-family names + */ + int spaceIndex = value.indexOf(' '); + int quoteIndex = (value.indexOf('\'') == -1) + ? value.indexOf('\"') : value.indexOf('\''); + if (spaceIndex == -1 + || (quoteIndex != -1 && spaceIndex > quoteIndex)) { + /* no spaces or first space appears after the first + * single/double quote, so malformed value string + */ + throw new PropertyException("Invalid property value: " + + "font=\"" + value + "\""); + } + PropertyMaker m = null; + int fromIndex = spaceIndex + 1; + int toIndex = specVal.length(); + /* at least one space that appears before the first + * single/double quote, so extract the individual properties + */ + boolean fontFamilyParsed = false; + int commaIndex = value.indexOf(','); + while (!fontFamilyParsed) { + /* value contains a (list of) possibly quoted + * font-family name(s) + */ + if (commaIndex == -1) { + /* no list, just a single name + * (or first name in the list) + */ + m = FObj.getPropertyMakerFor(PROP_IDS[1]); + prop = m.make(propertyList, specVal.substring(fromIndex), fo); + newProp.addProperty(prop, 1); + fontFamilyParsed = true; + } else { + if (quoteIndex != -1 && quoteIndex < commaIndex) { + /* a quoted font-family name as first name + * in the comma-separated list + * fromIndex = index of the first quote + */ + fromIndex = quoteIndex; + } else { + fromIndex = value.lastIndexOf(' ', commaIndex) + 1; + } + commaIndex = -1; + } + } + toIndex = fromIndex - 1; + fromIndex = value.lastIndexOf(' ', toIndex - 1) + 1; + value = specVal.substring(fromIndex, toIndex); + int slashIndex = value.indexOf('/'); + String fontSize = value.substring(0, + (slashIndex == -1) ? value.length() : slashIndex); + m = FObj.getPropertyMakerFor(PROP_IDS[0]); + prop = m.make(propertyList, fontSize, fo); + /* need to make sure subsequent call to LineHeightPropertyMaker.make() + * doesn't generate the default font-size property... + */ + propertyList.putExplicit(PROP_IDS[0], prop); + newProp.addProperty(prop, 0); + if (slashIndex != -1) { + /* line-height */ + String lineHeight = value.substring(slashIndex + 1); + m = FObj.getPropertyMakerFor(PROP_IDS[2]); + prop = m.make(propertyList, lineHeight, fo); + newProp.addProperty(prop, 2); + } + if (fromIndex != 0) { + toIndex = fromIndex - 1; + value = specVal.substring(0, toIndex); + fromIndex = 0; + spaceIndex = value.indexOf(' '); + do { + toIndex = (spaceIndex == -1) ? value.length() : spaceIndex; + String val = value.substring(fromIndex, toIndex); + for (int i = 6; --i >= 3;) { + if (newProp.list.get(i) == null) { + /* not set */ + m = FObj.getPropertyMakerFor(PROP_IDS[i]); + val = m.checkValueKeywords(val); + prop = m.checkEnumValues(val); + if (prop != null) { + newProp.addProperty(prop, i); + } + } + } + fromIndex = toIndex + 1; + spaceIndex = value.indexOf(' ', fromIndex); + } while (toIndex != value.length()); + } + } else { + //TODO: implement enum values + log.warn("Enum values other than \"inherit\"" + + " not yet supported for the font shorthand."); + return null; + } + } + if (newProp.list.get(0) == null || newProp.list.get(1) == null) { + throw new PropertyException("Invalid property value: " + + "font-size and font-family are required for the font shorthand" + + "\nfont=" + value); + } + return newProp; + } + + } + + private void addProperty(Property prop, int pos) { + while (list.size() < (pos + 1)) { + list.add(null); + } + list.set(pos, prop); + } +} diff --git a/src/java/org/apache/fop/fo/properties/FontSizePropertyMaker.java b/src/java/org/apache/fop/fo/properties/FontSizePropertyMaker.java index 83379dfa4..5cb36f978 100644 --- a/src/java/org/apache/fop/fo/properties/FontSizePropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/FontSizePropertyMaker.java @@ -14,7 +14,7 @@ * limitations under the License. */ -/* $Id: $ */ +/* $Id$ */ package org.apache.fop.fo.properties; import org.apache.fop.fo.Constants; diff --git a/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java b/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java index cc4546791..c86a9676e 100644 --- a/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java +++ b/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java @@ -23,6 +23,9 @@ import java.util.Iterator; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.expr.PropertyException; +/** + * Generic shorthand parser for ListProperties + */ public class GenericShorthandParser implements ShorthandParser { /** @@ -32,6 +35,7 @@ public class GenericShorthandParser implements ShorthandParser { } /** + * @param list the ListProperty * @param index the index into the List of properties * @return the property from the List of properties at the index parameter */ @@ -42,9 +46,10 @@ public class GenericShorthandParser implements ShorthandParser { return null; } } - - // Stores 1 to 3 values for border width, style, color - // Used for: border, border-top, border-right etc + + /** + * @see org.apache.fop.fo.properties.ShorthandParser#getValueForProperty() + */ public Property getValueForProperty(int propId, Property property, PropertyMaker maker, @@ -65,9 +70,11 @@ public class GenericShorthandParser implements ShorthandParser { * Converts a property name into a Property * @param propId the property ID in the Constants interface * @param maker the Property.Maker to be used in the conversion + * @param property ... * @param propertyList the PropertyList from which the Property should be * extracted * @return the Property matching the parameters, or null if not found + * @throws PropertyException (when?) */ protected Property convertValueForProperty(int propId, Property property, diff --git a/src/java/org/apache/fop/fo/properties/LengthProperty.java b/src/java/org/apache/fop/fo/properties/LengthProperty.java index 243414605..3ed72b9af 100644 --- a/src/java/org/apache/fop/fo/properties/LengthProperty.java +++ b/src/java/org/apache/fop/fo/properties/LengthProperty.java @@ -27,9 +27,9 @@ import org.apache.fop.fo.expr.PropertyException; /** * Superclass for properties wrapping a Length value. */ -abstract public class LengthProperty extends Property - implements Length, Numeric -{ +public abstract class LengthProperty extends Property + implements Length, Numeric { + /** * Inner class for making instances of LengthProperty */ @@ -49,10 +49,6 @@ abstract public class LengthProperty extends Property public Property convertProperty(Property p, PropertyList propertyList, FObj fo) throws PropertyException { - Property prop = super.convertProperty(p, propertyList, fo); - if (prop != null) { - return prop; - } if (p instanceof EnumProperty) { return new EnumLength(p); } @@ -63,6 +59,7 @@ abstract public class LengthProperty extends Property if (val != null) { return (Property) val; } + /* always null ?? */ return convertPropertyDatatype(p, propertyList, fo); } diff --git a/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java b/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java index b2194dc97..5c4907bf7 100644 --- a/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/LineHeightPropertyMaker.java @@ -17,7 +17,9 @@ /* $Id$ */ package org.apache.fop.fo.properties; + import org.apache.fop.datatypes.Numeric; +import org.apache.fop.fo.Constants; import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.expr.PropertyException; @@ -41,6 +43,23 @@ public class LineHeightPropertyMaker extends SpaceProperty.Maker { } /** + * @see PropertyMaker#make(PropertyList, String, FObj) + * @throws PropertyException + */ + public Property make(PropertyList propertyList, String value, FObj fo) + throws PropertyException { + /* if value was specified as a number/length/percentage then + * conditionality and precedence components are overridden + */ + Property p = super.make(propertyList, value, fo); + p.getSpace().setConditionality( + new EnumProperty(Constants.EN_RETAIN, "RETAIN"), true); + p.getSpace().setPrecedence( + new EnumProperty(Constants.EN_FORCE, "FORCE"), true); + return p; + } + + /** * Recalculate the line-height value based on the nearest specified * value. * @see PropertyMaker#compute(PropertyList) @@ -65,9 +84,9 @@ public class LineHeightPropertyMaker extends SpaceProperty.Maker { public Property convertProperty(Property p, PropertyList propertyList, FObj fo) throws PropertyException { - Numeric numval = p.getNumeric(); + Numeric numval = p.getNumeric(); if (numval != null && numval.getDimension() == 0) { - p = new PercentLength(numval.getNumericValue(), getPercentBase(fo,propertyList)); + p = new PercentLength(numval.getNumericValue(), getPercentBase(fo, propertyList)); Property spaceProp = super.convertProperty(p, propertyList, fo); spaceProp.setSpecifiedValue(String.valueOf(numval.getNumericValue())); return spaceProp; diff --git a/src/java/org/apache/fop/fo/properties/PageBreakShorthandParser.java b/src/java/org/apache/fop/fo/properties/PageBreakShorthandParser.java index 24d1f0f59..6b991525a 100644 --- a/src/java/org/apache/fop/fo/properties/PageBreakShorthandParser.java +++ b/src/java/org/apache/fop/fo/properties/PageBreakShorthandParser.java @@ -21,7 +21,6 @@ package org.apache.fop.fo.properties; import org.apache.fop.fo.Constants; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.expr.PropertyException; -import org.apache.fop.fo.properties.KeepProperty; /** * Shorthand parser for page-break-before, page-break-after and page-break-inside. diff --git a/src/java/org/apache/fop/fo/properties/PositionShorthandParser.java b/src/java/org/apache/fop/fo/properties/PositionShorthandParser.java index 04d85cd8f..5b44cb0f4 100755 --- a/src/java/org/apache/fop/fo/properties/PositionShorthandParser.java +++ b/src/java/org/apache/fop/fo/properties/PositionShorthandParser.java @@ -26,10 +26,15 @@ import org.apache.fop.fo.PropertyList; * values for absolute-position and relative-position. */ public class PositionShorthandParser implements ShorthandParser { + + /** + * @see org.apache.fop.fo.properties.ShorthandParser#getValueForProperty() + */ public Property getValueForProperty(int propId, Property property, PropertyMaker maker, PropertyList propertyList) { + int propVal = property.getEnum(); if (propId == Constants.PR_ABSOLUTE_POSITION) { switch (propVal) { @@ -40,6 +45,8 @@ public class PositionShorthandParser implements ShorthandParser { return new EnumProperty(Constants.EN_ABSOLUTE, "ABSOLUTE"); case Constants.EN_FIXED: return new EnumProperty(Constants.EN_FIXED, "FIXED"); + default: + //nop } } if (propId == Constants.PR_RELATIVE_POSITION) { @@ -52,6 +59,8 @@ public class PositionShorthandParser implements ShorthandParser { return new EnumProperty(Constants.EN_STATIC, "STATIC"); case Constants.EN_FIXED: return new EnumProperty(Constants.EN_STATIC, "STATIC"); + default: + //nop } } return null; diff --git a/src/java/org/apache/fop/fo/properties/PropertyMaker.java b/src/java/org/apache/fop/fo/properties/PropertyMaker.java index a1dcea7e9..caf9f87bb 100644 --- a/src/java/org/apache/fop/fo/properties/PropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/PropertyMaker.java @@ -59,7 +59,9 @@ public class PropertyMaker implements Cloneable { private PropertyMaker[] shorthands = null; private ShorthandParser datatypeParser; + /** default property **/ protected Property defaultProperty; + /** Maker for 'corresponding' properties **/ protected CorrespondingPropertyMaker corresponding; /** @@ -257,12 +259,12 @@ public class PropertyMaker implements Cloneable { p = corresponding.compute(propertyList); } else { p = propertyList.getExplicit(propId); - if (p == null) { - p = this.compute(propertyList); - } if (p == null) { // check for shorthand specification p = getShorthand(propertyList); } + if (p == null) { + p = this.compute(propertyList); + } } if (p == null && tryInherit) { // else inherit (if has parent and is inheritable) @@ -426,8 +428,7 @@ public class PropertyMaker implements Cloneable { newProp = convertProperty(newProp, propertyList, fo); } if (newProp == null) { - throw new org.apache.fop.fo.expr.PropertyException( - "No conversion defined " + pvalue); + throw new PropertyException("No conversion defined " + pvalue); } return newProp; } catch (PropertyException propEx) { @@ -459,6 +460,15 @@ public class PropertyMaker implements Cloneable { return baseProperty; } + /** + * Converts a shorthand property + * + * @param propertyList the propertyList for which to convert + * @param prop the shorthand property + * @param fo ... + * @return the converted property + * @throws PropertyException ... + */ public Property convertShorthandProperty(PropertyList propertyList, Property prop, FObj fo) throws PropertyException { @@ -467,13 +477,13 @@ public class PropertyMaker implements Cloneable { // If value is a name token, may be keyword or Enum String sval = prop.getNCname(); if (sval != null) { - //log.debug("Convert shorthand ncname " + sval); + log.debug("Convert shorthand ncname " + sval); pret = checkEnumValues(sval); if (pret == null) { /* Check for keyword shorthand values to be substituted. */ String pvalue = checkValueKeywords(sval); if (!pvalue.equals(sval)) { - // log.debug("Convert shorthand keyword" + pvalue); + log.debug("Convert shorthand keyword" + pvalue); // Substituted a value: must parse it Property p = PropertyParser.parse(pvalue, new PropertyInfo(this, diff --git a/src/java/org/apache/fop/fo/properties/SpacePropertyMaker.java b/src/java/org/apache/fop/fo/properties/SpacePropertyMaker.java index 9cc79f261..cca88c72d 100644 --- a/src/java/org/apache/fop/fo/properties/SpacePropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/SpacePropertyMaker.java @@ -36,7 +36,7 @@ public class SpacePropertyMaker extends CorrespondingPropertyMaker { } /** - * @see org.apache.fop.fo.properties.CorrespondingPropertyMaker#compute(org.apache.fop.fo.PropertyList) + * @see org.apache.fop.fo.properties.CorrespondingPropertyMaker#compute(PropertyList) */ public Property compute(PropertyList propertyList) throws PropertyException { Property prop = super.compute(propertyList); |