pbwest 2002/10/04 19:44:24 Modified: src/org/apache/fop/fo Tag: FOP_0-20-0_Alt-Design FOTree.java FONode.java Log: Completed removal of propertyStacks from FOTree, and shift of associated functionality into FONode. Revision Changes Path No revision No revision 1.1.2.16 +4 -152 xml-fop/src/org/apache/fop/fo/Attic/FOTree.java Index: FOTree.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/Attic/FOTree.java,v retrieving revision 1.1.2.15 retrieving revision 1.1.2.16 diff -u -r1.1.2.15 -r1.1.2.16 --- FOTree.java 4 Oct 2002 16:16:23 -0000 1.1.2.15 +++ FOTree.java 5 Oct 2002 02:44:24 -0000 1.1.2.16 @@ -4,10 +4,6 @@ import org.apache.fop.datatypes.Ints; import org.apache.fop.datatypes.Numeric; import org.apache.fop.datatypes.PropertyValue; -import org.apache.fop.datatypes.indirect.Inherit; -import org.apache.fop.datatypes.Auto; -import org.apache.fop.datatypes.None; -import org.apache.fop.datatypes.TextDecorations; import org.apache.fop.xml.XMLEvent; import org.apache.fop.xml.XMLNamespaces; import org.apache.fop.xml.SyncedXmlEventsBuffer; @@ -70,20 +66,6 @@ */ Object[] args = new Object[2]; - /** - * The array of stacks for resolving properties during FO tree building. - * An Array of ArrayList[]. Each ArrayList is a stack containing the - * most recently specified value of a particular property. The first - * element of each stack will contain the initial value. - * <p> - * The array is indexed by the same index values that are defined as - * constants in this file, and are the effective index values for the - * PropNames.propertyNames and classNames arrays. - * <p> - * ArrayList is part of the 1.2 Collections framework. - */ - protected ArrayList[] propertyStacks; - protected PropertyValue[] initialValues = new PropertyValue[PropNames.LAST_PROPERTY_INDEX + 1]; @@ -99,19 +81,14 @@ this.xmlevents = xmlevents; exprParser = new PropertyParser(this); - // Initialise the propertyStacks - propertyStacks = new ArrayList[PropNames.LAST_PROPERTY_INDEX + 1]; - PropertyValue prop; - for (int i = 1; i <= PropNames.LAST_PROPERTY_INDEX; i++) - propertyStacks[i] = new ArrayList(1); // Initialize the FontSize first. Any lengths defined in ems must // be resolved relative to the current font size. This may happen // during setup of initial values. // Set the initial value - prop = PropertyConsts.getInitialValue(PropNames.FONT_SIZE); + PropertyValue prop = + PropertyConsts.getInitialValue(PropNames.FONT_SIZE); if ( ! (prop instanceof Numeric) || ! ((Numeric)prop).isLength()) throw new PropertyException("Initial font-size is not a Length"); - propertyStacks[PropNames.FONT_SIZE].add(prop); initialValues[PropNames.FONT_SIZE] = prop; @@ -119,7 +96,6 @@ if (i == PropNames.FONT_SIZE) continue; // Set up the initial values for each property prop = PropertyConsts.getInitialValue(i); - propertyStacks[i].add(prop); System.out.println("....Setting initial value: " + i + ((prop == null) ? " NULL" : " notNULL")); initialValues[i] = prop; @@ -128,119 +104,6 @@ } /** - * Clone the font size from the <i>font-size</i> property stack. - * @return a <tt>Numeric</tt> containing the current font size - * @exception PropertyException if current font size is not defined, - * or is not expressed as a <tt>Numeric</tt>, or if cloning is not - * supported. - * [REMOVE] - */ - public Numeric cloneCurrentFontSize() throws PropertyException { - Numeric tmpval = - (Numeric)(propertyStacks[PropNames.FONT_SIZE] - .get(propertyStacks[PropNames.FONT_SIZE].size() - 1)); - try { - return (Numeric)(tmpval.clone()); - } catch (CloneNotSupportedException e) { - throw new PropertyException("Clone not supported."); - } - } - - /** - * Get the font size from the <i>font-size</i> property stack. This is - * a reference to the value on the stack. - * @return a <tt>Numeric</tt> containing the current font size - * @exception PropertyException if current font size is not defined, - * or is not expressed as a <tt>Numeric</tt>. - * [REMOVE] - */ - public Numeric currentFontSize() throws PropertyException { - return (Numeric)(propertyStacks[PropNames.FONT_SIZE] - .get(propertyStacks[PropNames.FONT_SIZE].size() - 1)); - } - - /** - * Set the initial value of a particular property. - * @param value <tt>PropertyValue</tt> to set - * @exception <tt>PropertyException</tt> - */ - public void setInitialValue(PropertyValue value) - throws PropertyException - { - propertyStacks[value.getProperty()].set(0, value); - } - - /** - * Clone the current <i>TextDecorations</i> property from the property - * stacks. - * @return a <tt>TextDecorations</tt> object containing the current - * text decorations - * @exception PropertyException if current text decorations are not - * defined, or are not expressed as <tt>TextDecorations</tt>. - */ - public TextDecorations cloneCurrentTextDecorations() - throws PropertyException - { - TextDecorations tmpval = (TextDecorations) - (propertyStacks[PropNames.TEXT_DECORATION] - .get(propertyStacks[PropNames.TEXT_DECORATION].size() - 1)); - try { - return (TextDecorations)(tmpval.clone()); - } catch (CloneNotSupportedException e) { - throw new PropertyException("Clone not supported."); - } - } - - /** - * Get the <tt>PropertyValue</tt> at the top of the stack for a - * given property. Note that this is a <b>raw</b> value; if it is - * an unresolved percentage that value will be returned. - * @param index - the property index. - * @return a <tt>PropertyValue</tt> containing the latest property - * value for the indexed property. - */ - public PropertyValue getCurrentPropertyValue(int index) - throws PropertyException - { - return (PropertyValue)(propertyStacks[index] - .get(propertyStacks[index].size() - 1)); - } - - /** - * Clone the <tt>PropertyValue</tt> at the top of the stack for a - * given property. Note that this is a <b>raw</b> value; if it is - * an unresolved percentage that value will be cloned. - * @param index - the property index. - * @return a <tt>PropertyValue</tt> containing the latest property - * value for the indexed property. - */ - public PropertyValue cloneCurrentPropertyValue(int index) - throws PropertyException - { - PropertyValue tmpval = (PropertyValue)(propertyStacks[index] - .get(propertyStacks[index].size() - 1)); - try { - return (PropertyValue)(tmpval.clone()); - } catch (CloneNotSupportedException e) { - throw new PropertyException("Clone not supported."); - } - } - - /** - * Pop the <tt>PropertyValue</tt> at the top of the stack for a - * given property. - * @param index - the property index. - * @return a <tt>PropertyValue</tt> containing the property - * value elements at the top of the stack for the indexed property. - */ - public PropertyValue popPropertyValue(int index) - throws PropertyException - { - return (PropertyValue)(propertyStacks[index] - .remove(propertyStacks[index].size() - 1)); - } - - /** * Get the initial value <tt>PropertyValue</tt> for a given property. * Note that this is a <b>raw</b> value; if it is * an unresolved percentage that value will be returned. @@ -252,17 +115,6 @@ throws PropertyException { return initialValues[index]; - } - - /** - * Push a <tt>PropertyValue</tt> onto the top of stack for a given - * property. - * @param value a <tt>PropertyValue</tt>. - */ - public void pushPropertyValue(PropertyValue value) - throws PropertyException - { - propertyStacks[value.getProperty()].add(value); } /** 1.19.2.15 +144 -92 xml-fop/src/org/apache/fop/fo/FONode.java Index: FONode.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/FONode.java,v retrieving revision 1.19.2.14 retrieving revision 1.19.2.15 diff -u -r1.19.2.14 -r1.19.2.15 --- FONode.java 4 Oct 2002 16:28:57 -0000 1.19.2.14 +++ FONode.java 5 Oct 2002 02:44:24 -0000 1.19.2.15 @@ -8,10 +8,12 @@ import org.apache.fop.fo.expr.PropertyParser; import org.apache.fop.datatypes.PropertyValue; import org.apache.fop.datatypes.PropertyValueList; -import org.apache.fop.datastructs.Tree; -import org.apache.fop.datastructs.ROBitSet; +import org.apache.fop.datatypes.Numeric; +import org.apache.fop.datatypes.TextDecorations; import org.apache.fop.datatypes.indirect.Inherit; import org.apache.fop.datatypes.indirect.IndirectValue; +import org.apache.fop.datastructs.Tree; +import org.apache.fop.datastructs.ROBitSet; import org.apache.fop.apps.FOPException; import org.apache.fop.xml.XMLEvent; import org.apache.fop.xml.SyncedXmlEventsBuffer; @@ -118,22 +120,9 @@ if ( ! (attrSet == FOPropertySets.MARKER_SET)) { processAttributes(); } - // Set up the remaining properties. - for (int prop = inheritedBitSet.nextSetBit(0); - prop >= 0; - prop = inheritedBitSet.nextSetBit(++prop)) { - System.out.println("...Setting inherited prop " + prop - + " " + PropNames.getPropertyName(prop)); - propertySet[prop] = fromParent(prop); - } - - for (int prop = nonInheritedBitSet.nextSetBit(0); - prop >= 0; - prop = inheritedBitSet.nextSetBit(++prop)) - { - propertySet[prop] = foTree.getInitialValue(prop); - } - + // Do not set up the remaining properties now. + // These will be developed by inheritance or from the initial values + // as the property values are referenced. } private void processAttributes() throws FOPException, PropertyException { @@ -164,19 +153,19 @@ ptype = props.getType(); if (ptype != PropertyValue.LIST) { property = props.getProperty(); - stackValue(props); - // Handle corresponding properties here // Update the propertySet propertySet[props.getProperty()] = props; + specifiedProps.set(property); + // Handle corresponding properties here } else { // a list PropertyValue value; Iterator propvals = ((PropertyValueList)props).iterator(); while (propvals.hasNext()) { value = (PropertyValue)(propvals.next()); property = value.getProperty(); - stackValue(value); - // Handle corresponding properties here propertySet[value.getProperty()] = value; + specifiedProps.set(property); + // Handle corresponding properties here } } } @@ -201,59 +190,15 @@ } } - private void stackValue(PropertyValue value) throws PropertyException { - int property = value.getProperty(); - PropertyValue currentValue = foTree.getCurrentPropertyValue(property); - if (currentValue.getStackedBy() == this) - foTree.popPropertyValue(property); - value.setStackedBy(this); - foTree.pushPropertyValue(value); - specifiedProps.set(property); - } - - private void unstackValues() throws PropertyException { - for (int prop = specifiedProps.nextSetBit(0); - prop >=0; - prop = specifiedProps.nextSetBit(++prop) - ) { - PropertyValue value = foTree.popPropertyValue(prop); - if (value.getStackedBy() != this) - throw new PropertyException - ("Unstacked property not stacked by this node."); - } - } - - /** - * Get the <tt>PropertyValue</tt> of the nearest ancestor with a - * specified value for the given property. - * @param property - the property of interest. - * @return the nearest specified <tt>PropertyValue</tt>. - */ - public PropertyValue getNearestSpecifiedValue(int property) - throws PropertyException - { - PropertyValue value = null; - ArrayList stack = foTree.propertyStacks[property]; - int stackp = stack.size(); - while (stackp-- > 0) { - value = (PropertyValue)(stack.get(stackp)); - // Following equality can't be the case for initial values, - // as their stackedBy will be null. - if (value.getStackedBy() == this) continue; - return value; - } - throw new PropertyException - ("No specified value in stack for " + property + ": " - + PropNames.getPropertyName(property)); - } - /** - * Get the computed value from nearest ancestor with a specified value. + * Get the adjusted <tt>PropertyValue</tt> of the property + * on the nearest ancestor with a specified value for that property. + * @see #fromNearestSpecified(init,int) + * @see #getNearestSpecifiedValue(int) * @param property - the index of both target and source properties. - * @return - the computed value corresponding to the nearest specified - * value (which may be the initial value) if it exists. If no computed - * value is available, return an <tt>Inherit</tt> object with a reference * to the PropertyTriplet. + * @return - the adjusted value corresponding to the nearest specified + * value if it exists, else the adjusted initial value. */ public PropertyValue fromNearestSpecified(int property) throws PropertyException @@ -262,26 +207,62 @@ } /** - * Get the computed value from nearest ancestor with a specified value. + * Get the adjusted <tt>PropertyValue</tt> of the source property + * on the nearest ancestor with a specified value for that property. + * <p>If this node is not the root, call the + * <i>getNearestSpecifiedValue</i> method in the parent node, adjust + * that value, and return the adjusted value. Do not set the current + * value of the property on this node. + * <p>If this is the root node, return the adjusted initial value for the + * property. Do not set the current value of the property on this node. + * <p>The <b>adjusted value</b> is either the value itself, or, if the + * value is an unresolved relative length, an <tt>IndirectValue</tt> + * referring to that unresolved length. + * Cf. {@link #getNearestSpecifiedValue(int)}. * @param property - the index of the target property. * @param sourceProperty - the index of the source property. - * @return - the computed value corresponding to the nearest specified - * value (which may be the initial value) if it exists. If no computed - * value is available, return an <tt>Inherit</tt> object with a reference - * to the PropertyTriplet. + * @return - the adjusted value corresponding to the nearest specified + * value if it exists, else the adjusted initial value. */ public PropertyValue fromNearestSpecified (int property, int sourceProperty) throws PropertyException { - PropertyValue value = getNearestSpecifiedValue(sourceProperty); - // Determine whether an indirect value is required - if (IndirectValue.isUnresolved(value)) { - Inherit inherit = new Inherit(property, sourceProperty); - inherit.setInheritedValue(value); - return inherit; - } - return value; + if (parent != null) + return IndirectValue.adjustedPropertyValue + (parent.getNearestSpecifiedValue(sourceProperty)); + else // root + return IndirectValue.adjustedPropertyValue + (foTree.getInitialValue(sourceProperty)); + } + + /** + * Get the adjusted <tt>PropertyValue</tt> of the property on the nearest + * ancestor with a specified value for the given property. + * <p>If a value has been specified on this node, return the adjusted + * value. + * <p>Otherwise, if the this node is not the root, return the adjusted + * value from a recursive call. + * <p>If this is the root node, return the adjusted initial value for the + * property. + * <p>The <b>adjusted value</b> is either the value itself, or, if the + * value is an unresolved relative length, an <tt>IndirectValue</tt> + * referring to that unresolved length. + * @param property - the property of interest. + * @return the adjusted value of the nearest specified + * <tt>PropertyValue</tt>. + */ + public PropertyValue getNearestSpecifiedValue(int property) + throws PropertyException + { + if (specifiedProps.get(property)) + return IndirectValue.adjustedPropertyValue(propertySet[property]); + if (parent != null) + return IndirectValue.adjustedPropertyValue + (parent.getNearestSpecifiedValue(property)); + else // root + return IndirectValue.adjustedPropertyValue + (foTree.getInitialValue(property)); } /** @@ -301,7 +282,7 @@ /** * Get the adjusted <tt>PropertyValue</tt> for the given source property * on the parent <tt>FONode</tt>. If this node is not the root, - * call the <i>getPropertyValue</i> method in the parent node, adjust that + * call the <i>getPropertyValue</i> method in the parent node, adjust * that value, and return the adjusted value. Do not set the current * value of the property on this node. * <p>If this is the root node, return the adjusted initial value for the @@ -326,10 +307,6 @@ (foTree.getInitialValue(sourceProperty)); } - public PropertyValue currentFontSize() throws PropertyException { - return getPropertyValue(PropNames.FONT_SIZE); - } - /** * Get the adjusted <tt>PropertyValue</tt> for the given property index. @@ -368,6 +345,81 @@ return (propertySet[property] = IndirectValue.adjustedPropertyValue (foTree.getInitialValue(property))); + } + + + /** + * Clone the adjusted <tt>PropertyValue</tt> for the given property index. + * <p>The <b>adjusted value</b> is either the value itself, or, if the + * value is an unresolved relative length, an <tt>IndirectValue</tt> + * referring to that unresolved length. + * Cf. {@link #getPropertyValue(int)}. + * @param index - the property index. + * @return a <tt>PropertyValue</tt> containing a clone of the adjusted + * property value for the indexed property. + */ + public PropertyValue clonePropertyValue(int index) + throws PropertyException + { + PropertyValue tmpval = getPropertyValue(index); + try { + return (PropertyValue)(tmpval.clone()); + } catch (CloneNotSupportedException e) { + throw new PropertyException("Clone not supported."); + } + } + + /** + * Get the current font size. This is a reference to the + * <tt>PropertyValue</tt> located. + * @return a <tt>Numeric</tt> containing the current font size + * @exception PropertyException if current font size is not defined, + * or is not expressed as a <tt>Numeric</tt>. + */ + public Numeric currentFontSize() throws PropertyException { + PropertyValue fontsize = getPropertyValue(PropNames.FONT_SIZE); + if ( ! (fontsize.getType() == PropertyValue.NUMERIC + && ((Numeric)fontsize).isLength())) + throw new PropertyException + ("font-size value is not a length."); + return (Numeric)fontsize; + } + + /** + * Clone the current font size. + * @return a <tt>Numeric</tt> containing the current font size + * @exception PropertyException if current font size is not defined, + * or is not expressed as a <tt>Numeric</tt>, or if cloning is not + * supported. + */ + public Numeric cloneCurrentFontSize() throws PropertyException { + Numeric tmpval = currentFontSize(); + try { + return (Numeric)(tmpval.clone()); + } catch (CloneNotSupportedException e) { + throw new PropertyException(e); + } + } + + /** + * Clone the current <i>TextDecorations</i> property. + * @return a <tt>TextDecorations</tt> object containing the current + * text decorations + * @exception PropertyException if current text decorations are not + * defined, or are not expressed as <tt>TextDecorations</tt>. + */ + public TextDecorations cloneCurrentTextDecorations() + throws PropertyException + { + PropertyValue textdec = getPropertyValue(PropNames.TEXT_DECORATION); + if (textdec.getType() != PropertyValue.TEXT_DECORATIONS) + throw new PropertyException + ("text-decoration value is not a TextDecorations object."); + try { + return (TextDecorations)(textdec.clone()); + } catch (CloneNotSupportedException e) { + throw new PropertyException("Clone not supported."); + } } }// FONode
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]