From: William Victor Mote Date: Sat, 16 Aug 2003 06:43:51 +0000 (+0000) Subject: 1. tie Document to fo.FOTreeBuilder and fo.pagination.Root X-Git-Tag: Root_Temp_KnuthStylePageBreaking~1195 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=47daa474f7f92a928541f809058637d8cc4de499;p=xmlgraphics-fop.git 1. tie Document to fo.FOTreeBuilder and fo.pagination.Root 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 --- diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index 86156f326..198e6303e 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -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; diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 60969030c..e51744f67 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -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(); + } + } diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index bb50b23be..1af4d795f 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -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); } diff --git a/src/java/org/apache/fop/fo/FObjMixed.java b/src/java/org/apache/fop/fo/FObjMixed.java index 4f6739f30..58ba11288 100644 --- a/src/java/org/apache/fop/fo/FObjMixed.java +++ b/src/java/org/apache/fop/fo/FObjMixed.java @@ -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); diff --git a/src/java/org/apache/fop/fo/PropertyManager.java b/src/java/org/apache/fop/fo/PropertyManager.java index 0e73e6433..42cc30876 100644 --- a/src/java/org/apache/fop/fo/PropertyManager.java +++ b/src/java/org/apache/fop/fo/PropertyManager.java @@ -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 = diff --git a/src/java/org/apache/fop/fo/XMLObj.java b/src/java/org/apache/fop/fo/XMLObj.java index 79318d102..b1e1b5b9b 100644 --- a/src/java/org/apache/fop/fo/XMLObj.java +++ b/src/java/org/apache/fop/fo/XMLObj.java @@ -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; } diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java index c8da3e382..62a9b5c4a 100644 --- a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -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; diff --git a/src/java/org/apache/fop/fo/pagination/Root.java b/src/java/org/apache/fop/fo/pagination/Root.java index 57bb879fa..2726372f1 100644 --- a/src/java/org/apache/fop/fo/pagination/Root.java +++ b/src/java/org/apache/fop/fo/pagination/Root.java @@ -50,9 +50,11 @@ */ 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; + } + }