public class PropertyListBuilder {
+ /** Name of font-size property attribute to set first. */
+ private static final String FONTSIZEATTR = "font-size";
+
private Hashtable propertyListTable;
- private Hashtable elementTable;
+ private Hashtable elementTable;
public PropertyListBuilder() {
this.propertyListTable = new Hashtable();
this.elementTable = new Hashtable();
- }
+ }
public void addList(Hashtable list)
{
return b;
}
- public PropertyList makeList(String elementName, Attributes attributes, PropertyList parentPropertyList) throws FOPException {
+ public PropertyList makeList(String elementName, Attributes attributes, PropertyList parentPropertyList, FObj fo) throws FOPException {
int index = elementName.indexOf("^");
String space = "http://www.w3.org/TR/1999/XSL/Format";
if(index != -1) {
p.setBuilder(this);
Hashtable table;
table = (Hashtable)elementTable.get(elementName.substring(index + 1));
+
+ /* Store names of properties already set. */
+ StringBuffer propsDone = new StringBuffer(256);
+ propsDone.append(' ');
+
+ /* If font-size is set on this FO, must set it first, since
+ * other attributes specified in terms of "ems" depend on it.
+ * When we do "shorthand" properties, must handle the "font"
+ * property as well to see if font-size is set.
+ */
+ String fontsizeval=attributes.getValue(FONTSIZEATTR);
+ if (fontsizeval != null) {
+ // get a Property.Maker
+ Property.Maker propertyMaker = findMaker(table, FONTSIZEATTR);
+ if (propertyMaker != null) {
+ p.put(FONTSIZEATTR, propertyMaker.make(p,fontsizeval,fo));
+ propsDone.append(FONTSIZEATTR + ' ');
+ }
+ }
+
for (int i = 0; i < attributes.getLength(); i++) {
String attributeName = attributes.getQName(i);
- Property.Maker propertyMaker = null;
- if(table != null) {
- propertyMaker = (Property.Maker)table.get(attributeName);
+ /* Handle "compound" properties, ex. space-before.minimum */
+ int sepchar = attributeName.indexOf('.');
+ String propName = attributeName;
+ String subpropName = null;
+ Property propVal = null;
+ if (sepchar > -1) {
+ propName = attributeName.substring(0,sepchar);
+ subpropName = attributeName.substring(sepchar+1);
}
- if(propertyMaker == null) {
- propertyMaker = (Property.Maker)propertyListTable.get(attributeName);
+ else if (propsDone.toString().indexOf(' '+propName+' ') != -1) {
+ // Already processed this property (base property
+ // for a property with sub-components or font-size)
+ continue;
}
+
+ Property.Maker propertyMaker =findMaker(table, propName);
+
if (propertyMaker != null) {
- p.put(attributeName,propertyMaker.make(p,attributes.getValue(i)));
+ if (subpropName != null) {
+ Property baseProp = p.getExplicit(propName);
+ if (baseProp == null) {
+ // See if it is specified later in this list
+ String baseValue = attributes.getValue(propName);
+ if (baseValue != null) {
+ baseProp = propertyMaker.make(p, baseValue,fo);
+ propsDone.append(propName + ' ');
+ }
+ else baseProp = propertyMaker.make(p, true); //default
+ }
+ propVal = propertyMaker.make(baseProp, subpropName, p,
+ attributes.getValue(i),fo);
+ }
+ else {
+ propVal = propertyMaker.make(p,attributes.getValue(i),fo);
+ }
+ p.put(propName,propVal);
} else {
//MessageHandler.errorln("WARNING: property " + attributeName + " ignored");
}
return p;
}
-
+
+ public Property getSubpropValue(String space, String element,
+ String propertyName, Property p,
+ String subpropName) {
+ Property.Maker maker = findMaker(space, element, propertyName);
+ if (maker != null) {
+ return maker.getSubpropValue(p, subpropName);
+ }
+ else return null;
+ }
+
public Property makeProperty(PropertyList propertyList, String space, String element, String propertyName) throws FOPException {
Property p = null;
protected Property.Maker findMaker(String space, String elementName, String propertyName)
{
- Hashtable propertyTable;
- Property.Maker propertyMaker = null;
- propertyTable = (Hashtable)elementTable.get(elementName);
- if(propertyTable != null) {
- propertyMaker = (Property.Maker)propertyTable.get(propertyName);
- }
- if(propertyMaker == null) {
- propertyMaker = (Property.Maker)propertyListTable.get(propertyName);
- }
- return propertyMaker;
+ return findMaker((Hashtable)elementTable.get(elementName),
+ propertyName);
}
+
+ /**
+ * Convenience function to return the Maker for a given property
+ * given the Hashtable containing properties specific to this element.
+ * If table is non-null and
+ * @param elemTable Element-specific properties or null if none.
+ * @param propertyName Name of property.
+ * @return A Maker for this property.
+ */
+ private Property.Maker findMaker(Hashtable elemTable, String propertyName) {
+ Property.Maker propertyMaker = null;
+ if (elemTable != null) {
+ propertyMaker = (Property.Maker)elemTable.get(propertyName);
+ }
+ if (propertyMaker == null) {
+ propertyMaker = (Property.Maker)propertyListTable.get(propertyName);
+ }
+ return propertyMaker;
+ }
+
}
package org.apache.fop.fo;
-import org.apache.fop.fo.properties.*;
+import org.apache.fop.fo.properties.FOPropertyMapping;
+import java.util.Enumeration;
import java.util.Hashtable;
public class StandardPropertyListMapping implements PropertyListMapping {
public void addToBuilder(TreeBuilder builder) {
String uri = "http://www.w3.org/1999/XSL/Format";
- Hashtable propertyTable = new Hashtable();
- propertyTable.put("end-indent",EndIndent.maker());
- propertyTable.put("master-name",MasterName.maker());
- propertyTable.put("page-master-first",PageMasterFirst.maker());
- propertyTable.put("page-master-repeating",PageMasterRepeating.maker());
- propertyTable.put("page-master-odd",PageMasterOdd.maker());
- propertyTable.put("page-master-even",PageMasterEven.maker());
- propertyTable.put("margin-top",MarginTop.maker());
- propertyTable.put("margin-bottom",MarginBottom.maker());
- propertyTable.put("margin-left",MarginLeft.maker());
- propertyTable.put("margin-right",MarginRight.maker());
- propertyTable.put("extent",Extent.maker());
- propertyTable.put("page-width",PageWidth.maker());
- propertyTable.put("page-height",PageHeight.maker());
- propertyTable.put("flow-name",FlowName.maker());
- propertyTable.put("font-family",FontFamily.maker());
- propertyTable.put("font-style",FontStyle.maker());
- propertyTable.put("font-weight",FontWeight.maker());
- propertyTable.put("font-size",FontSize.maker());
- propertyTable.put("line-height",LineHeight.maker());
- propertyTable.put("text-align",TextAlign.maker());
- propertyTable.put("text-align-last",TextAlignLast.maker());
- propertyTable.put("space-before.optimum",SpaceBeforeOptimum.maker());
- propertyTable.put("space-after.optimum",SpaceAfterOptimum.maker());
- propertyTable.put("start-indent",StartIndent.maker());
- propertyTable.put("end-indent",EndIndent.maker());
- propertyTable.put("provisional-distance-between-starts",ProvisionalDistanceBetweenStarts.maker());
- propertyTable.put("provisional-label-separation",ProvisionalLabelSeparation.maker());
- propertyTable.put("rule-thickness",RuleThickness.maker());
- propertyTable.put("color",Color.maker());
- propertyTable.put("wrap-option",WrapOption.maker());
- propertyTable.put("white-space-treatment",WhiteSpaceTreatment.maker());
- propertyTable.put("break-before",BreakBefore.maker());
- propertyTable.put("break-after",BreakAfter.maker());
- propertyTable.put("text-indent",TextIndent.maker());
- propertyTable.put("src",Src.maker());
- propertyTable.put("column-width",ColumnWidth.maker());
- propertyTable.put("keep-with-next",KeepWithNext.maker());
- propertyTable.put("background-color",BackgroundColor.maker());
- propertyTable.put("padding-top",PaddingTop.maker());
- propertyTable.put("padding-bottom",PaddingBottom.maker());
- propertyTable.put("padding-left",PaddingLeft.maker());
- propertyTable.put("padding-right",PaddingRight.maker());
- propertyTable.put("external-destination",ExternalDestination.maker());
- propertyTable.put("internal-destination",InternalDestination.maker());
+ builder.addPropertyList(uri, FOPropertyMapping.getGenericMappings());
+ /* Add any element mappings */
+ for (Enumeration e = FOPropertyMapping.getElementMappings();
+ e.hasMoreElements();) {
+ String elem = (String)e.nextElement();
+ builder.addElementPropertyList(uri, elem,
+ FOPropertyMapping.getElementMapping(elem));
+ }
- propertyTable.put("border-after-color",BorderAfterColor.maker());
- propertyTable.put("border-after-style",BorderAfterStyle.maker());
- propertyTable.put("border-after-width",BorderAfterWidth.maker());
- propertyTable.put("border-before-color",BorderBeforeColor.maker());
- propertyTable.put("border-before-style",BorderBeforeStyle.maker());
- propertyTable.put("border-before-width",BorderBeforeWidth.maker());
- propertyTable.put("border-bottom",BorderBottom.maker());
- propertyTable.put("border-bottom-color",BorderBottomColor.maker());
- propertyTable.put("border-bottom-style",BorderBottomStyle.maker());
- propertyTable.put("border-bottom-width",BorderBottomWidth.maker());
- propertyTable.put("border-color",BorderColor.maker());
- propertyTable.put("border-end-color",BorderEndColor.maker());
- propertyTable.put("border-end-style",BorderEndStyle.maker());
- propertyTable.put("border-end-width",BorderEndWidth.maker());
- propertyTable.put("border-left",BorderLeft.maker());
- propertyTable.put("border-left-color",BorderLeftColor.maker());
- propertyTable.put("border-left-style",BorderLeftStyle.maker());
- propertyTable.put("border-left-width",BorderLeftWidth.maker());
- propertyTable.put("border-right",BorderRight.maker());
- propertyTable.put("border-right-color",BorderRightColor.maker());
- propertyTable.put("border-right-style",BorderRightStyle.maker());
- propertyTable.put("border-right-width",BorderRightWidth.maker());
- propertyTable.put("border-start-color",BorderStartColor.maker());
- propertyTable.put("border-start-style",BorderStartStyle.maker());
- propertyTable.put("border-start-width",BorderStartWidth.maker());
- propertyTable.put("border-style",BorderStyle.maker());
- propertyTable.put("border-top",BorderTop.maker());
- propertyTable.put("border-top-color",BorderTopColor.maker());
- propertyTable.put("border-top-style",BorderTopStyle.maker());
- propertyTable.put("border-top-width",BorderTopWidth.maker());
- propertyTable.put("border-width",BorderWidth.maker());
- propertyTable.put("bottom",Bottom.maker());
- propertyTable.put("height",Height.maker());
- propertyTable.put("left",Left.maker());
- propertyTable.put("padding",Padding.maker());
- propertyTable.put("padding-after",PaddingAfter.maker());
- propertyTable.put("padding-before",PaddingBefore.maker());
- propertyTable.put("padding-end",PaddingEnd.maker());
- propertyTable.put("padding-start",PaddingStart.maker());
- propertyTable.put("position",Position.maker());
- propertyTable.put("right",Right.maker());
- propertyTable.put("top",Top.maker());
- propertyTable.put("width",Width.maker());
- propertyTable.put("initial-page-number",InitialPageNumber.maker());
- propertyTable.put("ref-id",RefId.maker()); // used by page-number-citation
- propertyTable.put("id",Id.maker()); // attribute for objects, used by page-number-citation
- propertyTable.put("maximum-repeats",MaximumRepeats.maker());
- propertyTable.put("page-position",PagePosition.maker());
- propertyTable.put("odd-or-even",OddOrEven.maker());
- propertyTable.put("blank-or-not-blank",BlankOrNotBlank.maker());
- propertyTable.put("content-width",ContentWidth.maker());
- propertyTable.put("content-height",ContentHeight.maker());
- propertyTable.put("leader-pattern",LeaderPattern.maker());
- propertyTable.put("leader-length",LeaderLength.maker());
- propertyTable.put("rule-style",RuleStyle.maker());
- propertyTable.put("scaling",Scaling.maker());
- propertyTable.put("vertical-align",VerticalAlign.maker());
- propertyTable.put("overflow",Overflow.maker());
- propertyTable.put("text-decoration",TextDecoration.maker());
- builder.addPropertyList(uri, propertyTable);
}
}