From ffbfa7cb2628ef8a3c97487def6a1e1fb34c609f Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sun, 23 May 2004 17:00:00 +0000 Subject: [PATCH] Reverted part of yesterday's work to make FObj simpler, added more commenting in FObj. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197619 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/FObj.java | 158 ++++++------------ .../org/apache/fop/fo/PropertyManager.java | 12 +- .../apache/fop/fo/pagination/RegionBody.java | 2 +- .../fop/fo/properties/PropertyMaker.java | 4 +- .../render/rtf/TableAttributesConverter.java | 19 ++- 5 files changed, 74 insertions(+), 121 deletions(-) diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index cec89be12..3f17965cf 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -37,36 +37,25 @@ import org.xml.sax.Locator; */ public class FObj extends FONode implements Constants { private static final String FO_URI = "http://www.w3.org/1999/XSL/Format"; + public static PropertyMaker[] propertyListTable = null; - /** - * Formatting properties for this fo element. - */ + /** Formatting properties for this fo element. */ protected PropertyList propertyList; - /** - * Property manager for handling some common properties. - */ + /** Property manager for providing refined properties/traits. */ protected PropertyManager propMgr; - /** - * Id of this fo element of null if no id. - */ + /** Id of this fo element of null if no id. */ protected String id = null; - /** - * The children of this node. - */ + /** The children of this node. */ public ArrayList children = null; - /** - * Markers added to this element. - */ + /** Markers added to this element. */ protected Map markers = null; - /** - * Dynamic layout dimension. Used to resolve relative lengths. - */ + /** Dynamic layout dimension. Used to resolve relative lengths. */ protected Map layoutDimension = null; /** Marks input file containing this object **/ @@ -102,15 +91,30 @@ public class FObj extends FONode implements Constants { */ public void processNode(String elementName, Locator locator, Attributes attlist) throws FOPException { - name = "fo:" + elementName; + setName(elementName); + setLocation(locator); + addProperties(attlist); + } + /** + * Set the name of this element. + * The prepends "fo:" to the name to indicate it is in the fo namespace. + * @param str the xml element name + */ + public void setName(String str) { + name = "fo:" + str; + } + + /** + * Set the location information for this element + * @param locator the org.xml.sax.Locator object + */ + public void setLocation(Locator locator) { if (locator != null) { line = locator.getLineNumber(); column = locator.getColumnNumber(); systemId = locator.getSystemId(); } - - addProperties(attlist); } /** @@ -119,34 +123,44 @@ public class FObj extends FONode implements Constants { */ protected void addProperties(Attributes attlist) throws FOPException { FObj parentFO = findNearestAncestorFObj(); - PropertyList parentPropertyList = null; + PropertyList parentPL = null; + if (parentFO != null) { - parentPropertyList = parentFO.getPropertiesForNamespace(FO_URI); + parentPL = parentFO.getPropertiesForNamespace(FO_URI); } - propertyList = new PropertyList(this, parentPropertyList, FO_URI, - name); + propertyList = new PropertyList(this, parentPL, FO_URI, name); propertyList.addAttributesToList(attlist); - this.propMgr = makePropertyManager(propertyList); + propMgr = new PropertyManager(propertyList); setWritingMode(); } /** - * Set the name of this element. - * The prepends "fo:" to the name to indicate it is in the fo namespace. - * - * @param str the xml element name + * Return the PropertyManager object for this FO. PropertyManager + * tends to hold the traits for this FO, and is primarily used in layout. + * @return the property manager for this FO */ - public void setName(String str) { - name = "fo:" + str; + public PropertyManager getPropertyManager() { + return propMgr; } - public void setLocation(Locator locator) { - if (locator != null) { - line = locator.getLineNumber(); - column = locator.getColumnNumber(); - systemId = locator.getSystemId(); - } + /** + * Return the property list object for this FO. PropertyList tends + * to hold the base, pre-trait properties for this FO, either explicitly + * declared in the input XML or from inherited values. + */ + public PropertyList getPropertyList() { + return propertyList; + } + + /** + * Helper method to quickly obtain the value of a property + * for this FO, without querying for the propertyList first. + * @param name - the name of the desired property to obtain + * @return the property + */ + public Property getProperty(int propId) { + return propertyList.get(propId); } /** @@ -216,15 +230,6 @@ public class FObj extends FONode implements Constants { return this.propertyList; } - /** - * @param propertyList the collection of Property objects to be managed - * @return a PropertyManager for the Property objects - */ - protected PropertyManager makePropertyManager( - PropertyList propertyList) { - return new PropertyManager(propertyList); - } - /* This section is the implemenation of the property context. */ /** @@ -285,57 +290,6 @@ public class FObj extends FONode implements Constants { } } - /** - * lets outside sources access the property list - * first used by PageNumberCitation to find the "id" property - * @param name - the name of the desired property to obtain - * @return the property - */ - public Property getProperty(int propId) { - return propertyList.get(propId); - } - - /** - * Return the "nearest" specified value for the given property. - * Implements the from-nearest-specified-value function. - * @param propertyName The name 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. - */ - public Property getNearestSpecifiedProperty(int propId) { - return propertyList.getNearestSpecified(propId); - } - - /** - * Return the value explicitly specified on this FO. - * @param propertyName The name of the property whose value is desired. - * It may be a compound name, such as space-before.optimum. - * @return The value if the property is explicitly set, otherwise null. - */ - public Property getExplicitProperty(int propId) { - return propertyList.getExplicit(propId); - } - - /** - * Uses the stored writingMode. - * @param absdir an absolute direction (top, bottom, left, right) - * @return the corresponding writing model relative direction name - * for the flow object. - */ - public int getWritingMode(int lrtb, int rltb, int tbrl) { - return propertyList.getWritingMode(lrtb, rltb, tbrl); - } - - - /** - * Uses the stored writingMode. - * @param relativeWritingMode relative direction (start, end, before, after) - * @return the corresponding absolute direction name for the flow object. - */ - public String getAbsoluteWritingMode(int relativeWritingMode) { - return propertyList.getAbsoluteWritingMode(relativeWritingMode); - } - /** * Setup the id for this formatting object. * Most formatting objects can have an id that can be referenced. @@ -486,14 +440,6 @@ public class FObj extends FONode implements Constants { return markers; } - /** - * lets layout managers access FO properties via PropertyManager - * @return the property manager for this FO - */ - public PropertyManager getPropertyManager() { - return this.propMgr; - } - /** * This is a hook for an FOTreeVisitor subclass to be able to access * this object. diff --git a/src/java/org/apache/fop/fo/PropertyManager.java b/src/java/org/apache/fop/fo/PropertyManager.java index 26ce0eedd..a5b1e8333 100644 --- a/src/java/org/apache/fop/fo/PropertyManager.java +++ b/src/java/org/apache/fop/fo/PropertyManager.java @@ -19,6 +19,7 @@ package org.apache.fop.fo; // FOP +import org.apache.fop.apps.FOPException; import org.apache.fop.fonts.Font; import org.apache.fop.fo.properties.Property; import org.apache.fop.fo.properties.CommonBorderAndPadding; @@ -35,6 +36,7 @@ import org.apache.fop.traits.SpaceVal; import org.apache.fop.traits.LayoutProps; // keep, break, span, space? import org.apache.fop.fonts.FontMetrics; import org.apache.fop.fo.properties.CommonHyphenation; +import org.xml.sax.Attributes; /** * Helper class for managing groups of properties. @@ -47,6 +49,7 @@ public class PropertyManager implements Constants { private CommonBorderAndPadding borderAndPadding = null; private CommonHyphenation hyphProps = null; private TextInfo textInfo = null; + private static final String NONE = "none"; private static final int[] SA_BEFORE = new int[] { PR_BORDER_BEFORE_COLOR, PR_BORDER_BEFORE_STYLE, PR_BORDER_BEFORE_WIDTH, PR_PADDING_BEFORE}; @@ -57,14 +60,13 @@ public class PropertyManager implements Constants { private static final int[] SA_END = new int[]{ PR_BORDER_END_COLOR, PR_BORDER_END_STYLE, PR_BORDER_END_WIDTH, PR_PADDING_END}; - private static final String NONE = "none"; - /** * Main constructor - * @param pList property list + * @param propList list of properties for the FO, initialized + * from the attributes in the input source document */ - public PropertyManager(PropertyList pList) { - this.propertyList = pList; + public PropertyManager(PropertyList propList) { + propertyList = propList; } /** diff --git a/src/java/org/apache/fop/fo/pagination/RegionBody.java b/src/java/org/apache/fop/fo/pagination/RegionBody.java index cb7de1642..797889271 100644 --- a/src/java/org/apache/fop/fo/pagination/RegionBody.java +++ b/src/java/org/apache/fop/fo/pagination/RegionBody.java @@ -79,7 +79,7 @@ public class RegionBody extends Region { private int getRelMargin(int reldir, int relPropId) { FObj parent = (FObj) getParent(); String sPropName = "margin-" - + parent.getAbsoluteWritingMode(reldir); + + parent.getPropertyList().getAbsoluteWritingMode(reldir); int propId = FOPropertyMapping.getPropertyId(sPropName); Property prop = propertyList.getExplicitOrShorthand(propId); if (prop == null) { diff --git a/src/java/org/apache/fop/fo/properties/PropertyMaker.java b/src/java/org/apache/fop/fo/properties/PropertyMaker.java index f11020fb4..53b58c12e 100644 --- a/src/java/org/apache/fop/fo/properties/PropertyMaker.java +++ b/src/java/org/apache/fop/fo/properties/PropertyMaker.java @@ -372,7 +372,7 @@ public class PropertyMaker implements Cloneable { * @return The initialized Property object. * @throws FOPException for invalid or inconsistent FO input */ - public Property make(PropertyList propertyList, String value, + public Property make(PropertyList propertyList, String value, FObj fo) throws FOPException { try { Property newProp = null; @@ -383,7 +383,7 @@ public class PropertyMaker implements Cloneable { newProp = checkEnumValues(value); } if (newProp == null) { - /* Check for keyword shorthand values to be substituted. */ + // Check for keyword shorthand values to be substituted. pvalue = checkValueKeywords(value); // Override parsePropertyValue in each subclass of Property.Maker Property p = PropertyParser.parse(pvalue, diff --git a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java index a10748500..345e1c743 100644 --- a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java @@ -34,6 +34,7 @@ import org.apache.fop.fo.properties.NumberProperty; import org.apache.fop.fo.properties.Property; import org.apache.fop.fo.Constants; import org.apache.fop.fo.FObj; +import org.apache.fop.fo.PropertyList; import org.apache.fop.datatypes.ColorType; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes; @@ -115,7 +116,9 @@ public class TableAttributesConverter { Property p; EnumProperty ep; RtfColorTable colorTable = RtfColorTable.getInstance(); - + PropertyList propList = fobj.getPropertyList(); + + RtfAttributes attrib = null; attrib = new RtfAttributes(); @@ -123,7 +126,8 @@ public class TableAttributesConverter { boolean isBorderPresent = false; // Cell background color - if ((p = fobj.getNearestSpecifiedProperty(Constants.PR_BACKGROUND_COLOR)) != null) { + if ((p = propList.getNearestSpecified( + Constants.PR_BACKGROUND_COLOR)) != null) { ColorType color = p.getColorType(); if (color != null) { if (color.getAlpha() != 0 @@ -141,7 +145,7 @@ public class TableAttributesConverter { } // Cell borders : - if ((p = fobj.getExplicitProperty(Constants.PR_BORDER_COLOR)) != null) { + if ((p = propList.getExplicit(Constants.PR_BORDER_COLOR)) != null) { ListProperty listprop = (ListProperty) p; ColorType color = null; if (listprop.getList().get(0) instanceof NCnameProperty) { @@ -155,28 +159,29 @@ public class TableAttributesConverter { colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(), (int)color.getBlue()).intValue()); } - if ((p = fobj.getExplicitProperty(Constants.PR_BORDER_TOP_COLOR)) != null) { + if ((p = propList.getExplicit( + Constants.PR_BORDER_TOP_COLOR)) != null) { ColorType color = p.getColorType(); attrib.set( BorderAttributesConverter.BORDER_COLOR, colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(), (int)color.getBlue()).intValue()); } - if ((p = fobj.getExplicitProperty(Constants.PR_BORDER_BOTTOM_COLOR)) != null) { + if ((p = propList.getExplicit(Constants.PR_BORDER_BOTTOM_COLOR)) != null) { ColorType color = p.getColorType(); attrib.set( BorderAttributesConverter.BORDER_COLOR, colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(), (int)color.getBlue()).intValue()); } - if ((p = fobj.getExplicitProperty(Constants.PR_BORDER_LEFT_COLOR)) != null) { + if ((p = propList.getExplicit(Constants.PR_BORDER_LEFT_COLOR)) != null) { ColorType color = p.getColorType(); attrib.set( BorderAttributesConverter.BORDER_COLOR, colorTable.getColorNumber((int)color.getRed(), (int)color.getGreen(), (int)color.getBlue()).intValue()); } - if ((p = fobj.getExplicitProperty(Constants.PR_BORDER_RIGHT_COLOR)) != null) { + if ((p = propList.getExplicit(Constants.PR_BORDER_RIGHT_COLOR)) != null) { ColorType color = p.getColorType(); attrib.set( BorderAttributesConverter.BORDER_COLOR, -- 2.39.5