/*
- * $Id: Area.java,v 1.16 2003/03/05 15:19:31 jeremias Exp $
- * ============================================================================
- * 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.area;
+ Copyright 2004 The Apache Software Foundation.
-import java.io.Serializable;
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
-import java.util.Map;
-import java.util.HashMap;
+ http://www.apache.org/licenses/LICENSE-2.0
-// If the area appears more than once in the output
-// or if the area has external data it is cached
-// to keep track of it and to minimize rendered output
-// renderers can render the output once and display it
-// for every occurence
-// this should also extend to all outputs (including PDFGraphics2D)
-// and all types of renderers
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
-/**
- * Base object for all areas.
+ * Created on 26/01/2004
+ * $Id$
*/
-public class Area implements Serializable {
- // stacking directions
- /**
- * Stacking left to right
- */
- public static final int LR = 0;
-
- /**
- * Stacking right to left
- */
- public static final int RL = 1;
-
- /**
- * Stacking top to bottom
- */
- public static final int TB = 2;
-
- /**
- * Stacking bottom to top
- */
- public static final int BT = 3;
-
- // orientations for reference areas
- /**
- * Normal orientation
- */
- public static final int ORIENT_0 = 0;
-
- /**
- * Rotated 90 degrees clockwise
- */
- public static final int ORIENT_90 = 1;
-
- /**
- * Rotate 180 degrees
- */
- public static final int ORIENT_180 = 2;
-
- /**
- * Rotated 270 degrees clockwise
- */
- public static final int ORIENT_270 = 3;
-
- // area class values
-
- /**
- * Normal class
- */
- public static final int CLASS_NORMAL = 0;
-
- /**
- * Fixed position class
- */
- public static final int CLASS_FIXED = 1;
-
- /**
- * Absolute position class
- */
- public static final int CLASS_ABSOLUTE = 2;
-
- /**
- * Before float class
- */
- public static final int CLASS_BEFORE_FLOAT = 3;
-
- /**
- * Footnote class
- */
- public static final int CLASS_FOOTNOTE = 4;
-
- /**
- * Side float class
- */
- public static final int CLASS_SIDE_FLOAT = 5;
-
- // IMPORTANT: make sure this is the maximum + 1
- /**
- * Maximum class count
- */
- public static final int CLASS_MAX = CLASS_SIDE_FLOAT + 1;
-
- private int areaClass = CLASS_NORMAL;
- private int ipd;
-
- /**
- * Traits for this area stored in a HashMap
- */
- protected HashMap props = null;
-
- /**
- * Get the area class of this area.
- *
- * @return the area class
- */
- public int getAreaClass() {
- return areaClass;
- }
-
- /**
- * Set the area class of this area.
- *
- * @param areaClass the area class
- */
- public void setAreaClass(int areaClass) {
- this.areaClass = areaClass;
- }
-
- /**
- * Set the inline progression dimension of this area.
- *
- * @param i the new inline progression dimension
- */
- public void setIPD(int i) {
- ipd = i;
- }
-
- /**
- * Get the inline progression dimension of this area.
- *
- * @return the inline progression dimension
- */
- public int getIPD() {
- return ipd;
- }
+package org.apache.fop.area;
- /**
- * Add a child to this area.
- * The default is to do nothing. Subclasses must override
- * to do something if they can have child areas.
- *
- * @param child the child area to add
- */
- public void addChild(Area child) {
- }
+import org.apache.fop.datastructs.Node;
- /**
- * Add a trait property to this area.
- *
- * @param prop the Trait to add
- */
- public void addTrait(Trait prop) {
- if (props == null) {
- props = new java.util.HashMap(20);
- }
- props.put(prop.getPropType(), prop.getData());
- }
+/**
+ * The base class for all areas. <code>Area</code> extends <code>Node</code>
+ * because all areas will find themselves in a tree of some kind.
+ * @author pbw
+ * @version $Revision$ $Name$
+ */
+public class Area extends Node {
/**
- * Add a trait to this area.
- *
- * @param traitCode the trait key
- * @param prop the value of the trait
+ * @param parent
+ * @param index
+ * @throws IndexOutOfBoundsException
*/
- public void addTrait(Object traitCode, Object prop) {
- if (props == null) {
- props = new java.util.HashMap(20);
- }
- props.put(traitCode, prop);
+ public Area(Node parent, int index)
+ throws IndexOutOfBoundsException {
+ super(parent, index, Node.SYNCHRONIZE);
+ // TODO Auto-generated constructor stub
}
/**
- * Get the map of all traits on this area.
- *
- * @return the map of traits
+ * @param parent
+ * @throws IndexOutOfBoundsException
*/
- public Map getTraits() {
- return this.props;
+ public Area(Node parent)
+ throws IndexOutOfBoundsException {
+ super(parent, Node.SYNCHRONIZE);
+ // TODO Auto-generated constructor stub
}
- /**
- * Get a trait from this area.
- *
- * @param oTraitCode the trait key
- * @return the trait value
- */
- public Object getTrait(Object oTraitCode) {
- return (props != null ? props.get(oTraitCode) : null);
- }
-
- /**
- * Get a trait from this area as an integer.
- *
- * @param oTraitCode the trait key
- * @return the trait value
- */
- public int getTraitAsInteger(Object oTraitCode) {
- final Object obj = getTrait(oTraitCode);
- if (obj instanceof Integer) {
- return ((Integer)obj).intValue();
- } else {
- throw new IllegalArgumentException("Trait "
- + oTraitCode.getClass().getName()
- + " could not be converted to an integer");
- }
- }
}
-
/*
- * $Id: AreaTree.java,v 1.16 2003/03/05 15:19:31 jeremias Exp $
- * ============================================================================
- * 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.area;
-
-import org.apache.fop.area.extensions.BookmarkData;
-import org.apache.fop.fo.extensions.Outline;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Iterator;
-
-/**
- * Area tree for formatting objects.
- *
- * Concepts:
- * The area tree is to be as small as possible. With minimal classes
- * and data to fully represent an area tree for formatting objects.
- * The area tree needs to be simple to render and follow the spec
- * closely.
- * This area tree has the concept of page sequences.
- * Where ever possible information is discarded or optimised to
- * keep memory use low. The data is also organised to make it
- * possible for renderers to minimise their output.
- * A page can be saved if not fully resolved and once rendered
- * a page contains only size and id reference information.
- * The area tree pages are organised in a model that depends on the
- * type of renderer.
- */
-public class AreaTree {
- // allows for different models to deal with adding/rendering
- // in different situations
- private AreaTreeModel model;
- private AreaTreeControl atControl;
-
- // hashmap of arraylists containing pages with id area
- private Map idLocations = new HashMap();
- // list of id's yet to be resolved and arraylists of pages
- private Map resolve = new HashMap();
- private List treeExtensions = new ArrayList();
-
- /**
- * Constructor.
- * @param atControl the AreaTreeControl object controlling this AreaTree
- */
- public AreaTree (AreaTreeControl atControl) {
- this.atControl = atControl;
- }
-
-
- /**
- * Create a new store pages model.
- * @return StorePagesModel the new model
- */
- public static StorePagesModel createStorePagesModel() {
- return new StorePagesModel();
- }
-
- /**
- * Set the tree model to use for this area tree.
- * The different models can have different behaviour
- * when pages area added and other changes.
- * @param m the area tree model
- */
- public void setTreeModel(AreaTreeModel m) {
- model = m;
- }
-
- /**
- * Get the area tree model for this area tree.
- *
- * @return AreaTreeModel the model being used for this area tree
- */
- public AreaTreeModel getAreaTreeModel() {
- return model;
- }
-
- /**
- * Start a new page sequence.
- * This signals that a new page sequence has started in the document.
- * @param title the title of the new page sequence or null if no title
- */
- public void startPageSequence(Title title) {
- model.startPageSequence(title);
- }
-
- /**
- * Add a new page to the area tree.
- * @param page the page to add
- */
- public void addPage(PageViewport page) {
- model.addPage(page);
- }
-
- /**
- * Add an id reference pointing to a page viewport.
- * @param id the id of the reference
- * @param pv the page viewport that contains the id reference
- */
- public void addIDRef(String id, PageViewport pv) {
- List list = (List)idLocations.get(id);
- if (list == null) {
- list = new ArrayList();
- idLocations.put(id, list);
- }
- list.add(pv);
-
- Set todo = (Set)resolve.get(id);
- if (todo != null) {
- for (Iterator iter = todo.iterator(); iter.hasNext();) {
- Resolveable res = (Resolveable)iter.next();
- res.resolve(id, list);
- }
- resolve.remove(id);
- }
- }
+ Copyright 2004 The Apache Software Foundation.
- /**
- * Get the list of id references for an id.
- * @param id the id to lookup
- * @return the list of id references.
- */
- public List getIDReferences(String id) {
- return (List)idLocations.get(id);
- }
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
- /**
- * Add an unresolved object with a given id.
- * @param id the id reference that needs resolving
- * @param res the Resolveable object to resolve
- */
- public void addUnresolvedID(String id, Resolveable res) {
- Set todo = (Set)resolve.get(id);
- if (todo == null) {
- todo = new HashSet();
- resolve.put(id, todo);
- }
- todo.add(res);
- }
+ http://www.apache.org/licenses/LICENSE-2.0
- /**
- * Add a tree extension.
- * This checks if the extension is resolveable and attempts
- * to resolve or add the resolveable ids for later resolution.
- * @param ext the tree extension to add.
- */
- public void addTreeExtension(TreeExt ext) {
- treeExtensions.add(ext);
- if (ext.isResolveable()) {
- Resolveable res = (Resolveable)ext;
- String[] ids = res.getIDs();
- for (int count = 0; count < ids.length; count++) {
- if (idLocations.containsKey(ids[count])) {
- res.resolve(ids[count], (List)idLocations.get(ids[count]));
- } else {
- Set todo = (Set)resolve.get(ids[count]);
- if (todo == null) {
- todo = new HashSet();
- resolve.put(ids[count], todo);
- }
- todo.add(ext);
- }
- }
- } else {
- handleTreeExtension(ext, TreeExt.IMMEDIATELY);
- }
- }
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
- /**
- * Handle a tree extension.
- * This sends the extension to the model for handling.
- * @param ext the tree extension to handle
- * @param when when the extension should be handled by the model
- */
- public void handleTreeExtension(TreeExt ext, int when) {
- // queue tree extension according to the when
- model.addExtension(ext, when);
- }
+ * Created on 26/01/2004
+ * $Id$
+ */
+package org.apache.fop.area;
- /**
- * Signal end of document.
- * This indicates that the document is complete and any unresolved
- * reference can be dealt with.
- */
- public void endDocument() {
- for (Iterator iter = resolve.keySet().iterator(); iter.hasNext();) {
- String id = (String)iter.next();
- Set list = (Set)resolve.get(id);
- for (Iterator resIter = list.iterator(); resIter.hasNext();) {
- Resolveable res = (Resolveable)resIter.next();
- if (!res.isResolved()) {
- res.resolve(id, null);
- }
- }
- }
- model.endDocument();
- }
+import org.apache.fop.datastructs.Tree;
- /**
- * Create the bookmark data in the area tree.
- */
- public void addBookmarksToAreaTree() {
- if (atControl.getBookmarks() == null) {
- return;
- }
- atControl.getLogger().debug("adding bookmarks to area tree");
- BookmarkData data = new BookmarkData();
- for (int count = 0; count < atControl.getBookmarks().getOutlines().size(); count++) {
- Outline out = (Outline)(atControl.getBookmarks().getOutlines()).get(count);
- data.addSubData(createBookmarkData(out));
- }
- addTreeExtension(data);
- data.setAreaTree(this);
- }
+/**
+ * The tree of areas created from flow objects.
+ *
+ * @author pbw
+ * @version $Revision$ $Name$
+ */
+public class AreaTree extends Tree {
/**
- * Create and return the bookmark data for this outline.
- * This creates a bookmark data with the destination
- * and adds all the data from child outlines.
- *
- * @param outline the Outline object for which a bookmark entry should be
- * created
- * @return the new bookmark data
+ *
*/
- public BookmarkData createBookmarkData(Outline outline) {
- BookmarkData data = new BookmarkData(outline.getInternalDestination());
- data.setLabel(outline.getLabel());
- for (int count = 0; count < outline.getOutlines().size(); count++) {
- Outline out = (Outline)(outline.getOutlines()).get(count);
- data.addSubData(createBookmarkData(out));
- }
- return data;
- }
-
- public AreaTreeControl getAreaTreeControl() {
- return atControl;
+ public AreaTree() {
+ super();
+ // TODO Auto-generated constructor stub
}
}