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;
/** 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 <code>property</code> 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 <code>property</code> 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
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) {
}
}
+ 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
{
// Clean up structures that are no longer needed
propertySet = null;
specifiedProps = null;
+ correspondingProps = null;
attrBitSet = null;
foKeys = null;
foProperties = null;
package org.apache.fop.fo;
-import java.util.BitSet;
+//import java.util.BitSet;
import java.util.HashMap;
import java.util.StringTokenizer;
*/
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
(int)((PropNames.LAST_PROPERTY_INDEX + 1) / 0.75) + 1);
/**
- * An <tt>int[]</tt> containing the <i>inherited</i> values from the
- * <tt>Property</tt> classes.
- */
- private final int[] inherited
- = new int[PropNames.LAST_PROPERTY_INDEX + 1];
-
- /**
- * A <tt>BitSet</tt> 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.
- * <p>The <tt>BitSet</tt> is private and is the basis for
- * <i>inheritedProperties</i>.
- */
- private final BitSet inheritedprops
- = new BitSet(PropNames.LAST_PROPERTY_INDEX + 1);
-
- /**
- * An int[] array of the types of the <i>initialValue</i> 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 <tt>PropertyValue</tt> 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 <i>dataTypes</i> field of each
+ * An int[] array of the values of the <i>traitMapping</i> 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
- * <i>dataTypes</i> field in each property class.
+ * <i>traitMapping</i> 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 <i>traitMapping</i> field of each
+ * An int[] array of the types of the <i>initialValue</i> 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
- * <i>traitMapping</i> 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
throws PropertyException
{
setupProperty(propindex);
- //System.out.println("getInitialValueType: " + propindex + " "
- //+ initialValueTypes[propindex]);
return initialValueTypes[propindex];
}
+ /**
+ * A <tt>PropertyValue</tt> 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 <tt>PropertyValue</tt> for a given property.
* Note that this is a <b>raw</b> value; if it is
{
if (initialValues[propindex] != null)
return initialValues[propindex];
- //System.out.println("PropertyConts.getInitialValue(" + propindex
- //+ ") " + PropNames.getPropertyName(propindex));
return
(initialValues[propindex] =
setupProperty(propindex).getInitialValue(propindex));
}
/**
- * Get the <tt>Numeric</tt> value corresponding to an enumerated value.
- * @param foNode the <tt>FONode</tt> being built
- * @param propindex int index of the FO property
- * @param enum - the integer equivalent of the enumeration keyword.
- * @return the <tt>Numeric</tt> result.
- * @throws PropertyException
+ * An <tt>int[]</tt> containing the <i>inherited</i> values from the
+ * <tt>Property</tt> 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
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
Property property = setupProperty(propindex);
return inherited[propindex] != Property.NO;
}
-
/**
* @param property String name of the FO property
* @return <tt>boolean</tt> is property inherited?
return isInherited(PropNames.getPropertyIndex(property));
}
+
+ /**
+ * An int[] array of the values of the <i>dataTypes</i> 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
+ * <i>dataTypes</i> field in each property class.
+ */
+ private final int[] datatypes
+ = new int[PropNames.LAST_PROPERTY_INDEX + 1];
+
+ /**
+ * Get the <tt>Numeric</tt> value corresponding to an enumerated value.
+ * @param foNode the <tt>FONode</tt> being built
+ * @param propindex int index of the FO property
+ * @param enum - the integer equivalent of the enumeration keyword.
+ * @return the <tt>Numeric</tt> 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 <tt>boolean</tt> is property a shorthand?
return property.getEnumText(enumIndex);
}
+ /** An array of boolean results of the <code>isCorrespondingAbsolute</code>
+ * 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 <code>isCorrespondingRelative</code>
+ * 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
* <tt>Property</tt> object. If the <tt>Property</tt> object
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
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