Browse Source

create fo/FOTreeControl interface, and make control/Document implement it, to further encapsulate the FO Tree


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196811 13f79535-47bb-0310-9956-ffa450edef68
pull/30/head
William Victor Mote 21 years ago
parent
commit
7d04f44b9d

+ 1
- 1
src/java/org/apache/fop/apps/Driver.java View File

@@ -601,7 +601,7 @@ public class Driver implements LogEnabled, FOTreeListener {
if (foInputHandler instanceof FOTreeHandler) {
currentDocument.setLayoutStrategy(new LayoutManagerLS());
}
treeBuilder.document = currentDocument;
treeBuilder.foTreeControl = currentDocument;
try {
if (foInputHandler instanceof FOTreeHandler) {
FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler;

+ 2
- 1
src/java/org/apache/fop/control/Document.java View File

@@ -55,6 +55,7 @@ import java.util.Map;

// FOP
import org.apache.fop.apps.Driver;
import org.apache.fop.fo.FOTreeControl;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontMetrics;
import org.apache.fop.layout.LayoutStrategy;
@@ -63,7 +64,7 @@ import org.apache.fop.layout.LayoutStrategy;
* Class storing information for the FOP Document being processed, and managing
* the processing of it.
*/
public class Document {
public class Document implements FOTreeControl {

/** The parent Driver object */
private Driver driver;

+ 3
- 3
src/java/org/apache/fop/fo/FONode.java View File

@@ -61,7 +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.fo.FOTreeControl;
import org.apache.fop.util.CharUtilities;

/**
@@ -216,8 +216,8 @@ public abstract class FONode {
* which returns the parent Document.
* @return the Document object that is the parent of this node.
*/
public Document getDocument() {
return parent.getDocument();
public FOTreeControl getFOTreeControl() {
return parent.getFOTreeControl();
}

/**

+ 3
- 3
src/java/org/apache/fop/fo/FOTreeBuilder.java View File

@@ -54,7 +54,7 @@ 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.FOTreeControl;
import org.apache.fop.fo.pagination.Root;

// SAX
@@ -122,7 +122,7 @@ public class FOTreeBuilder extends DefaultHandler {

private FOUserAgent userAgent;

public Document document;
public FOTreeControl foTreeControl;

/**
* Default constructor
@@ -295,7 +295,7 @@ public class FOTreeBuilder extends DefaultHandler {
+ fobj.getName()));
}
rootFObj = (Root)fobj;
rootFObj.setDocument(document);
rootFObj.setFOTreeControl(foTreeControl);
} else {
currentFObj.addChild(fobj);
}

+ 72
- 0
src/java/org/apache/fop/fo/FOTreeControl.java View File

@@ -0,0 +1,72 @@
/*
* $Id$
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/

package org.apache.fop.fo;

import org.apache.fop.fonts.FontMetrics;

/**
* An interface for classes that are conceptually the parent class of the
* fo.pagination.Root object. The purpose of the interface is to maintain
* encapsulation of the FO Tree classes, but to acknowledge that a higher-level
* object is needed to control the building of the FO Tree, to provide it
* with information about the environment, and to keep track of meta-type
* information.
*/

public interface FOTreeControl {

public String fontLookup(String family, String style,
int weight);

public FontMetrics getMetricsFor(String fontName);

}

+ 4
- 4
src/java/org/apache/fop/fo/FObjMixed.java View File

@@ -50,7 +50,7 @@
*/
package org.apache.fop.fo;

import org.apache.fop.control.Document;
import org.apache.fop.fo.FOTreeControl;
import org.apache.fop.layoutmgr.InlineStackingLayoutManager;
import org.apache.fop.layoutmgr.LMiter;

@@ -64,7 +64,7 @@ public class FObjMixed extends FObj {
/** TextInfo for this object */
protected TextInfo textInfo = null;
/** FontInfo for this object */
protected Document fontInfo = null;
protected FOTreeControl fontInfo = null;

/**
* @param parent FONode that is the parent of this object
@@ -90,8 +90,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(getDocument());
textInfo = propMgr.getTextLayoutProps(getDocument());
propMgr.setFontInfo(getFOTreeControl());
textInfo = propMgr.getTextLayoutProps(getFOTreeControl());
}

FOText ft = new FOText(data, start, length, textInfo, this);

+ 13
- 13
src/java/org/apache/fop/fo/PropertyManager.java View File

@@ -58,7 +58,7 @@ import java.awt.geom.Rectangle2D;
import org.apache.fop.area.CTM;
import org.apache.fop.datatypes.FODimension;
import org.apache.fop.fonts.Font;
import org.apache.fop.control.Document;
import org.apache.fop.fo.FOTreeControl;
import org.apache.fop.fo.properties.CommonBorderAndPadding;
import org.apache.fop.fo.properties.CommonMarginBlock;
import org.apache.fop.fo.properties.CommonMarginInline;
@@ -83,7 +83,7 @@ import org.apache.fop.fo.properties.CommonHyphenation;
public class PropertyManager {

private PropertyList properties;
private Document doc = null;
private FOTreeControl foTreeControl = null;
private Font fontState = null;
private CommonBorderAndPadding borderAndPadding = null;
private CommonHyphenation hyphProps = null;
@@ -122,8 +122,8 @@ public class PropertyManager {
* available.
* @param doc Document containing font information
*/
public void setFontInfo(Document doc) {
this.doc = doc;
public void setFontInfo(FOTreeControl foTreeControl) {
this.foTreeControl = foTreeControl;
}


@@ -133,12 +133,12 @@ public class PropertyManager {
* @param doc Document containing the font information
* @return a FontState object
*/
public Font getFontState(Document doc) {
public Font getFontState(FOTreeControl foTreeControl) {
if (fontState == null) {
if (doc == null) {
doc = this.doc;
} else if (this.doc == null) {
this.doc = doc;
if (foTreeControl == null) {
foTreeControl = this.foTreeControl;
} else if (this.foTreeControl == null) {
this.foTreeControl = foTreeControl;
}
/**@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 = doc.fontLookup(fontFamily, fontStyle,
String fname = foTreeControl.fontLookup(fontFamily, fontStyle,
fontWeight);
FontMetrics metrics = doc.getMetricsFor(fname);
FontMetrics metrics = foTreeControl.getMetricsFor(fname);
fontState = new Font(fname, metrics, fontSize);
}
return fontState;
@@ -479,10 +479,10 @@ public class PropertyManager {
* @param doc Document containing list of available fonts
* @return a TextInfo object
*/
public TextInfo getTextLayoutProps(Document doc) {
public TextInfo getTextLayoutProps(FOTreeControl foTreeControl) {
if (textInfo == null) {
textInfo = new TextInfo();
textInfo.fs = getFontState(doc);
textInfo.fs = getFontState(foTreeControl);
textInfo.color = properties.get("color").getColorType();

textInfo.verticalAlign =

+ 12
- 11
src/java/org/apache/fop/fo/pagination/Root.java View File

@@ -54,7 +54,7 @@ package org.apache.fop.fo.pagination;
import java.util.List;

// FOP
import org.apache.fop.control.Document;
import org.apache.fop.fo.FOTreeControl;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.FOTreeVisitor;
@@ -71,7 +71,7 @@ public class Root extends FObj {
*/
private int runningPageNumberCounter = 0;

private Document document = null;
private FOTreeControl foTreeControl = null;

/**
* @see org.apache.fop.fo.FONode#FONode(FONode)
@@ -144,22 +144,23 @@ public class Root extends FObj {
}

/**
* Sets the Document that this Root is attached to
* @param document the Document that this Root is attached to
* Sets the FOTreeControl that this Root is attached to
* @param foTreeControl the FOTreeControl implementation to which this Root
* is attached
*/
public void setDocument(Document document) {
this.document = document;
public void setFOTreeControl(FOTreeControl foTreeControl) {
this.foTreeControl = foTreeControl;
}

/**
* 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
* of the tree, it returns the actual foTreeControl object. Thus, any FONode
* can use this chain to find which foTreeControl it is being built for.
* @return the FOTreeControl implementation that this Root is attached to
*/
public Document getDocument() {
return document;
public FOTreeControl getFOTreeControl() {
return foTreeControl;
}

public void acceptVisitor(FOTreeVisitor fotv) {

+ 1
- 1
src/java/org/apache/fop/layoutmgr/AddLMVisitor.java View File

@@ -251,7 +251,7 @@ public class AddLMVisitor extends FOTreeVisitor {
BlockLayoutManager blm = new BlockLayoutManager();
blm.setUserAgent(node.getUserAgent());
blm.setFObj(node);
TextInfo ti = node.getPropertyManager().getTextLayoutProps(node.getDocument());
TextInfo ti = node.getPropertyManager().getTextLayoutProps(node.getFOTreeControl());
blm.setBlockTextInfo(ti);
currentLMList.add(blm);
}

Loading…
Cancel
Save