pbwest 02/05/06 22:23:06 Modified: src/org/apache/fop/fo Tag: FOP_0-20-0_Alt-Design FONode.java Log: Experimental version of FONode Revision Changes Path No revision No revision 1.19.2.1 +81 -230 xml-fop/src/org/apache/fop/fo/FONode.java Index: FONode.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/FONode.java,v retrieving revision 1.19 retrieving revision 1.19.2.1 diff -u -r1.19 -r1.19.2.1 --- FONode.java 1 Aug 2001 23:08:54 -0000 1.19 +++ FONode.java 7 May 2002 05:23:06 -0000 1.19.2.1 @@ -1,244 +1,95 @@ +package org.apache.fop.fo; + +import org.apache.fop.fo.FOTree; +import org.apache.fop.fo.FOAttributes; +import org.apache.fop.fo.FObjects; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.expr.PropertyParser; +import org.apache.fop.fo.expr.PropertyValue; +import org.apache.fop.fo.expr.PropertyValueList; +import org.apache.fop.datastructs.Tree; +import org.apache.fop.datastructs.SyncedCircularBuffer; +import org.apache.fop.apps.FOPException; +import org.apache.fop.xml.XMLEvent; + +import org.xml.sax.Attributes; + +import java.util.LinkedList; +import java.util.ArrayList; + /* - * $Id: FONode.java,v 1.19 2001/08/01 23:08:54 gears Exp $ + * FONode.java + * Created: Sat Nov 10 01:39:37 2001 + * * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Peter B. West</a> + * @version $Revision: 1.19.2.1 $ $Name: $ */ - - -package org.apache.fop.fo; - -// FOP -import org.apache.fop.apps.FOPException; -import org.apache.fop.layout.Area; -import org.apache.fop.layout.AreaClass; -import org.apache.fop.layout.LinkSet; -import org.apache.fop.system.BufferManager; -import org.apache.fop.fo.flow.Marker; - -// Java -import java.util.Vector; -import java.util.Hashtable; - /** - * base class for nodes in the formatting object tree - * - * Modified by Mark Lillywhite [EMAIL PROTECTED] Made - * Vector a protected member. (/me things this should be - * a private member with an API for adding children; - * this woudl save a lot of memory because the Vector - * would not have to be instantiated unless the node had - * children). + * Class for nodes in the FO tree. */ -abstract public class FONode { - - protected FObj parent; - - protected String areaClass = AreaClass.UNASSIGNED; - - public BufferManager bufferManager; - protected Vector children = new Vector(); // made public for searching for id's - - /** - * value of marker before layout begins - */ - public final static int START = -1000; - - /** - * value of marker after break-after - */ - public final static int BREAK_AFTER = -1001; +public class FONode extends FOTree.Node{ /** - * where the layout was up to. - * for FObjs it is the child number - * for FOText it is the character number + * Constants for the set of attributes of interest with this FONode */ - protected int marker = START; - - protected boolean isInTableCell = false; - - protected int forcedStartOffset = 0; - protected int forcedWidth = 0; - - protected int widows = 0; - protected int orphans = 0; - - protected LinkSet linkSet; - - // count of areas generated-by/returned-by - public int areasGenerated = 0; - - // markers - protected Hashtable markers; - - protected FONode(FObj parent) { - this.parent = parent; - if (parent != null) { - this.bufferManager = parent.bufferManager; + public static final int + NONE = 0 + ,ROOT = 1 + ,LAYOUT = 2 + ,FLOW = 3 + ; + + /** The <tt>FOTree</tt> of which this node is a member. */ + protected FOTree foTree; + /** The <tt>XMLEvent</tt> which triggered this node. */ + protected XMLEvent event; + /** The buffer from which parser events are drawn. */ + protected SyncedCircularBuffer xmlevents; + /** The array of property value stacks */ + protected LinkedList[] propertyStacks; + /** The attributes defined on this node. */ + public FOAttributes foAttributes; + /** The property expression parser in the FOTree. */ + protected PropertyParser exprParser; + + /** + * @param foTree an <tt>FOTree</tt> to which this node belongs + * @param parent an <tt>FONode</tt>, the parent node of this node in + * <i>foTree</i> + * @param event the <tt>XMLEvent</tt> that triggered the creation of this + * node + */ + public FONode (FOTree foTree, FONode parent, XMLEvent event, int attrSet) + throws Tree.TreeException, FOPException, PropertyException + { + foTree.super(parent); + this.foTree = foTree; + this.event = event; + xmlevents = foTree.xmlevents; + propertyStacks = foTree.propertyStacks; + exprParser = foTree.exprParser; + foAttributes = new FOAttributes(event); + // Process the FOAttributes - parse and stack the values + // font-size is always done first + String value = foAttributes.getFoAttrValue("font-size"); + if (value != null) { // font-size is defined in the attributes + // parse the expression + exprParser.resetParser(); + PropertyValue props = + exprParser.parse(PropNames.FONT_SIZE, value); + // font-size must be a single property value, which may be + // a percentage + if (props instanceof PropertyValueList) + throw new PropertyException + ("font-size requires single PropertyValue in " + + "PropertyValueList"); + } - - markers = new Hashtable(); - - if (null != parent) - this.areaClass = parent.areaClass; - } - - public void setIsInTableCell() { - this.isInTableCell = true; - // made recursive by Eric Schaeffer - for (int i = 0; i < this.children.size(); i++) { - FONode child = (FONode)this.children.elementAt(i); - child.setIsInTableCell(); - } - } - - public void forceStartOffset(int offset) { - this.forcedStartOffset = offset; - // made recursive by Eric Schaeffer - for (int i = 0; i < this.children.size(); i++) { - FONode child = (FONode)this.children.elementAt(i); - child.forceStartOffset(offset); - } - } - - public void forceWidth(int width) { - this.forcedWidth = width; - // made recursive by Eric Schaeffer - for (int i = 0; i < this.children.size(); i++) { - FONode child = (FONode)this.children.elementAt(i); - child.forceWidth(width); - } - } - - public void resetMarker() { - this.marker = START; - int numChildren = this.children.size(); - for (int i = 0; i < numChildren; i++) { - ((FONode)children.elementAt(i)).resetMarker(); - } - } - - public void setWidows(int wid) { - widows = wid; - } - - public void setOrphans(int orph) { - orphans = orph; - } - - public void removeAreas() { - // still to do - } - - - protected void addChild(FONode child) { - children.addElement(child); - } - - public FObj getParent() { - return this.parent; - } - - public void setBufferManager(BufferManager bufferManager) { - this.bufferManager = bufferManager; - } - - public BufferManager getBufferManager() { - return this.bufferManager; - } - - public void setLinkSet(LinkSet linkSet) { - this.linkSet = linkSet; - for (int i = 0; i < this.children.size(); i++) { - FONode child = (FONode)this.children.elementAt(i); - child.setLinkSet(linkSet); - } - } - - public LinkSet getLinkSet() { - return this.linkSet; - } - - abstract public Status layout(Area area) throws FOPException; - - /** - * lets outside sources access the property list - * first used by PageNumberCitation to find the "id" property - * returns null by default, overide this function when there is a property list - * @param name - the name of the desired property to obtain - * @returns the property - */ - public Property getProperty(String name) { - return (null); - } - - /** - * At the start of a new span area layout may be partway through a - * nested FO, and balancing requires rollback to this known point. - * The snapshot records exactly where layout is at. - * @param snapshot a Vector of markers (Integer) - * @returns the updated Vector of markers (Integers) - */ - public Vector getMarkerSnapshot(Vector snapshot) { - snapshot.addElement(new Integer(this.marker)); - - // terminate if no kids or child not yet accessed - if (this.marker < 0) - return snapshot; - else if (children.isEmpty()) - return snapshot; - else - return ((FONode)children.elementAt(this.marker)).getMarkerSnapshot(snapshot); - } - - /** - * When balancing occurs, the flow layout() method restarts at the - * point specified by the current marker snapshot, which is retrieved - * and restored using this method. - * @param snapshot the Vector of saved markers (Integers) - */ - public void rollback(Vector snapshot) { - this.marker = ((Integer)snapshot.elementAt(0)).intValue(); - snapshot.removeElementAt(0); - - if (this.marker == START) { - // make sure all the children of this FO are also reset - resetMarker(); - return; - } else if ((this.marker == -1) || children.isEmpty()) - return; - - int numChildren = this.children.size(); - - if (this.marker <= START) { - return; - } - - for (int i = this.marker + 1; i < numChildren; i++) { - FONode fo = (FONode)children.elementAt(i); - fo.resetMarker(); - } - ((FONode)children.elementAt(this.marker)).rollback(snapshot); - } - - - public void addMarker(Marker marker) throws FOPException { - String mcname = marker.getMarkerClassName(); - if (!markers.containsKey(mcname) && children.isEmpty()) - markers.put(mcname, marker); - else - throw new FOPException("fo:marker must be an initial child," - + "and 'marker-class-name' must be unique for same parent"); - } - - public boolean hasMarkers() { - return !markers.isEmpty(); - } - - public Vector getMarkers() { - return new Vector(markers.values()); } -} +}// FONode
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]