From: Karen Lease Date: Fri, 10 Nov 2000 22:11:04 +0000 (+0000) Subject: PropertyListBuilder.java X-Git-Tag: pre-columns~115 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1819a8cd168a69c708a1f15e46e5dce6787e6e76;p=xmlgraphics-fop.git PropertyListBuilder.java git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193771 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/fo/PropertyListBuilder.java b/src/org/apache/fop/fo/PropertyListBuilder.java index 820b74b8a..b625d6720 100644 --- a/src/org/apache/fop/fo/PropertyListBuilder.java +++ b/src/org/apache/fop/fo/PropertyListBuilder.java @@ -64,13 +64,16 @@ import java.util.Hashtable; 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) { @@ -107,7 +110,7 @@ public class PropertyListBuilder { 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) { @@ -123,17 +126,64 @@ public class PropertyListBuilder { 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"); } @@ -141,7 +191,17 @@ public class PropertyListBuilder { 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; @@ -157,15 +217,27 @@ public class PropertyListBuilder { 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; + } + } diff --git a/src/org/apache/fop/fo/StandardPropertyListMapping.java b/src/org/apache/fop/fo/StandardPropertyListMapping.java index 547309c43..cb29642bb 100644 --- a/src/org/apache/fop/fo/StandardPropertyListMapping.java +++ b/src/org/apache/fop/fo/StandardPropertyListMapping.java @@ -51,8 +51,9 @@ 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 { @@ -60,112 +61,15 @@ 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); } } diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index 866a6553a..6c80aea6e 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -351,4 +351,14 @@ public class Block extends FObjMixed { public int getAreaHeight() { return blockArea.getHeight(); } + + + /** + * Return the content width of the boxes generated by this FO. + */ + protected int getContentWidth() { + if (blockArea != null) + return blockArea.getContentWidth(); //getAllocationWidth()?? + else return 0; // not laid out yet + } } diff --git a/src/org/apache/fop/fo/flow/BlockContainer.java b/src/org/apache/fop/fo/flow/BlockContainer.java index a38e7ddc4..04bbdad1e 100644 --- a/src/org/apache/fop/fo/flow/BlockContainer.java +++ b/src/org/apache/fop/fo/flow/BlockContainer.java @@ -272,4 +272,14 @@ public class BlockContainer extends FObj { return new Status(Status.OK); } + + /** + * Return the content width of the boxes generated by this block + * container FO. + */ + protected int getContentWidth() { + if (areaContainer != null) + return areaContainer.getContentWidth(); //getAllocationWidth()?? + else return 0; // not laid out yet + } } diff --git a/src/org/apache/fop/fo/flow/Flow.java b/src/org/apache/fop/fo/flow/Flow.java index 3d68ef470..58ddefa9d 100644 --- a/src/org/apache/fop/fo/flow/Flow.java +++ b/src/org/apache/fop/fo/flow/Flow.java @@ -76,6 +76,7 @@ public class Flow extends FObj { } PageSequence pageSequence; + private Area area; // Area in which we lay out our kids protected Flow(FObj parent, PropertyList propertyList) throws FOPException { @@ -96,7 +97,7 @@ public class Flow extends FObj { if (this.marker == START) { this.marker = 0; } - + this.area = area; boolean prevChildMustKeepWithNext = false; int numChildren = this.children.size(); @@ -128,4 +129,14 @@ public class Flow extends FObj { } return new Status(Status.OK); } + + /** + * Return the content width of this flow (really of the region + * in which it is flowing). + */ + protected int getContentWidth() { + if (area != null) + return area.getContentWidth(); //getAllocationWidth()?? + else return 0; // not laid out yet + } } diff --git a/src/org/apache/fop/fo/flow/Table.java b/src/org/apache/fop/fo/flow/Table.java index 1da227493..89595d02f 100644 --- a/src/org/apache/fop/fo/flow/Table.java +++ b/src/org/apache/fop/fo/flow/Table.java @@ -272,4 +272,14 @@ public class Table extends FObj { public int getAreaHeight() { return areaContainer.getHeight(); } + + /** + * Return the content width of the boxes generated by this table FO. + */ + protected int getContentWidth() { + if (areaContainer != null) + return areaContainer.getContentWidth(); //getAllocationWidth()?? + else return 0; // not laid out yet + } + } diff --git a/src/org/apache/fop/fo/pagination/PageSequence.java b/src/org/apache/fop/fo/pagination/PageSequence.java index da51a47cd..381d52d9f 100644 --- a/src/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/org/apache/fop/fo/pagination/PageSequence.java @@ -122,8 +122,10 @@ public class PageSequence extends FObj layoutMasterSet = root.getLayoutMasterSet(); thisIsFirstPage=true; // we are now on the first page of the page sequence + /* InitialPageNumber ipn = (InitialPageNumber) this.properties.get("initial-page-number"); - String ipnValue=ipn.getString(); + */ + String ipnValue= this.properties.get("initial-page-number").getString(); if ( ipnValue.equals("auto") ) { @@ -151,7 +153,8 @@ public class PageSequence extends FObj } } - masterName = ((MasterName) this.properties.get("master-name")).getString(); + // masterName = ((MasterName) this.properties.get("master-name")).getString(); + masterName = this.properties.get("master-name").getString(); } protected Page makePage(AreaTree areaTree) throws FOPException {