From e01b2f6990807ca1ffa657ef835fa82fb76d182a Mon Sep 17 00:00:00 2001 From: Karen Lease Date: Sat, 16 Dec 2000 21:53:19 +0000 Subject: [PATCH] Modify to improve handling of compound properties git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193878 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/fo/FObj.java | 30 +++++------ src/org/apache/fop/fo/LengthProperty.java | 3 +- .../apache/fop/fo/LengthRangeProperty.java | 8 --- src/org/apache/fop/fo/Property.java | 26 ++++++---- src/org/apache/fop/fo/PropertyList.java | 52 +++++++++++++------ .../apache/fop/fo/PropertyListBuilder.java | 12 ++--- src/org/apache/fop/fo/SpaceProperty.java | 9 ---- 7 files changed, 74 insertions(+), 66 deletions(-) diff --git a/src/org/apache/fop/fo/FObj.java b/src/org/apache/fop/fo/FObj.java index 221c25e27..2e396c220 100644 --- a/src/org/apache/fop/fo/FObj.java +++ b/src/org/apache/fop/fo/FObj.java @@ -84,6 +84,7 @@ public class FObj extends FONode { protected FObj(FObj parent, PropertyList propertyList) { super(parent); this.properties = propertyList; + propertyList.setFObj(this); this.name = "default FO"; } @@ -142,29 +143,18 @@ public class FObj extends FONode { return(properties.get(name)); } + /** - * Return the width of the containing area for this FO's areas. + * Return the "content width" of the areas generated by this FO. * This is used by percent-based properties to get the dimension of * the containing block. * If an FO has a property with a percentage value, that value - * is usually calculated on the basis of the corresponding dimenions - * of the block which contains areas generated by the FO. - * Implementation note: if this block has an FObj parent, this method - * returns the value of getContentWidth() on that FObj. Normally subclasses - * will override getContentWidth and not getContainingWidth(). + * is usually calculated on the basis of the corresponding dimension + * of the area which contains areas generated by the FO. + * NOTE: subclasses of FObj should implement this to return a reasonable + * value! */ - public int getContainingWidth() { - FObj parent = getParent(); - if (parent != null) - return parent.getContentWidth(); - else return 0; // no parent, top level box - } - - /** - * Return the "content width" of the areas generated by this FO. - * NOTE: subclasses of FObj should implement this! - */ - protected int getContentWidth() { + public int getContentWidth() { return 0; } @@ -186,5 +176,9 @@ public class FObj extends FONode { } } + public boolean generatesReferenceAreas() { + return false; + } + } diff --git a/src/org/apache/fop/fo/LengthProperty.java b/src/org/apache/fop/fo/LengthProperty.java index 24866c449..2234b59dd 100644 --- a/src/org/apache/fop/fo/LengthProperty.java +++ b/src/org/apache/fop/fo/LengthProperty.java @@ -54,6 +54,7 @@ import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.PercentLength; import org.apache.fop.datatypes.TableColLength; import org.apache.fop.fo.expr.Numeric; +import org.apache.fop.apps.FOPException; public class LengthProperty extends Property { @@ -77,7 +78,7 @@ public class LengthProperty extends Property { } protected Property convertProperty(Property p, PropertyList propertyList, - FObj fo) { + FObj fo) throws FOPException { if (isAutoLengthAllowed()) { String pval = p.getString(); if (pval != null && pval.equals("auto")) diff --git a/src/org/apache/fop/fo/LengthRangeProperty.java b/src/org/apache/fop/fo/LengthRangeProperty.java index 31a495d57..b5aa7af04 100644 --- a/src/org/apache/fop/fo/LengthRangeProperty.java +++ b/src/org/apache/fop/fo/LengthRangeProperty.java @@ -60,14 +60,6 @@ public class LengthRangeProperty extends Property { protected Maker(String name) { super(name); } - - protected Property convertProperty(Property p, PropertyList propertyList, - FObj fo) { - Length val = p.getLength(); - if (val != null) - return new LengthRangeProperty(new LengthRange(val)); - return convertPropertyDatatype(p, propertyList, fo); - } } private LengthRange lengthRange ; diff --git a/src/org/apache/fop/fo/Property.java b/src/org/apache/fop/fo/Property.java index 90394a9d5..c397f09bf 100644 --- a/src/org/apache/fop/fo/Property.java +++ b/src/org/apache/fop/fo/Property.java @@ -100,6 +100,7 @@ public class Property { */ public boolean inheritsSpecified() { return false; } + /** * Return an object implementing the PercentBase interface. * This is used to handle properties specified as a percentage of @@ -157,6 +158,9 @@ public class Property { PropertyList propertyList, String value, FObj fo) throws FOPException { + if (baseProp==null) { + baseProp = makeCompound(propertyList, fo); + } Maker spMaker = getSubpropMaker(partName); if (spMaker != null) { Property p = spMaker.make(propertyList, value, fo); @@ -189,7 +193,6 @@ public class Property { return baseProp; } - /** * Create a Property object from an attribute specification. * @param propertyList The PropertyList object being built for this FO. @@ -252,7 +255,7 @@ public class Property { * can't be converted to the correct type. */ protected Property convertProperty(Property p, - PropertyList propertyList, FObj fo) { + PropertyList propertyList, FObj fo) throws FOPException { return null; } @@ -266,17 +269,17 @@ public class Property { * @param propertyList The PropertyList object being built for this FO. */ public Property make(PropertyList propertyList) throws FOPException { - return make(propertyList, false); + return null; } /** * Return a Property object representing the initial value. * @param propertyList The PropertyList object being built for this FO. - * @param bForceNew A boolean value indicating whether a new Property - * object must be constructed or whether a reference to the - * default Property object may be returned. + * @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. */ - public Property make(PropertyList propertyList, boolean bForceNew) throws FOPException { + protected Property makeCompound(PropertyList propertyList, FObj parentFO) throws FOPException { return null; } @@ -299,9 +302,8 @@ public class Property { // Only need to do this if the value is relative!!! String specVal = specProp.getSpecifiedValue(); if (specVal != null) { - // SHOULD HAVE FO!!! get from PropertyList ? try { - return make(propertyList, specVal, null); + return make(propertyList, specVal, propertyList.getParentFObj()); } catch (FOPException e) { MessageHandler.errorln("Error computing property value for " + propName + " from " + specVal); @@ -340,8 +342,14 @@ public class Property { */ public Length getLength() { return null; } public ColorType getColorType() { return null; } + public CondLength getCondLength() { return null; } public LengthRange getLengthRange() { return null; } public Space getSpace() { return null; } + /* KL: first decide which direction to go with this! + public Keep getKeep() { return null; } + public KeepValue getKeepValue() { return null; } + public Precedence getPrecedence() { return null; } + */ public int getEnum() { return 0; } public char getCharacter() { return 0;} diff --git a/src/org/apache/fop/fo/PropertyList.java b/src/org/apache/fop/fo/PropertyList.java index 54ca49138..6838960c6 100644 --- a/src/org/apache/fop/fo/PropertyList.java +++ b/src/org/apache/fop/fo/PropertyList.java @@ -60,6 +60,7 @@ public class PropertyList extends Hashtable { private PropertyList parentPropertyList = null; String namespace = ""; String element = ""; + FObj fobj=null; public PropertyList(PropertyList parentPropertyList, String space, String el) { this.parentPropertyList = parentPropertyList; @@ -67,6 +68,21 @@ public class PropertyList extends Hashtable { this.element = el; } + public void setFObj(FObj fobj) { + this.fobj = fobj; + } + + public FObj getFObj() { + return this.fobj; + } + + public FObj getParentFObj() { + if (parentPropertyList != null) { + return parentPropertyList.getFObj(); + } + else return null; + } + /** * Return the value explicitly specified on this FO. * @param propertyName The name of the property whose value is desired. @@ -102,6 +118,21 @@ public class PropertyList extends Hashtable { return null; // No builder or exception in makeProperty! } + private Property findProperty(String propertyName) { + Property p = getExplicit(propertyName); + if (p == null) { + p = this.builder.computeProperty(this,namespace, element, propertyName); + } + if (p == null) { // else inherit (if has parent and is inheritable) + if (this.parentPropertyList != null && + builder.isInherited(namespace, element, propertyName)) { + p = parentPropertyList.findProperty(propertyName); + } + } + return p; + } + + /** * Return the property on the current FlowObject. If it isn't set explicitly, * this will try to compute it based on other properties, or if it is @@ -121,21 +152,12 @@ public class PropertyList extends Hashtable { propertyName = propertyName.substring(0,sepchar); } - Property p = getExplicit(propertyName); - - if (p == null) { // if not explicit - p = this.builder.computeProperty(this,namespace, element, propertyName); - if (p == null) { // else inherit (if has parent and is inheritable) - if ((this.parentPropertyList != null) && - (this.builder.isInherited(namespace, element, propertyName))) { - p = this.parentPropertyList.get(propertyName); // retrieve parent's value - } else { // default value - try { - p = this.builder.makeProperty(this,namespace, element,propertyName); - } catch (FOPException e) { - // don't know what to do here - } - } + Property p = findProperty(propertyName); + if (p == null) { // default value for this FO! + try { + p = this.builder.makeProperty(this,namespace, element,propertyName); + } catch (FOPException e) { + // don't know what to do here } } if (subpropName != null) { diff --git a/src/org/apache/fop/fo/PropertyListBuilder.java b/src/org/apache/fop/fo/PropertyListBuilder.java index d3c067fc0..e8f1ed214 100644 --- a/src/org/apache/fop/fo/PropertyListBuilder.java +++ b/src/org/apache/fop/fo/PropertyListBuilder.java @@ -110,7 +110,7 @@ public class PropertyListBuilder { return b; } - public PropertyList makeList(String elementName, Attributes attributes, PropertyList parentPropertyList, FObj fo) throws FOPException { + public PropertyList makeList(String elementName, Attributes attributes, PropertyList parentPropertyList, FObj parentFO) throws FOPException { int index = elementName.indexOf("^"); String space = "http://www.w3.org/TR/1999/XSL/Format"; if(index != -1) { @@ -141,7 +141,7 @@ public class PropertyListBuilder { Property.Maker propertyMaker = findMaker(table, FONTSIZEATTR); if (propertyMaker != null) { try { - p.put(FONTSIZEATTR, propertyMaker.make(p,fontsizeval,fo)); + p.put(FONTSIZEATTR, propertyMaker.make(p,fontsizeval,parentFO)); } catch (FOPException e) { } } // Put in the "done" list even if error or no Maker. @@ -175,16 +175,16 @@ public class PropertyListBuilder { // See if it is specified later in this list String baseValue = attributes.getValue(propName); if (baseValue != null) { - baseProp = propertyMaker.make(p, baseValue,fo); + baseProp = propertyMaker.make(p, baseValue, parentFO); propsDone.append(propName + ' '); } - else baseProp = propertyMaker.make(p, true); //default + //else baseProp = propertyMaker.makeCompound(p, parentFO); } propVal = propertyMaker.make(baseProp, subpropName, p, - attributes.getValue(i),fo); + attributes.getValue(i),parentFO); } else { - propVal = propertyMaker.make(p,attributes.getValue(i),fo); + propVal = propertyMaker.make(p,attributes.getValue(i),parentFO); } if (propVal != null) { p.put(propName,propVal); diff --git a/src/org/apache/fop/fo/SpaceProperty.java b/src/org/apache/fop/fo/SpaceProperty.java index b92b49b57..4235dfccc 100644 --- a/src/org/apache/fop/fo/SpaceProperty.java +++ b/src/org/apache/fop/fo/SpaceProperty.java @@ -57,18 +57,9 @@ import org.apache.fop.datatypes.LengthRange; public class SpaceProperty extends Property { public static class Maker extends LengthRangeProperty.Maker { - protected Maker(String name) { super(name); } - - protected Property convertProperty(Property p, PropertyList propertyList, - FObj fo) { - Length val = p.getLength(); - if (val != null) - return new SpaceProperty(new Space(val)); - return convertPropertyDatatype(p, propertyList, fo); - } } private Space space ; -- 2.39.5