]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
1. tie Document to fo.FOTreeBuilder and fo.pagination.Root
authorWilliam Victor Mote <vmote@apache.org>
Sat, 16 Aug 2003 06:43:51 +0000 (06:43 +0000)
committerWilliam Victor Mote <vmote@apache.org>
Sat, 16 Aug 2003 06:43:51 +0000 (06:43 +0000)
2. add getDocument() method to FONode (using this.parent for all nodes except Root)
3. start using getDocument() to gain access to font collections stored in Document

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196808 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/apps/Driver.java
src/java/org/apache/fop/fo/FONode.java
src/java/org/apache/fop/fo/FOTreeBuilder.java
src/java/org/apache/fop/fo/FObjMixed.java
src/java/org/apache/fop/fo/PropertyManager.java
src/java/org/apache/fop/fo/XMLObj.java
src/java/org/apache/fop/fo/flow/InstreamForeignObject.java
src/java/org/apache/fop/fo/pagination/Root.java

index 86156f326ba227ee2ecedfc61ac41d88d8598d42..198e6303eaded010905c0e6189c915a727de7ec0 100644 (file)
@@ -601,6 +601,7 @@ public class Driver implements LogEnabled, FOTreeListener {
         if (foInputHandler instanceof FOTreeHandler) {
             currentDocument.setLayoutStrategy(new LayoutManagerLS());
         }
+        treeBuilder.document = currentDocument;
         try {
             if (foInputHandler instanceof FOTreeHandler) {
                 FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler;
index 60969030c0287971eab0d1e9493324ada2c22eea..e51744f67ba99026a97b0e8c2b74e782034cd6ed 100644 (file)
@@ -61,6 +61,7 @@ import org.apache.avalon.framework.logger.Logger;
 
 // FOP
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.control.Document;
 import org.apache.fop.util.CharUtilities;
 
 /**
@@ -209,5 +210,10 @@ public abstract class FONode {
     protected boolean isMarker() {
         return false;
     }
+
+    public Document getDocument() {
+        return parent.getDocument();
+    }
+
 }
 
index bb50b23be48d5161a71c39d8c730f371c8717f97..1af4d795fd83c038ad0afe25ea3c431c7d918cc9 100644 (file)
@@ -54,6 +54,8 @@ package org.apache.fop.fo;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
+import org.apache.fop.control.Document;
+import org.apache.fop.fo.pagination.Root;
 
 // SAX
 import org.apache.avalon.framework.logger.Logger;
@@ -110,7 +112,7 @@ public class FOTreeBuilder extends DefaultHandler {
     /**
      * The root of the formatting object tree
      */
-    protected FONode rootFObj = null;
+    protected Root rootFObj = null;
 
     /**
      * The class that handles formatting and rendering to a stream
@@ -120,6 +122,8 @@ public class FOTreeBuilder extends DefaultHandler {
 
     private FOUserAgent userAgent;
 
+    public Document document;
+
     /**
      * Default constructor
      */
@@ -290,7 +294,8 @@ public class FOTreeBuilder extends DefaultHandler {
                                                         + " be fo:root, not "
                                                         + fobj.getName()));
             }
-            rootFObj = fobj;
+            rootFObj = (Root)fobj;
+            rootFObj.setDocument(document);
         } else {
             currentFObj.addChild(fobj);
         }
index 4f6739f3050984bec3506084422b184f8a39a662..58ba11288407aeea8baa22dcb8d2dbc63536b2d5 100644 (file)
@@ -104,8 +104,8 @@ public class FObjMixed extends FObj {
         if (textInfo == null) {
             // Really only need one of these, but need to get fontInfo
             // stored in propMgr for later use.
-            propMgr.setFontInfo(fontInfo);
-            textInfo = propMgr.getTextLayoutProps(fontInfo);
+            propMgr.setFontInfo(getDocument());
+            textInfo = propMgr.getTextLayoutProps(getDocument());
         }
 
         FOText ft = new FOText(data, start, length, textInfo, this);
index 0e73e64334876813661138feea615f2f11b50053..42cc308768e6ddfda583951ba0b15a375fb507b6 100644 (file)
@@ -83,7 +83,7 @@ import org.apache.fop.fo.properties.CommonHyphenation;
 public class PropertyManager {
 
     private PropertyList properties;
-    private Document fontInfo = null;
+    private Document doc = null;
     private Font fontState = null;
     private CommonBorderAndPadding borderAndPadding = null;
     private CommonHyphenation hyphProps = null;
@@ -118,27 +118,27 @@ public class PropertyManager {
     }
 
     /**
-     * Sets the FontInfo object telling the property manager which fonts are
+     * Sets the Document object telling the property manager which fonts are
      * available.
-     * @param fontInfo available fonts
+     * @param doc Document containing font information
      */
-    public void setFontInfo(Document fontInfo) {
-        this.fontInfo = fontInfo;
+    public void setFontInfo(Document doc) {
+        this.doc = doc;
     }
 
 
     /**
      * Constructs a FontState object. If it was constructed before it is
      * reused.
-     * @param fontInfo FontInfo to work with
+     * @param doc Document containing the font information
      * @return a FontState object
      */
-    public Font getFontState(Document fontInfo) {
+    public Font getFontState(Document doc) {
         if (fontState == null) {
-            if (fontInfo == null) {
-                fontInfo = this.fontInfo;
-            } else if (this.fontInfo == null) {
-                this.fontInfo = fontInfo;
+            if (doc == null) {
+                doc = this.doc;
+            } else if (this.doc == null) {
+                this.doc = doc;
             }
             /**@todo this is ugly. need to improve. */
 
@@ -167,9 +167,9 @@ public class PropertyManager {
             // various kinds of keywords too
             int fontSize = properties.get("font-size").getLength().getValue();
             //int fontVariant = properties.get("font-variant").getEnum();
-            String fname = fontInfo.fontLookup(fontFamily, fontStyle,
+            String fname = doc.fontLookup(fontFamily, fontStyle,
                                                fontWeight);
-            FontMetrics metrics = fontInfo.getMetricsFor(fname);
+            FontMetrics metrics = doc.getMetricsFor(fname);
             fontState = new Font(fname, metrics, fontSize);
         }
         return fontState;
@@ -476,13 +476,13 @@ public class PropertyManager {
     /**
      * Constructs a TextInfo objects. If it was constructed before it is
      * reused.
-     * @param fontInfo available fonts
+     * @param doc Document containing list of available fonts
      * @return a TextInfo object
      */
-    public TextInfo getTextLayoutProps(Document fontInfo) {
+    public TextInfo getTextLayoutProps(Document doc) {
         if (textInfo == null) {
             textInfo = new TextInfo();
-            textInfo.fs = getFontState(fontInfo);
+            textInfo.fs = getFontState(doc);
             textInfo.color = properties.get("color").getColorType();
 
             textInfo.verticalAlign =
index 79318d102f5bdd772fc30ff45d936e9e67edfd0c..b1e1b5b9bb98065596965317b094a762d3609023 100644 (file)
@@ -102,7 +102,7 @@ public abstract class XMLObj extends FONode {
     /**
      * @return DOM document representing this foreign XML
      */
-    public Document getDocument() {
+    public Document getDOMDocument() {
         return doc;
     }
 
index c8da3e38280bc62a9e8afdb0b80d0383f6528dd0..62a9b5c4ad99b3c3b88f5bd53ab95610a20767b1 100644 (file)
@@ -237,7 +237,7 @@ public class InstreamForeignObject extends FObj {
 
         Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight);
 
-        Document doc = child.getDocument();
+        Document doc = child.getDOMDocument();
         String ns = child.getDocumentNamespace();
 
         children = null;
index 57bb879faa56677ec6676974e0f7fad5ce1498fe..2726372f16b5de520b2169d7ec43c79ecf6dfdef 100644 (file)
  */
 package org.apache.fop.fo.pagination;
 
-// FOP
+// java
 import java.util.List;
 
+// FOP
+import org.apache.fop.control.Document;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FObj;
 
@@ -68,6 +70,8 @@ public class Root extends FObj {
      */
     private int runningPageNumberCounter = 0;
 
+    private Document document = null;
+
     /**
      * @see org.apache.fop.fo.FONode#FONode(FONode)
      */
@@ -137,4 +141,24 @@ public class Root extends FObj {
     public void setLayoutMasterSet(LayoutMasterSet layoutMasterSet) {
         this.layoutMasterSet = layoutMasterSet;
     }
+
+    /**
+     * Sets the Document that this Root is attached to
+     * @param document the Document that this Root is attached to
+     */
+    public void setDocument(Document document) {
+        this.document = document;
+    }
+
+    /**
+     * This method overrides the FONode version. The FONode version calls the
+     * method by the same name for the parent object. Since Root is at the top
+     * of the tree, it returns the actual Document object. Thus, any FONode can
+     * use this chain to find which Document it is being built for.
+     * @return the Document that this Root is attached to
+     */
+    public Document getDocument() {
+        return document;
+    }
+
 }