]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
PropertyListBuilder.java
authorKaren Lease <klease@apache.org>
Fri, 10 Nov 2000 22:11:04 +0000 (22:11 +0000)
committerKaren Lease <klease@apache.org>
Fri, 10 Nov 2000 22:11:04 +0000 (22:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193771 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/fo/PropertyListBuilder.java
src/org/apache/fop/fo/StandardPropertyListMapping.java
src/org/apache/fop/fo/flow/Block.java
src/org/apache/fop/fo/flow/BlockContainer.java
src/org/apache/fop/fo/flow/Flow.java
src/org/apache/fop/fo/flow/Table.java
src/org/apache/fop/fo/pagination/PageSequence.java

index 820b74b8abd0699b8982d228f2b67e679d5a6ada..b625d67201af293ba5c1d2f5ed35d6ecdcbcc8d4 100644 (file)
@@ -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;
+  }
+
 }
index 547309c43d9c4ab6f7a992895a4c0e4175b88408..cb29642bbdb84ea75ba40483538f90d875a93243 100644 (file)
@@ -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); 
     }
 }
index 866a6553a1443001bd674d6110de0fa57a437006..6c80aea6e04d8612b89681d2f3ed7e914bb828e4 100644 (file)
@@ -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
+  }
 }
index a38e7ddc47f278a9a85142119005bc2904c32907..04bbdad1edd86143c9406aab00eccd3e60c1a213 100644 (file)
@@ -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
+  }
 }
index 3d68ef470de77a8d97e7e5684f105a70883343b6..58ddefa9d602f393f2a09d0d6a1642777b268176 100644 (file)
@@ -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
+  }
 }
index 1da2274932974f6da1f44b7d95fbf0ad6fd59b9f..89595d02f3d84c4832e9bf27b443b67c275fc17f 100644 (file)
@@ -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
+  }
+
 }
index da51a47cddbec8b8dec6b4d48bbb9dfb9683b154..381d52d9f519cae275bbfbf7ea392bc24c195c76 100644 (file)
@@ -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 {