From b754c5bb080392349330a2ce0d317348ed5fed63 Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Sat, 24 Apr 2004 13:43:25 +0000 Subject: [PATCH] More work on border corresponding properties; Handling corresponding properties within FONode git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197537 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/FONode.java | 80 +++++++- src/java/org/apache/fop/fo/PropNames.java | 4 + .../org/apache/fop/fo/PropertyConsts.java | 175 +++++++++--------- .../BorderColorCorrespondingAbsolute.java | 3 + .../BorderColorCorrespondingRelative.java | 3 + .../properties/BorderCommonStyleAbsolute.java | 3 + .../properties/BorderCommonStyleRelative.java | 3 + .../properties/BorderCommonWidthAbsolute.java | 3 + .../properties/BorderCommonWidthRelative.java | 3 + .../fop/fo/properties/BorderLeftStyle.java | 2 +- .../apache/fop/fo/properties/Property.java | 4 +- 11 files changed, 187 insertions(+), 96 deletions(-) diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 40b181da3..e3bb2366d 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -36,6 +36,7 @@ import org.apache.fop.datatypes.indirect.IndirectValue; import org.apache.fop.fo.expr.FunctionNotImplementedException; import org.apache.fop.fo.expr.PropertyException; import org.apache.fop.fo.expr.PropertyParser; +import org.apache.fop.fo.properties.CorrespondingProperty; import org.apache.fop.fo.properties.Property; import org.apache.fop.xml.XmlEvent; import org.apache.fop.xml.Namespaces; @@ -142,6 +143,31 @@ public class FONode extends SyncedNode{ /** BitSet of properties which have been specified on this node. */ private BitSet specifiedProps = new BitSet(PropNames.LAST_PROPERTY_INDEX + 1); + /** BitSet of corresponding properties set on this mode. */ + private BitSet correspondingProps = + new BitSet(PropNames.LAST_CORRESPONDING_INDEX + 1); + /** + * Indicate that the corresponding property has been set on + * this node + * @param property + */ + public void setCorresponding(int property) throws PropertyException { + if (correspondingProps != null) { + correspondingProps.set(property); + } + throw new PropertyException("No corresponding BitSet"); + } + /** + * Has the corresponding property been set on this node? + * @param property + * @return + */ + public boolean correspondingSet(int property) throws PropertyException { + if (correspondingProps != null) { + return correspondingProps.get(property); + } + throw new PropertyException("No corresponding BitSet"); + } /** The property set for this node. This reference has two lives. During FO subtree building, it holds all values which may potentially @@ -257,21 +283,14 @@ public class FONode extends SyncedNode{ try { props = handleAttrValue(prop, attrValue); ptype = props.getType(); - if (ptype != PropertyValue.LIST) { - property = props.getProperty(); - // Update the propertySet - propertySet[property] = props; - specifiedProps.set(property); - // Handle corresponding properties here + if (ptype != PropertyValue.LIST) { + handlePropertyValue(props); } else { // a list PropertyValue value; Iterator propvals = ((PropertyValueList)props).iterator(); while (propvals.hasNext()) { value = (PropertyValue)(propvals.next()); - property = value.getProperty(); - propertySet[value.getProperty()] = value; - specifiedProps.set(property); - // Handle corresponding properties here + handlePropertyValue(value); } } } catch (FunctionNotImplementedException e) { @@ -287,6 +306,46 @@ public class FONode extends SyncedNode{ } } + private void handlePropertyValue(PropertyValue propval) + throws PropertyException { + int property = propval.getProperty(); + Property tempP = + PropertyConsts.pconsts.getProperty(property); + specifiedProps.set(property); + // Handle corresponding properties here + if (tempP instanceof CorrespondingProperty) { + // is this property already set? + if ( ! correspondingProps.get(property)) { + // Update the propertySet + propertySet[property] = propval; + correspondingProps.set(property); + // find corresponding properties, and check whether + // already set + // TODO Can a property have more than one + // coresponding? I don't think so. I think this + // is dealt with in shorthand/compound handling + int corresP = + ((CorrespondingProperty)tempP) + .getCorrespondingProperty(this); + if ( ! correspondingProps.get(corresP)) { + propertySet[corresP] = propval; + correspondingProps.set(corresP); + } // else this property's corresponding property + // already set. Presumably it has already been + // encountered in the set of attributes, e.g. + // the absolute property is set. Ignore this + // value. + } // this property already set by its corresponding + // property. E.g. this is a relative property. + // Ignore this value. + } + else { + // Not a corresponding property + // Update the propertySet + propertySet[property] = propval; + } + } + private PropertyValue handleAttrValue(int property, String attrValue) throws FunctionNotImplementedException, PropertyException { @@ -320,6 +379,7 @@ public class FONode extends SyncedNode{ // Clean up structures that are no longer needed propertySet = null; specifiedProps = null; + correspondingProps = null; attrBitSet = null; foKeys = null; foProperties = null; diff --git a/src/java/org/apache/fop/fo/PropNames.java b/src/java/org/apache/fop/fo/PropNames.java index 08deb0808..44d8a2763 100644 --- a/src/java/org/apache/fop/fo/PropNames.java +++ b/src/java/org/apache/fop/fo/PropNames.java @@ -407,6 +407,10 @@ public class PropNames { Z_INDEX = 323, LAST_PROPERTY_INDEX = Z_INDEX; + // TODO specify last corresponding accurately and possibly re-organize to + // group all corresponding properties early in the list + public static final int + LAST_CORRESPONDING_INDEX = Z_INDEX; /** diff --git a/src/java/org/apache/fop/fo/PropertyConsts.java b/src/java/org/apache/fop/fo/PropertyConsts.java index 7cf205c4e..e6b9304ec 100644 --- a/src/java/org/apache/fop/fo/PropertyConsts.java +++ b/src/java/org/apache/fop/fo/PropertyConsts.java @@ -24,7 +24,7 @@ package org.apache.fop.fo; -import java.util.BitSet; +//import java.util.BitSet; import java.util.HashMap; import java.util.StringTokenizer; @@ -73,7 +73,15 @@ public class PropertyConsts { */ private final Property[] properties = new Property[PropNames.LAST_PROPERTY_INDEX + 1]; - + /** + * Get the individual Property object denoted by the property index + * @param propindex + * @return + * @throws PropertyException + */ + public Property getProperty(int propindex) throws PropertyException { + return setupProperty(propindex); + } /** * A Class[] array containing Class objects corresponding to each of the * class names in the classNames array. Elements are set @@ -106,62 +114,24 @@ public class PropertyConsts { (int)((PropNames.LAST_PROPERTY_INDEX + 1) / 0.75) + 1); /** - * An int[] containing the inherited values from the - * Property classes. - */ - private final int[] inherited - = new int[PropNames.LAST_PROPERTY_INDEX + 1]; - - /** - * A BitSet of properties which are normally inherited - * (strictly, not not inherited). - * It is defined relative to the set of all properties; i.e. the - * inheritability of any property can be established by testing the - * bit in this set that corresponds to the queried property's index. - *

The BitSet is private and is the basis for - * inheritedProperties. - */ - private final BitSet inheritedprops - = new BitSet(PropNames.LAST_PROPERTY_INDEX + 1); - - /** - * An int[] array of the types of the initialValue field of each - * property. The array is indexed by the index value constants that are - * defined in the PropNames class in parallel to the - * PropNames.propertyNames[] array. - */ - private final int[] initialValueTypes - = new int[PropNames.LAST_PROPERTY_INDEX + 1]; - - /** - * A PropertyValue array containing the initial values of - * each of the properties. - */ - private final PropertyValue[] initialValues - = new PropertyValue[PropNames.LAST_PROPERTY_INDEX + 1]; - - /** - * An int[] array of the values of the dataTypes field of each + * An int[] array of the values of the traitMapping field of each * property. The array is indexed by the index value constants that are * defined in the PropNames class in parallel to the * PropNames.propertyNames[] array. * The array elements are set from the values of the - * dataTypes field in each property class. + * traitMapping field in each property class. */ - private final int[] datatypes + private final int[] traitMappings = new int[PropNames.LAST_PROPERTY_INDEX + 1]; /** - * An int[] array of the values of the traitMapping field of each + * An int[] array of the types of the initialValue field of each * property. The array is indexed by the index value constants that are * defined in the PropNames class in parallel to the * PropNames.propertyNames[] array. - * The array elements are set from the values of the - * traitMapping field in each property class. */ - private final int[] traitMappings + private final int[] initialValueTypes = new int[PropNames.LAST_PROPERTY_INDEX + 1]; - /** * Get the initial value type for a property name. * @param property String name of the FO property @@ -187,11 +157,15 @@ public class PropertyConsts { throws PropertyException { setupProperty(propindex); - //System.out.println("getInitialValueType: " + propindex + " " - //+ initialValueTypes[propindex]); return initialValueTypes[propindex]; } + /** + * A PropertyValue array containing the initial values of + * each of the properties. + */ + private final PropertyValue[] initialValues + = new PropertyValue[PropNames.LAST_PROPERTY_INDEX + 1]; /** * Get the initial value PropertyValue for a given property. * Note that this is a raw value; if it is @@ -206,8 +180,6 @@ public class PropertyConsts { { if (initialValues[propindex] != null) return initialValues[propindex]; - //System.out.println("PropertyConts.getInitialValue(" + propindex - //+ ") " + PropNames.getPropertyName(propindex)); return (initialValues[propindex] = setupProperty(propindex).getInitialValue(propindex)); @@ -249,25 +221,11 @@ public class PropertyConsts { } /** - * Get the Numeric value corresponding to an enumerated value. - * @param foNode the FONode being built - * @param propindex int index of the FO property - * @param enum - the integer equivalent of the enumeration keyword. - * @return the Numeric result. - * @throws PropertyException + * An int[] containing the inherited values from the + * Property classes. */ - public Numeric getMappedNumeric(FONode foNode, int propindex, int enum) - throws PropertyException - { - Property property = setupProperty(propindex); - if ((datatypes[propindex] & Property.MAPPED_LENGTH) != 0) - return property.getMappedLength(foNode, enum); - else - throw new PropertyException - ("MAPPED_LENGTH not valid in " - + PropNames.getPropertyName(propindex)); - } - + private final int[] inherited + = new int[PropNames.LAST_PROPERTY_INDEX + 1]; /** * @param property name of the FO property * @return int type of inheritance for this property @@ -277,7 +235,6 @@ public class PropertyConsts { public int inheritance(String property) throws PropertyException { return inheritance(PropNames.getPropertyIndex(property)); } - /** * @param propindex int index of the FO property * @return int type of inheritance for this property @@ -298,7 +255,6 @@ public class PropertyConsts { Property property = setupProperty(propindex); return inherited[propindex] != Property.NO; } - /** * @param property String name of the FO property * @return boolean is property inherited? @@ -308,6 +264,37 @@ public class PropertyConsts { return isInherited(PropNames.getPropertyIndex(property)); } + + /** + * An int[] array of the values of the dataTypes field of each + * property. The array is indexed by the index value constants that are + * defined in the PropNames class in parallel to the + * PropNames.propertyNames[] array. + * The array elements are set from the values of the + * dataTypes field in each property class. + */ + private final int[] datatypes + = new int[PropNames.LAST_PROPERTY_INDEX + 1]; + + /** + * Get the Numeric value corresponding to an enumerated value. + * @param foNode the FONode being built + * @param propindex int index of the FO property + * @param enum - the integer equivalent of the enumeration keyword. + * @return the Numeric result. + * @throws PropertyException + */ + public Numeric getMappedNumeric(FONode foNode, int propindex, int enum) + throws PropertyException + { + Property property = setupProperty(propindex); + if ((datatypes[propindex] & Property.MAPPED_LENGTH) != 0) + return property.getMappedLength(foNode, enum); + else + throw new PropertyException + ("MAPPED_LENGTH not valid in " + + PropNames.getPropertyName(propindex)); + } /** * @param propindex int index of the FO property * @return boolean is property a shorthand? @@ -405,6 +392,37 @@ public class PropertyConsts { return property.getEnumText(enumIndex); } + /** An array of boolean results of the isCorrespondingAbsolute + * method */ + private final boolean[] correspondingAbs = + new boolean[PropNames.LAST_PROPERTY_INDEX + 1]; + /** + * Is the indicated property absolute corresponding? + * @param propindex + * @return + * @throws PropertyException + */ + public boolean isCorrespondingAbs(int propindex) + throws PropertyException { + Property property = setupProperty(propindex); + return correspondingAbs[propindex]; + } + /** An array of boolean results of the isCorrespondingRelative + * method */ + private final boolean[] correspondingRel = + new boolean[PropNames.LAST_PROPERTY_INDEX + 1]; + /** + * Is the indicated property relative corresponding? + * @param propindex + * @return + * @throws PropertyException + */ + public boolean isCorrespondingRel(int propindex) + throws PropertyException { + Property property = setupProperty(propindex); + return correspondingRel[propindex]; + } + /** * Set up the details of a single property and return the * Property object. If the Property object @@ -418,12 +436,11 @@ public class PropertyConsts { public Property setupProperty(int propindex) throws PropertyException { - String cname = ""; - Class pclass; Property property; - if ((property = properties[propindex]) != null) return property; + String cname = ""; + Class pclass; // Get the property class name StringTokenizer stoke; stoke = new StringTokenizer @@ -448,23 +465,15 @@ public class PropertyConsts { try { pclass = Class.forName(name); classes[propindex] = pclass; - // Instantiate the class property = (Property)(pclass.newInstance()); properties[propindex] = property; - - // Set inheritance value - if ((inherited[propindex] - = property.getInherited()) - != Property.NO) - inheritedprops.set(propindex); - // Set datatypes + inherited[propindex] = property.getInherited(); datatypes[propindex] = property.getDataTypes(); - - // Set initialValueTypes initialValueTypes[propindex] = property.getInitialValueType(); - traitMappings[propindex] = property.getTraitMapping(); + correspondingAbs[propindex] = property.isCorrespondingAbsolute(); + correspondingRel[propindex] = property.isCorrespondingRelative(); } catch (ClassNotFoundException e) { throw new PropertyException diff --git a/src/java/org/apache/fop/fo/properties/BorderColorCorrespondingAbsolute.java b/src/java/org/apache/fop/fo/properties/BorderColorCorrespondingAbsolute.java index ec0c8bfe6..e984315ec 100644 --- a/src/java/org/apache/fop/fo/properties/BorderColorCorrespondingAbsolute.java +++ b/src/java/org/apache/fop/fo/properties/BorderColorCorrespondingAbsolute.java @@ -55,4 +55,7 @@ public class BorderColorCorrespondingAbsolute extends BorderColorCorresponding { return relBorderColorProps[relEdge]; } + public boolean isCorrespondingAbsolute() { + return true; + } } diff --git a/src/java/org/apache/fop/fo/properties/BorderColorCorrespondingRelative.java b/src/java/org/apache/fop/fo/properties/BorderColorCorrespondingRelative.java index df814cdd6..db80d95fe 100644 --- a/src/java/org/apache/fop/fo/properties/BorderColorCorrespondingRelative.java +++ b/src/java/org/apache/fop/fo/properties/BorderColorCorrespondingRelative.java @@ -59,4 +59,7 @@ public class BorderColorCorrespondingRelative extends BorderColorCorresponding { return false; } + public boolean isCorrespondingRelative() { + return true; + } } diff --git a/src/java/org/apache/fop/fo/properties/BorderCommonStyleAbsolute.java b/src/java/org/apache/fop/fo/properties/BorderCommonStyleAbsolute.java index c8d31a91d..aa03715ee 100644 --- a/src/java/org/apache/fop/fo/properties/BorderCommonStyleAbsolute.java +++ b/src/java/org/apache/fop/fo/properties/BorderCommonStyleAbsolute.java @@ -59,4 +59,7 @@ extends BorderCommonStyle { return relBorderStyleProps[relEdge]; } + public boolean isCorrespondingAbsolute() { + return true; + } } diff --git a/src/java/org/apache/fop/fo/properties/BorderCommonStyleRelative.java b/src/java/org/apache/fop/fo/properties/BorderCommonStyleRelative.java index 7fc0a8e97..c807d685b 100644 --- a/src/java/org/apache/fop/fo/properties/BorderCommonStyleRelative.java +++ b/src/java/org/apache/fop/fo/properties/BorderCommonStyleRelative.java @@ -63,4 +63,7 @@ extends BorderCommonStyle { return false; } + public boolean isCorrespondingRelative() { + return true; + } } diff --git a/src/java/org/apache/fop/fo/properties/BorderCommonWidthAbsolute.java b/src/java/org/apache/fop/fo/properties/BorderCommonWidthAbsolute.java index 096f466e3..bb0a9003b 100644 --- a/src/java/org/apache/fop/fo/properties/BorderCommonWidthAbsolute.java +++ b/src/java/org/apache/fop/fo/properties/BorderCommonWidthAbsolute.java @@ -55,4 +55,7 @@ public abstract class BorderCommonWidthAbsolute extends BorderCommonWidth { return relBorderWidthProps[relEdge]; } + public boolean isCorrespondingAbsolute() { + return true; + } } diff --git a/src/java/org/apache/fop/fo/properties/BorderCommonWidthRelative.java b/src/java/org/apache/fop/fo/properties/BorderCommonWidthRelative.java index ce6c4ce03..6f6c982e6 100644 --- a/src/java/org/apache/fop/fo/properties/BorderCommonWidthRelative.java +++ b/src/java/org/apache/fop/fo/properties/BorderCommonWidthRelative.java @@ -59,4 +59,7 @@ public abstract class BorderCommonWidthRelative extends BorderCommonWidth { return false; } + public boolean isCorrespondingRelative() { + return true; + } } diff --git a/src/java/org/apache/fop/fo/properties/BorderLeftStyle.java b/src/java/org/apache/fop/fo/properties/BorderLeftStyle.java index d54633d16..90aa7a58e 100644 --- a/src/java/org/apache/fop/fo/properties/BorderLeftStyle.java +++ b/src/java/org/apache/fop/fo/properties/BorderLeftStyle.java @@ -51,7 +51,7 @@ extends BorderCommonStyleAbsolute { return inherited; } - public int getCorrespondingRelativeProperty(FONode foNode) + public int getCorrespondingProperty(FONode foNode) throws PropertyException { return getCorrespondingStyleProperty( foNode, WritingMode.LEFT); diff --git a/src/java/org/apache/fop/fo/properties/Property.java b/src/java/org/apache/fop/fo/properties/Property.java index 12760a3a0..ad67a1744 100644 --- a/src/java/org/apache/fop/fo/properties/Property.java +++ b/src/java/org/apache/fop/fo/properties/Property.java @@ -251,7 +251,7 @@ public class Property { * Such properties must override this method. * @return answer */ - public static boolean isCorrespondingAbsolute() { + public boolean isCorrespondingAbsolute() { return false; } @@ -260,7 +260,7 @@ public class Property { * Such properties must override this method. * @return answer */ - public static boolean isCorrespondingRelative() { + public boolean isCorrespondingRelative() { return false; } -- 2.39.5