Browse Source

PR:

Obtained from:
Submitted by:
Reviewed by:
1.) Rename of interface Resolveable to Resolvable.      (http://dictionary.reference.com/search?q=resolvable)
2.) Reordering of methods in AreaTreeHandler, removal of unneeded TreeExt array.
3.) Switch from AreaTreeModel.addExtension() to .handleExtension().
4.) Removal of unneeded TreeExt.getName() (unused), getMimeType() (implementation
of an Area Tree extension up to each renderer), and isResolvable() (code changed to
use instanceof operator instead).
5.) Couple of minor layout bugs fixed.


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198098 13f79535-47bb-0310-9956-ffa450edef68
pull/30/head
Glen Mazza 19 years ago
parent
commit
daf6d29eb3

+ 2
- 2
src/java/org/apache/fop/apps/FOUserAgent.java View File

@@ -57,8 +57,8 @@ import org.apache.fop.render.Renderer;
* eg. bookmarks will be held in a special hierarchical area representing
* the title and bookmark structure
* <br>
* These areas may contain resolveable areas that will be processed
* with other resolveable areas
* These areas may contain resolvable areas that will be processed
* with other resolvable areas
*/
public class FOUserAgent {


+ 55
- 58
src/java/org/apache/fop/area/AreaTreeHandler.java View File

@@ -86,8 +86,6 @@ public class AreaTreeHandler extends FOEventHandler {
// list of id's yet to be resolved and arraylists of pages
private Map resolve = new HashMap();

private List treeExtensions = new ArrayList();

private static Log log = LogFactory.getLog(AreaTreeHandler.class);

/**
@@ -136,7 +134,7 @@ public class AreaTreeHandler extends FOEventHandler {
Set todo = (Set)resolve.get(id);
if (todo != null) {
for (Iterator iter = todo.iterator(); iter.hasNext();) {
Resolveable res = (Resolveable)iter.next();
Resolvable res = (Resolvable)iter.next();
res.resolve(id, list);
}
resolve.remove(id);
@@ -155,9 +153,9 @@ public class AreaTreeHandler extends FOEventHandler {
/**
* Add an unresolved object with a given id.
* @param id the id reference that needs resolving
* @param res the Resolveable object to resolve
* @param res the Resolvable object to resolve
*/
public void addUnresolvedID(String id, Resolveable res) {
public void addUnresolvedID(String id, Resolvable res) {
Set todo = (Set)resolve.get(id);
if (todo == null) {
todo = new HashSet();
@@ -166,34 +164,6 @@ public class AreaTreeHandler extends FOEventHandler {
todo.add(res);
}

/**
* 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.
*/
private 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 {
model.addExtension(ext, TreeExt.IMMEDIATELY);
}
}

/**
* Prepare AreaTreeHandler for document processing
* This is called from FOTreeBuilder.startDocument()
@@ -224,7 +194,7 @@ public class AreaTreeHandler extends FOEventHandler {
String id = (String)iter.next();
Set list = (Set)resolve.get(id);
for (Iterator resIter = list.iterator(); resIter.hasNext();) {
Resolveable res = (Resolveable)resIter.next();
Resolvable res = (Resolvable)resIter.next();
if (!res.isResolved()) {
res.resolve(id, null);
}
@@ -257,6 +227,36 @@ public class AreaTreeHandler extends FOEventHandler {
}
}

/**
* End the PageSequence.
* The PageSequence formats Pages and adds them to the AreaTree.
* The area tree then handles what happens with the pages.
*
* @param pageSequence the page sequence ending
*/
public void endPageSequence(PageSequence pageSequence) {

if (collectStatistics) {
if (MEM_PROFILE_WITH_GC) {
// This takes time but gives better results
System.gc();
}
long memoryNow = runtime.totalMemory() - runtime.freeMemory();
if (logger != null) {
logger.debug("Current heap size: " + (memoryNow / 1024L) + "Kb");
}
}

// If no main flow, nothing to layout!
if (pageSequence.getMainFlow() != null) {
addBookmarks(pageSequence.getRoot().getBookmarks());
PageSequenceLayoutManager pageSLM
= new PageSequenceLayoutManager(this, pageSequence);
pageSLM.run();
pageSequence.setCurrentPageNumber(pageSLM.getPageCount());
}
}

/**
* Create the bookmark data in the area tree.
*/
@@ -295,32 +295,29 @@ public class AreaTreeHandler extends FOEventHandler {
}

/**
* End the PageSequence.
* The PageSequence formats Pages and adds them to the AreaTree.
* The area tree then handles what happens with the pages.
*
* @param pageSequence the page sequence ending
* Add a tree extension.
* This checks if the extension is resolvable and attempts
* to resolve or add the resolvable ids for later resolution.
* @param ext the tree extension to add.
*/
public void endPageSequence(PageSequence pageSequence) {

if (collectStatistics) {
if (MEM_PROFILE_WITH_GC) {
// This takes time but gives better results
System.gc();
}
long memoryNow = runtime.totalMemory() - runtime.freeMemory();
if (logger != null) {
logger.debug("Current heap size: " + (memoryNow / 1024L) + "Kb");
private void addTreeExtension(TreeExt ext) {
if (ext instanceof Resolvable) {
Resolvable res = (Resolvable)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);
}
}
}

// If no main flow, nothing to layout!
if (pageSequence.getMainFlow() != null) {
addBookmarks(pageSequence.getRoot().getBookmarks());
PageSequenceLayoutManager pageSLM
= new PageSequenceLayoutManager(this, pageSequence);
pageSLM.run();
pageSequence.setCurrentPageNumber(pageSLM.getPageCount());
} else {
model.handleExtension(ext, TreeExt.IMMEDIATELY);
}
}
}

+ 3
- 3
src/java/org/apache/fop/area/AreaTreeModel.java View File

@@ -43,11 +43,11 @@ public abstract class AreaTreeModel {
public abstract void addPage(PageViewport page);

/**
* Add an extension to this model.
* @param ext the extension to add
* Handle an area tree extension
* @param ext the extension to handle
* @param when when the extension should be handled
*/
public abstract void addExtension(TreeExt ext, int when);
public abstract void handleExtension(TreeExt ext, int when);

/**
* Signal the end of the document for any processing.

+ 2
- 2
src/java/org/apache/fop/area/LinkResolver.java View File

@@ -24,14 +24,14 @@ import java.io.Serializable;

// FOP
import org.apache.fop.area.Trait;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.Resolvable;
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Area;

/**
* Link resolving for resolving internal links.
*/
public class LinkResolver implements Resolveable, Serializable {
public class LinkResolver implements Resolvable, Serializable {
private boolean resolved = false;
private String idRef;
private Area area;

+ 3
- 3
src/java/org/apache/fop/area/PageViewport.java View File

@@ -37,7 +37,7 @@ import org.apache.fop.fo.Constants;
* This is the level that creates the page.
* The page (reference area) is then rendered inside the page object
*/
public class PageViewport implements Resolveable, Cloneable {
public class PageViewport implements Resolvable, Cloneable {
private Page page;
private Rectangle2D viewArea;
@@ -131,7 +131,7 @@ public class PageViewport implements Resolveable, Cloneable {
* @param id the id of the reference
* @param res the resolver of the reference
*/
public void addUnresolvedID(String id, Resolveable res) {
public void addUnresolvedID(String id, Resolvable res) {
if (unresolved == null) {
unresolved = new HashMap();
}
@@ -177,7 +177,7 @@ public class PageViewport implements Resolveable, Cloneable {
List todo = (List)unresolved.get(id);
if (todo != null) {
for (int count = 0; count < todo.size(); count++) {
Resolveable res = (Resolveable)todo.get(count);
Resolvable res = (Resolvable)todo.get(count);
res.resolve(id, pages);
}
}

+ 2
- 8
src/java/org/apache/fop/area/RenderPagesModel.java View File

@@ -175,15 +175,9 @@ public class RenderPagesModel extends StorePagesModel {
}

/**
* Add an extension to this model.
* If handle immediately then send directly to the renderer.
* The after page ones are handled after the next page is added.
* End of document extensions are added to a list to be
* handled at the end.
* @param ext the extension
* @param when when to render the extension
* @see org.apache.fop.area.AreaTreeModel#handleExtension(TreeExt, int)
*/
public void addExtension(TreeExt ext, int when) {
public void handleExtension(TreeExt ext, int when) {
switch(when) {
case TreeExt.IMMEDIATELY:
renderer.renderExtension(ext);

src/java/org/apache/fop/area/Resolveable.java → src/java/org/apache/fop/area/Resolvable.java View File

@@ -21,11 +21,11 @@ package org.apache.fop.area;
import java.util.List;

/**
* Resolveable Interface.
* Resolvable Interface.
* Classes that implement this can be resolved when
* an id is added to the area tree.
*/
public interface Resolveable {
public interface Resolvable {

/**
* Check if this area has been resolved.
@@ -35,8 +35,8 @@ public interface Resolveable {
boolean isResolved();

/**
* Get the array of id references of this resolveable object.
* If this object contains child resolveables that are
* Get the array of id references of this resolvable object.
* If this object contains child resolvables that are
* resolved through this then it should return the id's of
* the child also.
*

+ 2
- 6
src/java/org/apache/fop/area/StorePagesModel.java View File

@@ -92,13 +92,9 @@ public class StorePagesModel extends AreaTreeModel {
}

/**
* Add an extension to the store page model.
* The extension is stored so that it can be retrieved in the
* appropriate position.
* @param ext the extension to add
* @param when when the extension should be handled
* @see org.apache.fop.area.AreaTreeModel#handleExtension(TreeExt, int)
*/
public void addExtension(TreeExt ext, int when) {
public void handleExtension(TreeExt ext, int when) {
int seq, page;
switch(when) {
case TreeExt.IMMEDIATELY:

+ 0
- 23
src/java/org/apache/fop/area/TreeExt.java View File

@@ -45,27 +45,4 @@ public interface TreeExt {
*/
public static final int END_OF_DOC = 2;

/**
* Check if this tree extension is also resolveable so that
* the area tree can do id reference resolution when the
* extension is added to the area tree.
*
* @return true if this also implements resolveable
*/
boolean isResolveable();

/**
* Get the mime type for the document that this area tree
* extension applies.
*
* @return the mime type of the document where this applies
*/
String getMimeType();

/**
* Get the name of this extension.
*
* @return the name of this extension
*/
String getName();
}

+ 7
- 34
src/java/org/apache/fop/area/extensions/BookmarkData.java View File

@@ -19,7 +19,7 @@
package org.apache.fop.area.extensions;

import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.Resolvable;
import org.apache.fop.area.TreeExt;
import org.apache.fop.area.AreaTreeModel;

@@ -29,10 +29,10 @@ import java.util.HashMap;

/**
* This class holds the PDF bookmark extension data.
* This implements Resolveable and TreeExt so that it can be
* added to the area tree as a resolveable tree extension.
* This implements Resolvable and TreeExt so that it can be
* added to the area tree as a resolvable tree extension.
*/
public class BookmarkData implements Resolveable, TreeExt {
public class BookmarkData implements Resolvable, TreeExt {
private ArrayList subData = new ArrayList();
private HashMap idRefs = new HashMap();

@@ -146,34 +146,7 @@ public class BookmarkData implements Resolveable, TreeExt {
}

/**
* Check if this tree extension is resolveable.
*
* @return true since this also implements Resolveable
*/
public boolean isResolveable() {
return true;
}

/**
* Get the mime type of this area tree extension.
*
* @return this tree extension applies to pdf
*/
public String getMimeType() {
return "application/pdf";
}

/**
* Get the name of this area tree extension.
*
* @return the name of the PDF bookmark extension is "Bookmark"
*/
public String getName() {
return "Bookmark";
}

/**
* Check if this resolveable object has been resolved.
* Check if this resolvable object has been resolved.
* Once the id reference is null then it has been resolved.
*
* @return true if this has been resolved
@@ -193,7 +166,7 @@ public class BookmarkData implements Resolveable, TreeExt {
}

/**
* Resolve this resolveable object.
* Resolve this resolvable object.
* This resolves the id reference and if possible also
* resolves id references of child elements that have the same
* id reference.
@@ -230,7 +203,7 @@ public class BookmarkData implements Resolveable, TreeExt {
if (idRefs.size() == 0) {
idRefs = null;
if (areaTreeModel != null) {
areaTreeModel.addExtension(this, TreeExt.AFTER_PAGE);
areaTreeModel.handleExtension(this, TreeExt.AFTER_PAGE);
}
}
}

+ 4
- 4
src/java/org/apache/fop/area/inline/UnresolvedPageNumber.java View File

@@ -19,21 +19,21 @@
package org.apache.fop.area.inline;

import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.Resolvable;

import java.util.List;

/**
* Unresolveable page number area.
* Unresolvable page number area.
* This is a word area that resolves itself to a page number
* from an id reference.
*/
public class UnresolvedPageNumber extends TextArea implements Resolveable {
public class UnresolvedPageNumber extends TextArea implements Resolvable {
private boolean resolved = false;
private String pageRefId;

/**
* Create a new unresolveable page number.
* Create a new unresolvable page number.
*
* @param id the id reference for resolving this
*/

+ 1
- 1
src/java/org/apache/fop/fo/FObj.java View File

@@ -111,7 +111,7 @@ public class FObj extends FONode implements Constants {
* @throws SAXParseException
*/
public void bind(PropertyList pList) throws SAXParseException {
throw new SAXParseException("Unconverted element " + this, locator);
// throw new SAXParseException("Unconverted element " + this, locator);
}

/**

+ 2
- 2
src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java View File

@@ -21,7 +21,7 @@ package org.apache.fop.layoutmgr;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.FONode;
import org.apache.fop.area.Area;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.Resolvable;
import org.apache.fop.area.PageViewport;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.flow.Marker;
@@ -364,7 +364,7 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants
*
* @see org.apache.fop.layoutmgr.LayoutManager
*/
public void addUnresolvedArea(String id, Resolveable res) {
public void addUnresolvedArea(String id, Resolvable res) {
parentLM.addUnresolvedArea(id, res);
}


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

@@ -37,6 +37,7 @@ public class BasicLinkLayoutManager extends InlineStackingLayoutManager {
*/
public BasicLinkLayoutManager(BasicLink node) {
super(node);
fobj = node;
}

protected InlineParent createArea() {

+ 2
- 2
src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java View File

@@ -22,7 +22,7 @@ import org.apache.fop.fo.FObj;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.flow.Marker;
import org.apache.fop.area.Area;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.Resolvable;
import org.apache.fop.area.PageViewport;

import java.util.LinkedList;
@@ -234,7 +234,7 @@ public class ContentLayoutManager implements LayoutManager {
}

/** @see org.apache.fop.layoutmgr.LayoutManager */
public void addUnresolvedArea(String id, Resolveable res) {
public void addUnresolvedArea(String id, Resolvable res) {
parentLM.addUnresolvedArea(id, res);
}


+ 5
- 5
src/java/org/apache/fop/layoutmgr/LayoutManager.java View File

@@ -25,7 +25,7 @@ import java.util.Map;
import org.apache.fop.fo.flow.Marker;

import org.apache.fop.area.Area;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.Resolvable;
import org.apache.fop.area.PageViewport;
import org.apache.fop.fo.FObj;

@@ -166,7 +166,7 @@ public interface LayoutManager {
/**
* Resolve the id reference.
* This is called by an area looking for an id reference.
* If the id reference is not found then it should add a resolveable object.
* If the id reference is not found then it should add a resolvable object.
*
* @param ref the id reference
* @return the page containing the id reference or null if not found
@@ -183,12 +183,12 @@ public interface LayoutManager {

/**
* Add an unresolved area.
* The is used to add a resolveable object to the page for a given id.
* The is used to add a resolvable object to the page for a given id.
*
* @param id the id reference this object needs for resolving
* @param res the resolveable object
* @param res the resolvable object
*/
void addUnresolvedArea(String id, Resolveable res);
void addUnresolvedArea(String id, Resolvable res);

/**
* Add the marker.

+ 5
- 5
src/java/org/apache/fop/layoutmgr/LineLayoutManager.java View File

@@ -25,7 +25,7 @@ import org.apache.fop.fo.properties.CommonHyphenation;
import org.apache.fop.hyphenation.Hyphenation;
import org.apache.fop.hyphenation.Hyphenator;
import org.apache.fop.area.LineArea;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.Resolvable;

import java.util.ListIterator;
import java.util.Iterator;
@@ -1491,11 +1491,11 @@ public class LineLayoutManager extends InlineStackingLayoutManager {
* resolves the inline area and can do the necessary
* adjustments to the line and inline areas.
*
* @param id the id reference of the resolveable
* @param res the resolveable object
* @param id the id reference of the resolvable
* @param res the resolvable object
*/
public void addUnresolvedArea(String id, Resolveable res) {
// create a resolveable class that handles ipd
public void addUnresolvedArea(String id, Resolvable res) {
// create a resolvable class that handles ipd
// adjustment for the current line

parentLM.addUnresolvedArea(id, res);

+ 3
- 3
src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java View File

@@ -20,7 +20,7 @@ package org.apache.fop.layoutmgr;

import org.apache.fop.fo.flow.PageNumberCitation;
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.Resolvable;
import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.UnresolvedPageNumber;
@@ -58,7 +58,7 @@ public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager {
public void addAreas(PositionIterator posIter, LayoutContext context) {
super.addAreas(posIter, context);
if (!resolved) {
parentLM.addUnresolvedArea(fobj.getRefId(), (Resolveable) curArea);
parentLM.addUnresolvedArea(fobj.getRefId(), (Resolvable) curArea);
}
}
@@ -68,7 +68,7 @@ public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager {

/**
* if id can be resolved then simply return a word, otherwise
* return a resolveable area
* return a resolvable area
*/
private InlineArea getPageNumberCitationInlineArea(LayoutManager parentLM) {
PageViewport page = parentLM.resolveRefID(fobj.getRefId());

+ 5
- 5
src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java View File

@@ -35,7 +35,7 @@ import org.apache.fop.area.MainReference;
import org.apache.fop.area.Span;
import org.apache.fop.area.BeforeFloat;
import org.apache.fop.area.Footnote;
import org.apache.fop.area.Resolveable;
import org.apache.fop.area.Resolvable;
import org.apache.fop.area.Trait;

import org.apache.fop.datatypes.PercentBase;
@@ -330,14 +330,14 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager implements
* Add an unresolved area to the layout manager.
* The Page layout manager handles the unresolved ID
* reference by adding to the current page and then adding
* the page as a resolveable to the area tree.
* the page as a resolvable to the area tree.
* This is so that the area tree can resolve the reference
* and the page can serialize the resolvers if required.
*
* @param id the ID reference to add
* @param res the resolveable object that needs resolving
* @param res the resolvable object that needs resolving
*/
public void addUnresolvedArea(String id, Resolveable res) {
public void addUnresolvedArea(String id, Resolvable res) {
// add unresolved to tree
// adds to the page viewport so it can serialize
curPage.addUnresolvedID(id, res);
@@ -671,7 +671,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager implements
* See if need to generate a new page for a forced break condition.
*/
private boolean needNewPage(int breakValue) {
if (curPage.getPage().isEmpty()) {
if (curPage != null && curPage.getPage().isEmpty()) {
if (breakValue == Constants.PAGE) {
return false;
}

Loading…
Cancel
Save