aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache
diff options
context:
space:
mode:
authorKeiron Liddle <keiron@apache.org>2002-05-27 12:34:19 +0000
committerKeiron Liddle <keiron@apache.org>2002-05-27 12:34:19 +0000
commit07b58c1b5e179a7e076a54b05cd03b0466ed57b4 (patch)
tree017049c62daa31ceca08c10e28061c3742370e52 /src/org/apache
parent812824bfbeef3b218807e358750f5a581e0c5d75 (diff)
downloadxmlgraphics-fop-07b58c1b5e179a7e076a54b05cd03b0466ed57b4.tar.gz
xmlgraphics-fop-07b58c1b5e179a7e076a54b05cd03b0466ed57b4.zip
start of structure handler concept and adjusted the layout
handling appropriately git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194842 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache')
-rw-r--r--src/org/apache/fop/apps/Driver.java6
-rw-r--r--src/org/apache/fop/apps/Fop.java4
-rw-r--r--src/org/apache/fop/apps/LayoutHandler.java (renamed from src/org/apache/fop/apps/StreamRenderer.java)136
-rw-r--r--src/org/apache/fop/apps/StructureHandler.java219
-rw-r--r--src/org/apache/fop/extensions/Bookmarks.java7
-rw-r--r--src/org/apache/fop/fo/FONode.java4
-rw-r--r--src/org/apache/fop/fo/FOTreeBuilder.java16
-rw-r--r--src/org/apache/fop/fo/FObj.java10
-rw-r--r--src/org/apache/fop/fo/FObjMixed.java5
-rw-r--r--src/org/apache/fop/fo/flow/Block.java1
-rw-r--r--src/org/apache/fop/fo/pagination/PageSequence.java13
-rw-r--r--src/org/apache/fop/layout/AreaTree.java6
12 files changed, 309 insertions, 118 deletions
diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java
index e67443bcf..5c4d98c0f 100644
--- a/src/org/apache/fop/apps/Driver.java
+++ b/src/org/apache/fop/apps/Driver.java
@@ -453,11 +453,11 @@ public class Driver {
* events but isn't a SAX Parser itself.
*/
public ContentHandler getContentHandler() {
- StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer);
- streamRenderer.setLogger(getLogger());
+ StructureHandler handler = new LayoutHandler(_stream, _renderer, true);
+ handler.setLogger(getLogger());
_treeBuilder.setLogger(getLogger());
_treeBuilder.setUserAgent(getUserAgent());
- _treeBuilder.setStreamRenderer(streamRenderer);
+ _treeBuilder.setStructHandler(handler);
return _treeBuilder;
}
diff --git a/src/org/apache/fop/apps/Fop.java b/src/org/apache/fop/apps/Fop.java
index 4dc42dcfb..7b170a7e2 100644
--- a/src/org/apache/fop/apps/Fop.java
+++ b/src/org/apache/fop/apps/Fop.java
@@ -17,8 +17,8 @@ public class Fop {
Starter starter = options.getStarter();
starter.run();
} catch (FOPException e) {
- if("null".equals(e.getMessage())) {
- System.err.println("NullPointerException");
+ if("null".equals("" + e.getMessage())) {
+ System.err.println("Exception occured with a null error message");
} else {
System.err.println("" + e.getMessage());
}
diff --git a/src/org/apache/fop/apps/StreamRenderer.java b/src/org/apache/fop/apps/LayoutHandler.java
index 74c545360..ba4bdc04a 100644
--- a/src/org/apache/fop/apps/StreamRenderer.java
+++ b/src/org/apache/fop/apps/LayoutHandler.java
@@ -16,38 +16,32 @@ import org.apache.fop.fo.pagination.PageSequence;
import org.apache.avalon.framework.logger.Logger;
/**
- This class acts as a bridge between the XML:FO parser
- and the formatting/rendering classes. It will queue
- PageSequences up until all the IDs required by them
- are satisfied, at which time it will render the
- pages.<P>
-
- StreamRenderer is created by Driver and called from
- FOTreeBuilder when a PageSequence is created,
- and AreaTree when a Page is formatted.<P>
-*/
-public class StreamRenderer {
+ * Layout handler that receives the structure events.
+ * This initiates layout processes and corresponding
+ * rendering processes such as start/end.
+ */
+public class LayoutHandler extends StructureHandler {
private static final boolean MEM_PROFILE_WITH_GC = false;
/**
Somewhere to get our stats from.
- */
+ */
private Runtime runtime = Runtime.getRuntime();
/**
Keep track of the number of pages rendered.
- */
+ */
int pageCount = 0;
/**
Keep track of heap memory allocated,
for statistical purposes.
- */
+ */
private long initialMemory;
/**
Keep track of time used by renderer.
- */
+ */
private long startTime;
/**
@@ -55,34 +49,33 @@ public class StreamRenderer {
written to. <B>Note</B> that some renderers
do not render to a stream, and that this
member can therefore be null.
- */
+ */
private OutputStream outputStream;
/**
The renderer being used.
- */
+ */
private Renderer renderer;
/**
The FontInfo for this renderer.
- */
+ */
private FontInfo fontInfo = new FontInfo();
/**
- The current set of id's in the FO tree
- This is used so we know if the FO tree contains duplicates
- */
- private HashSet idReferences = new HashSet();
-
- private Logger log;
-
- /**
* The current AreaTree for the PageSequence being rendered.
*/
private AreaTree areaTree;
private AreaTree.StorePagesModel atModel;
- public StreamRenderer(OutputStream outputStream, Renderer renderer) {
+ /**
+ * @param outputStream the stream that the result is rendered to
+ * @param renderer the renderer to call
+ * @param store if true then use the store pages model and keep the
+ * area tree in memory
+ */
+ public LayoutHandler(OutputStream outputStream, Renderer renderer,
+ boolean store) {
this.outputStream = outputStream;
this.renderer = renderer;
@@ -91,24 +84,15 @@ public class StreamRenderer {
areaTree.setTreeModel(atModel);
}
- public void setLogger(Logger logger) {
- log = logger;
- }
-
- public HashSet getIDReferences() {
- return idReferences;
- }
-
public AreaTree getAreaTree() {
return areaTree;
}
- public void startRenderer()
- throws SAXException {
+ public void startDocument() throws SAXException {
pageCount = 0;
if (MEM_PROFILE_WITH_GC)
- System.gc(); // This takes time but gives better results
+ System.gc(); // This takes time but gives better results
initialMemory = runtime.totalMemory() - runtime.freeMemory();
startTime = System.currentTimeMillis();
@@ -121,15 +105,14 @@ public class StreamRenderer {
}
}
- public void stopRenderer()
- throws SAXException {
+ public void endDocument() throws SAXException {
/*
- Force the processing of any more queue elements,
- even if they are not resolved.
- */
+ Force the processing of any more queue elements,
+ even if they are not resolved.
+ */
try {
//processQueue(true);
- processAreaTree();
+ processAreaTree();
renderer.stopRenderer();
} catch (FOPException e) {
throw new SAXException(e);
@@ -139,13 +122,13 @@ public class StreamRenderer {
}
if (MEM_PROFILE_WITH_GC)
- System.gc(); // This takes time but gives better results
+ System.gc(); // This takes time but gives better results
long memoryNow = runtime.totalMemory() - runtime.freeMemory();
long memoryUsed = (memoryNow - initialMemory) / 1024L;
- log.debug("Initial heap size: " + (initialMemory/1024L) + "Kb");
- log.debug("Current heap size: " + (memoryNow/1024L) + "Kb");
+ log.debug("Initial heap size: " + (initialMemory / 1024L) + "Kb");
+ log.debug("Current heap size: " + (memoryNow / 1024L) + "Kb");
log.debug("Total memory used: " + memoryUsed + "Kb");
if (!MEM_PROFILE_WITH_GC) {
@@ -161,45 +144,46 @@ public class StreamRenderer {
}
/**
- Format the PageSequence. The PageSequence
- formats Pages and adds them to the AreaTree,
- which subsequently calls the StreamRenderer
- instance (this) again to render the page.
- At this time the page might be printed
- or it might be queued. A page might not
- be renderable immediately if the IDReferences
- are not all valid. In this case we defer
- the rendering until they are all valid.
- */
- public void render(PageSequence pageSequence)
+ Format the PageSequence. The PageSequence
+ formats Pages and adds them to the AreaTree,
+ which subsequently calls the StreamRenderer
+ instance (this) again to render the page.
+ At this time the page might be printed
+ or it might be queued. A page might not
+ be renderable immediately if the IDReferences
+ are not all valid. In this case we defer
+ the rendering until they are all valid.
+ */
+ public void endPageSequence(PageSequence pageSequence)
throws FOPException {
//areaTree.setFontInfo(fontInfo);
- pageSequence.format(areaTree);
+ pageSequence.format(areaTree);
}
private void processAreaTree() throws FOPException {
- int count = 0;
- int seqc = atModel.getPageSequenceCount();
- while (count < seqc) {
- Title title = atModel.getTitle(count);
- renderer.startPageSequence(title);
- int pagec = atModel.getPageCount(count);
- for (int c=0; c < pagec; c++) {
- try {
- renderer.renderPage(atModel.getPage(count, c));
- } catch (java.io.IOException ioex) {
- throw new FOPException("I/O Error rendering page", ioex);
- }
- }
- count++;
- }
-
+ int count = 0;
+ int seqc = atModel.getPageSequenceCount();
+ while (count < seqc) {
+ Title title = atModel.getTitle(count);
+ renderer.startPageSequence(title);
+ int pagec = atModel.getPageCount(count);
+ for (int c = 0; c < pagec; c++) {
+ try {
+ renderer.renderPage(atModel.getPage(count, c));
+ } catch (java.io.IOException ioex) {
+ throw new FOPException("I/O Error rendering page",
+ ioex);
+ }
+ }
+ count++;
+ }
+
}
public FontInfo getFontInfo() {
- return this.fontInfo;
+ return this.fontInfo;
}
}
diff --git a/src/org/apache/fop/apps/StructureHandler.java b/src/org/apache/fop/apps/StructureHandler.java
new file mode 100644
index 000000000..3eb716331
--- /dev/null
+++ b/src/org/apache/fop/apps/StructureHandler.java
@@ -0,0 +1,219 @@
+/*
+ * $Id$
+ * 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.
+ */
+
+package org.apache.fop.apps;
+
+// Java
+import java.util.HashSet;
+
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.fop.fo.pagination.PageSequence;
+import org.apache.fop.layout.FontInfo;
+
+import org.xml.sax.SAXException;
+
+/**
+ * This class receives structure events from the FO Tree.
+ * Sub-classes can then implement various methods to handle
+ * the FO Tree when the SAX events occur.
+ */
+public class StructureHandler {
+ /**
+ The current set of id's in the FO tree
+ This is used so we know if the FO tree contains duplicates
+ */
+ private HashSet idReferences = new HashSet();
+ protected Logger log;
+
+ public StructureHandler() {
+ }
+
+ public void setLogger(Logger logger) {
+ log = logger;
+ }
+
+ public HashSet getIDReferences() {
+ return idReferences;
+ }
+
+ public FontInfo getFontInfo() {
+ return null;
+ }
+
+ public void startDocument() throws SAXException {
+
+ }
+
+ public void endDocument() throws SAXException {
+
+ }
+
+ public void startPageSequence() {
+
+ }
+
+ public void endPageSequence(PageSequence pageSeq) throws FOPException {
+
+ }
+
+ public void setPageInfo() {
+
+ }
+
+ public void startBlock() {
+
+ }
+
+ public void endBlock() {
+
+ }
+
+
+ // Tables
+ public void startTable() {
+
+ }
+
+ public void endTable() {
+
+ }
+
+ public void startHeader() {
+
+ }
+
+ public void endHeader() {
+
+ }
+
+ public void startFooter() {
+
+ }
+
+ public void endFooter() {
+
+ }
+
+ public void startBody() {
+
+ }
+
+ public void endBody() {
+
+ }
+
+ public void startRow() {
+
+ }
+
+ public void endRow() {
+
+ }
+
+ public void startCell() {
+
+ }
+
+ public void endCell() {
+
+ }
+
+
+ // Lists
+ public void startList() {
+
+ }
+
+ public void endList() {
+
+ }
+
+ public void startListItem() {
+
+ }
+
+ public void endListItem() {
+
+ }
+
+ public void startListLabel() {
+
+ }
+
+ public void endListLabel() {
+
+ }
+
+ public void startListBody() {
+
+ }
+
+ public void endListBody() {
+
+ }
+
+
+ // Static Regions
+ public void startStatic() {
+
+ }
+
+ public void endStatic() {
+
+ }
+
+
+ public void startMarkup() {
+
+ }
+
+ public void endMarkup() {
+
+ }
+
+
+ public void startLink() {
+
+ }
+
+ public void endLink() {
+
+ }
+
+
+ public void image() {
+
+ }
+
+ public void pageRef() {
+
+ }
+
+ public void foreignObject() {
+
+ }
+
+ public void footnote() {
+
+ }
+
+ public void leader() {
+
+ }
+
+
+ public void characters() {
+
+ }
+
+ public void pageBreak() {
+
+ }
+
+
+}
+
diff --git a/src/org/apache/fop/extensions/Bookmarks.java b/src/org/apache/fop/extensions/Bookmarks.java
index 03ac929f6..4a4415ea0 100644
--- a/src/org/apache/fop/extensions/Bookmarks.java
+++ b/src/org/apache/fop/extensions/Bookmarks.java
@@ -7,6 +7,7 @@
package org.apache.fop.extensions;
+import org.apache.fop.apps.LayoutHandler;
import org.apache.fop.fo.FONode;
import org.apache.fop.area.AreaTree;
@@ -40,8 +41,10 @@ public class Bookmarks extends ExtensionObj {
data.addSubData(out.getData());
}
// add data to area tree for resolving and handling
- AreaTree at = streamRenderer.getAreaTree();
- at.addTreeExtension(data);
+ if(structHandler instanceof LayoutHandler) {
+ AreaTree at = ((LayoutHandler)structHandler).getAreaTree();
+ at.addTreeExtension(data);
+ }
}
}
diff --git a/src/org/apache/fop/fo/FONode.java b/src/org/apache/fop/fo/FONode.java
index 2e0dc72d8..ee0b6ad6a 100644
--- a/src/org/apache/fop/fo/FONode.java
+++ b/src/org/apache/fop/fo/FONode.java
@@ -9,7 +9,7 @@ package org.apache.fop.fo;
// FOP
import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.StreamRenderer;
+import org.apache.fop.apps.StructureHandler;
import org.apache.fop.layout.Area;
import org.apache.fop.util.CharUtilities;
@@ -48,7 +48,7 @@ abstract public class FONode {
userAgent = ua;
}
- public void setStreamRenderer(StreamRenderer st) {
+ public void setStructHandler(StructureHandler st) {
}
public void handleAttrs(Attributes attlist) throws FOPException {
diff --git a/src/org/apache/fop/fo/FOTreeBuilder.java b/src/org/apache/fop/fo/FOTreeBuilder.java
index 988f7739f..946007d32 100644
--- a/src/org/apache/fop/fo/FOTreeBuilder.java
+++ b/src/org/apache/fop/fo/FOTreeBuilder.java
@@ -10,7 +10,7 @@ package org.apache.fop.fo;
// FOP
import org.apache.fop.layout.AreaTree;
import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.StreamRenderer;
+import org.apache.fop.apps.StructureHandler;
import org.apache.fop.fo.pagination.Root;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.extensions.ExtensionObj;
@@ -70,7 +70,7 @@ public class FOTreeBuilder extends DefaultHandler {
* The class that handles formatting and rendering to a stream
* (mark-fop@inomial.com)
*/
- private StreamRenderer streamRenderer;
+ private StructureHandler structHandler;
private Logger log;
private FOUserAgent userAgent;
@@ -89,8 +89,8 @@ public class FOTreeBuilder extends DefaultHandler {
}
- public void setStreamRenderer(StreamRenderer streamRenderer) {
- this.streamRenderer = streamRenderer;
+ public void setStructHandler(StructureHandler sh) {
+ this.structHandler = sh;
}
/**
@@ -131,13 +131,13 @@ public class FOTreeBuilder extends DefaultHandler {
throws SAXException {
rootFObj = null; // allows FOTreeBuilder to be reused
log.info("building formatting object tree");
- streamRenderer.startRenderer();
+ structHandler.startDocument();
}
public void endDocument()
throws SAXException {
log.info("Parsing of document complete, stopping renderer");
- streamRenderer.stopRenderer();
+ structHandler.endDocument();
}
/**
@@ -185,7 +185,7 @@ public class FOTreeBuilder extends DefaultHandler {
fobj.setUserAgent(userAgent);
// set the stream renderer so that appropriate
// elements can add pages and handle resolving references
- fobj.setStreamRenderer(streamRenderer);
+ fobj.setStructHandler(structHandler);
fobj.handleAttrs(attlist);
} catch (FOPException e) {
@@ -209,7 +209,7 @@ public class FOTreeBuilder extends DefaultHandler {
public void reset() {
currentFObj = null;
rootFObj = null;
- streamRenderer = null;
+ structHandler = null;
}
public boolean hasData() {
diff --git a/src/org/apache/fop/fo/FObj.java b/src/org/apache/fop/fo/FObj.java
index 6e4219223..7be9fb522 100644
--- a/src/org/apache/fop/fo/FObj.java
+++ b/src/org/apache/fop/fo/FObj.java
@@ -11,7 +11,7 @@ package org.apache.fop.fo;
import org.apache.fop.layout.Area;
import org.apache.fop.layout.AreaClass;
import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.StreamRenderer;
+import org.apache.fop.apps.StructureHandler;
import org.apache.fop.layoutmgr.LayoutManager;
import org.apache.fop.fo.properties.FOPropertyMapping;
import org.apache.fop.layout.Area;
@@ -34,7 +34,7 @@ import java.util.HashSet;
* base class for representation of formatting objects and their processing
*/
public class FObj extends FONode {
- protected StreamRenderer streamRenderer;
+ protected StructureHandler structHandler;
public PropertyList properties;
protected PropertyManager propMgr;
protected String areaClass = AreaClass.UNASSIGNED;
@@ -135,8 +135,8 @@ public class FObj extends FONode {
children.add(child);
}
- public void setStreamRenderer(StreamRenderer st) {
- streamRenderer = st;
+ public void setStructHandler(StructureHandler st) {
+ structHandler = st;
}
/**
@@ -154,7 +154,7 @@ public class FObj extends FONode {
if(prop != null) {
String str = prop.getString();
if(str != null && !str.equals("")) {
- HashSet idrefs = streamRenderer.getIDReferences();
+ HashSet idrefs = structHandler.getIDReferences();
if(!idrefs.contains(str)) {
id = str;
idrefs.add(id);
diff --git a/src/org/apache/fop/fo/FObjMixed.java b/src/org/apache/fop/fo/FObjMixed.java
index a21732c1a..93cad8758 100644
--- a/src/org/apache/fop/fo/FObjMixed.java
+++ b/src/org/apache/fop/fo/FObjMixed.java
@@ -11,7 +11,7 @@ import org.apache.fop.layout.Area;
import org.apache.fop.layout.FontState;
import org.apache.fop.layout.FontInfo;
import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.StreamRenderer;
+import org.apache.fop.apps.StructureHandler;
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.layoutmgr.InlineStackingBPLayoutManager;
import org.apache.fop.layoutmgr.LMiter;
@@ -30,7 +30,8 @@ public class FObjMixed extends FObj {
super(parent);
}
- public void setStreamRenderer(StreamRenderer st) {
+ public void setStructHandler(StructureHandler st) {
+ super.setStructHandler(st);
fontInfo = st.getFontInfo();
}
diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java
index 9fb9c9e83..5483ea685 100644
--- a/src/org/apache/fop/fo/flow/Block.java
+++ b/src/org/apache/fop/fo/flow/Block.java
@@ -16,7 +16,6 @@ import org.apache.fop.apps.FOPException;
import org.apache.fop.layoutmgr.LayoutManager;
import org.apache.fop.layoutmgr.BlockLayoutManager;
import org.apache.fop.util.CharUtilities;
-import org.apache.fop.apps.StreamRenderer;
import org.xml.sax.Attributes;
diff --git a/src/org/apache/fop/fo/pagination/PageSequence.java b/src/org/apache/fop/fo/pagination/PageSequence.java
index 591df45f7..3b75628cb 100644
--- a/src/org/apache/fop/fo/pagination/PageSequence.java
+++ b/src/org/apache/fop/fo/pagination/PageSequence.java
@@ -21,7 +21,6 @@ import org.apache.fop.layout.PageMaster;
import org.apache.fop.area.AreaTree;
import org.apache.fop.area.PageViewport;
import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.StreamRenderer;
import org.apache.fop.layoutmgr.PageLayoutManager;
@@ -48,11 +47,6 @@ public class PageSequence extends FObj {
// associations
//
/**
- * Use to layout and render the page sequence.
- */
- private StreamRenderer streamRenderer;
-
- /**
* The parent root object
*/
private Root root;
@@ -271,14 +265,9 @@ public class PageSequence extends FObj {
}
}
-
- public void setStreamRenderer(StreamRenderer st) {
- this.streamRenderer = st;
- }
-
public void end() {
try {
- this.streamRenderer.render(this);
+ this.structHandler.endPageSequence(this);
} catch (FOPException fopex) {
log.error("Error in PageSequence.end(): " +
fopex.getMessage());
diff --git a/src/org/apache/fop/layout/AreaTree.java b/src/org/apache/fop/layout/AreaTree.java
index 234e77de9..12554efd0 100644
--- a/src/org/apache/fop/layout/AreaTree.java
+++ b/src/org/apache/fop/layout/AreaTree.java
@@ -9,7 +9,6 @@ package org.apache.fop.layout;
// FOP
import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.StreamRenderer;
import org.apache.fop.fo.flow.StaticContent;
import org.apache.fop.svg.*;
import org.apache.fop.render.Renderer;
@@ -49,10 +48,7 @@ public class AreaTree {
*/
Vector rootExtensions = null;
- private StreamRenderer streamRenderer;
-
- public AreaTree(StreamRenderer streamRenderer) {
- this.streamRenderer = streamRenderer;
+ public AreaTree() {
}
public void setFontInfo(FontInfo fontInfo) {