You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ol...@apache.org on 2002/12/22 23:40:31 UTC
cvs commit: xml-fop/src/org/apache/fop/tools AreaTreeBuilder.java
olegt 2002/12/22 14:40:31
Modified: src/org/apache/fop/apps LayoutHandler.java
src/org/apache/fop/area AreaTree.java
CachedRenderPagesModel.java
src/org/apache/fop/tools AreaTreeBuilder.java
Added: src/org/apache/fop/area AreaTreeModel.java
RenderPagesModel.java StorePagesModel.java
Log:
AreaTreeModel and its implementations moved out of AreaTree class.
Revision Changes Path
1.10 +4 -6 xml-fop/src/org/apache/fop/apps/LayoutHandler.java
Index: LayoutHandler.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/LayoutHandler.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- LayoutHandler.java 18 Dec 2002 23:09:28 -0000 1.9
+++ LayoutHandler.java 22 Dec 2002 22:40:31 -0000 1.10
@@ -17,9 +17,7 @@
// FOP
import org.apache.fop.layout.FontInfo;
-import org.apache.fop.area.AreaTree;
-import org.apache.fop.area.Title;
-import org.apache.fop.area.TreeExt;
+import org.apache.fop.area.*;
import org.apache.fop.render.Renderer;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fo.pagination.LayoutMasterSet;
@@ -78,7 +76,7 @@
* The current AreaTree for the PageSequence being rendered.
*/
private AreaTree areaTree;
- private AreaTree.AreaTreeModel atModel;
+ private AreaTreeModel atModel;
/**
* @param outputStream the stream that the result is rendered to
@@ -225,7 +223,7 @@
* @param model the store pages model
* @throws FOPException if there is an error
*/
- private void processAreaTree(AreaTree.StorePagesModel model) throws FOPException {
+ private void processAreaTree(StorePagesModel model) throws FOPException {
int count = 0;
int seqc = model.getPageSequenceCount();
while (count < seqc) {
1.14 +1 -320 xml-fop/src/org/apache/fop/area/AreaTree.java
Index: AreaTree.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/area/AreaTree.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- AreaTree.java 29 Nov 2002 23:18:52 -0000 1.13
+++ AreaTree.java 22 Dec 2002 22:40:31 -0000 1.14
@@ -192,324 +192,5 @@
}
model.endDocument();
}
-
- /**
- * This is the model for the area tree object.
- * The model implementation can handle the page sequence,
- * page and extensions.
- */
- public abstract static class AreaTreeModel {
- /**
- * Start a page sequence on this model.
- * @param title the title of the new page sequence
- */
- public abstract void startPageSequence(Title title);
-
- /**
- * Add a page to this moel.
- * @param page the page to add to the model.
- */
- public abstract void addPage(PageViewport page);
-
- /**
- * Add an extension to this model.
- * @param ext the extension to add
- * @param when when the extension should be handled
- */
- public abstract void addExtension(TreeExt ext, int when);
-
- /**
- * Signal the end of the document for any processing.
- */
- public abstract void endDocument();
- }
-
- /**
- * This class stores all the pages in the document
- * for interactive agents.
- * The pages are stored and can be retrieved in any order.
- */
- public static class StorePagesModel extends AreaTreeModel {
- private List pageSequence = null;
- private List titles = new ArrayList();
- private List currSequence;
- private List extensions = new ArrayList();
-
- /**
- * Create a new store pages model
- */
- public StorePagesModel() {
- }
-
- /**
- * Start a new page sequence.
- * This creates a new list for the pages in the new page sequence.
- * @param title the title of the page sequence.
- */
- public void startPageSequence(Title title) {
- titles.add(title);
- if (pageSequence == null) {
- pageSequence = new ArrayList();
- }
- currSequence = new ArrayList();
- pageSequence.add(currSequence);
- }
-
- /**
- * Add a page.
- * @param page the page to add to the current page sequence
- */
- public void addPage(PageViewport page) {
- currSequence.add(page);
- }
-
- /**
- * Get the page sequence count.
- * @return the number of page sequences in the document.
- */
- public int getPageSequenceCount() {
- return pageSequence.size();
- }
-
- /**
- * Get the title for a page sequence.
- * @param count the page sequence count
- * @return the title of the page sequence
- */
- public Title getTitle(int count) {
- return (Title) titles.get(count);
- }
-
- /**
- * Get the page count.
- * @param seq the page sequence to count.
- * @return returns the number of pages in a page sequence
- */
- public int getPageCount(int seq) {
- List sequence = (List) pageSequence.get(seq);
- return sequence.size();
- }
-
- /**
- * Get the page for a position in the document.
- * @param seq the page sequence number
- * @param count the page count in the sequence
- * @return the PageViewport for the particular page
- */
- public PageViewport getPage(int seq, int count) {
- List sequence = (List) pageSequence.get(seq);
- return (PageViewport) sequence.get(count);
- }
-
- /**
- * 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
- */
- public void addExtension(TreeExt ext, int when) {
- int seq, page;
- switch(when) {
- case TreeExt.IMMEDIATELY:
- seq = pageSequence == null ? 0 : pageSequence.size();
- page = currSequence == null ? 0 : currSequence.size();
- break;
- case TreeExt.AFTER_PAGE:
- break;
- case TreeExt.END_OF_DOC:
- break;
- }
- extensions.add(ext);
- }
-
- /**
- * Get the list of extensions that apply at a particular
- * position in the document.
- * @param seq the page sequence number
- * @param count the page count in the sequence
- * @return the list of extensions
- */
- public List getExtensions(int seq, int count) {
- return null;
- }
-
- /**
- * Get the end of document extensions for this stroe pages model.
- * @return the list of end extensions
- */
- public List getEndExtensions() {
- return extensions;
- }
-
- /**
- * End document, do nothing.
- */
- public void endDocument() {
- }
- }
-
- /**
- * This uses the store pages model to store the pages
- * each page is either rendered if ready or prepared
- * for later rendering.
- * Once a page is rendered it is cleared to release the
- * contents but the PageViewport is retained. So even
- * though the pages are stored the contents are discarded.
- */
- public static class RenderPagesModel extends StorePagesModel {
- /**
- * The renderer that will render the pages.
- */
- protected Renderer renderer;
- /**
- * Pages that have been prepared but not rendered yet.
- */
- protected List prepared = new ArrayList();
- private List pendingExt = new ArrayList();
- private List endDocExt = new ArrayList();
-
- /**
- * Create a new render pages model with the given renderer.
- * @param rend the renderer to render pages to
- */
- public RenderPagesModel(Renderer rend) {
- renderer = rend;
- }
-
- /**
- * Start a new page sequence.
- * This tells the renderer that a new page sequence has
- * started with the given title.
- * @param title the title of the new page sequence
- */
- public void startPageSequence(Title title) {
- super.startPageSequence(title);
- renderer.startPageSequence(title);
- }
-
- /**
- * Add a page to the render page model.
- * If the page is finished it can be rendered immediately.
- * If the page needs resolving then if the renderer supports
- * out of order rendering it can prepare the page. Otherwise
- * the page is added to a queue.
- * @param page the page to add to the model
- */
- public void addPage(PageViewport page) {
- super.addPage(page);
-
- // for links the renderer needs to prepare the page
- // it is more appropriate to do this after queued pages but
- // it will mean that the renderer has not prepared a page that
- // could be referenced
- boolean done = renderer.supportsOutOfOrder() && page.isResolved();
- if (done) {
- try {
- renderer.renderPage(page);
- } catch (Exception e) {
- // use error handler to handle this FOP or IO Exception
- e.printStackTrace();
- }
- page.clear();
- } else {
- preparePage(page);
- }
-
-
- // check prepared pages
- boolean cont = checkPreparedPages(page);
-
- if (cont) {
- renderExtensions(pendingExt);
- pendingExt.clear();
- }
- }
-
- /**
- * Check prepared pages
- * @return true if the current page should be rendered
- * false if the renderer doesn't support out of order
- * rendering and there are pending pages
- */
- protected boolean checkPreparedPages(PageViewport newpage) {
- for (Iterator iter = prepared.iterator(); iter.hasNext();) {
- PageViewport p = (PageViewport)iter.next();
- if (p.isResolved()) {
- try {
- renderer.renderPage(p);
- } catch (Exception e) {
- // use error handler to handle this FOP or IO Exception
- e.printStackTrace();
- }
- p.clear();
- iter.remove();
- } else {
- // if keeping order then stop at first page not resolved
- if (!renderer.supportsOutOfOrder()) {
- break;
- }
- }
- }
- return renderer.supportsOutOfOrder() || prepared.isEmpty();
- }
-
- /**
- * Prepare a page.
- * An unresolved page can be prepared if the renderer supports
- * it and the page will be rendered later.
- * @param page the page to prepare
- */
- protected void preparePage(PageViewport page) {
- if (renderer.supportsOutOfOrder()) {
- renderer.preparePage(page);
- }
- prepared.add(page);
- }
-
- /**
- * 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
- */
- public void addExtension(TreeExt ext, int when) {
- switch(when) {
- case TreeExt.IMMEDIATELY:
- renderer.renderExtension(ext);
- break;
- case TreeExt.AFTER_PAGE:
- pendingExt.add(ext);
- break;
- case TreeExt.END_OF_DOC:
- endDocExt.add(ext);
- break;
- }
- }
-
- private void renderExtensions(List list) {
- for (int count = 0; count < list.size(); count++) {
- TreeExt ext = (TreeExt)list.get(count);
- renderer.renderExtension(ext);
- }
- }
-
- /**
- * End the document. Render any end document extensions.
- */
- public void endDocument() {
- // render any pages that had unresolved ids
- checkPreparedPages(null);
-
- renderExtensions(pendingExt);
- pendingExt.clear();
-
- renderExtensions(endDocExt);
- }
- }
-
}
1.5 +2 -2 xml-fop/src/org/apache/fop/area/CachedRenderPagesModel.java
Index: CachedRenderPagesModel.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/area/CachedRenderPagesModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CachedRenderPagesModel.java 29 Nov 2002 23:18:52 -0000 1.4
+++ CachedRenderPagesModel.java 22 Dec 2002 22:40:31 -0000 1.5
@@ -27,7 +27,7 @@
* the page contents to a file and once the page is resolved
* the contents a reloaded.
*/
-public class CachedRenderPagesModel extends AreaTree.RenderPagesModel {
+public class CachedRenderPagesModel extends RenderPagesModel {
private Map pageMap = new HashMap();
/**
1.1 xml-fop/src/org/apache/fop/area/AreaTreeModel.java
Index: AreaTreeModel.java
===================================================================
/*
* $Id: AreaTreeModel.java,v 1.1 2002/12/22 22:40:31 olegt Exp $
* Copyright (C) 2002 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.area;
/**
* This is the model for the area tree object.
* The model implementation can handle the page sequence,
* page and extensions.
*/
public abstract class AreaTreeModel {
/**
* Start a page sequence on this model.
* @param title the title of the new page sequence
*/
public abstract void startPageSequence(Title title);
/**
* Add a page to this moel.
* @param page the page to add to the model.
*/
public abstract void addPage(PageViewport page);
/**
* Add an extension to this model.
* @param ext the extension to add
* @param when when the extension should be handled
*/
public abstract void addExtension(TreeExt ext, int when);
/**
* Signal the end of the document for any processing.
*/
public abstract void endDocument();
}
1.1 xml-fop/src/org/apache/fop/area/RenderPagesModel.java
Index: RenderPagesModel.java
===================================================================
/*
* $Id: RenderPagesModel.java,v 1.1 2002/12/22 22:40:31 olegt Exp $
* Copyright (C) 2002 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.area;
// FOP
import org.apache.fop.render.Renderer;
// Java
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
/**
* This uses the store pages model to store the pages
* each page is either rendered if ready or prepared
* for later rendering.
* Once a page is rendered it is cleared to release the
* contents but the PageViewport is retained. So even
* though the pages are stored the contents are discarded.
*/
public class RenderPagesModel extends StorePagesModel {
/**
* The renderer that will render the pages.
*/
protected Renderer renderer;
/**
* Pages that have been prepared but not rendered yet.
*/
protected List prepared = new ArrayList();
private List pendingExt = new ArrayList();
private List endDocExt = new ArrayList();
/**
* Create a new render pages model with the given renderer.
* @param rend the renderer to render pages to
*/
public RenderPagesModel(Renderer rend) {
renderer = rend;
}
/**
* Start a new page sequence.
* This tells the renderer that a new page sequence has
* started with the given title.
* @param title the title of the new page sequence
*/
public void startPageSequence(Title title) {
super.startPageSequence(title);
renderer.startPageSequence(title);
}
/**
* Add a page to the render page model.
* If the page is finished it can be rendered immediately.
* If the page needs resolving then if the renderer supports
* out of order rendering it can prepare the page. Otherwise
* the page is added to a queue.
* @param page the page to add to the model
*/
public void addPage(PageViewport page) {
super.addPage(page);
// for links the renderer needs to prepare the page
// it is more appropriate to do this after queued pages but
// it will mean that the renderer has not prepared a page that
// could be referenced
boolean done = renderer.supportsOutOfOrder() && page.isResolved();
if (done) {
try {
renderer.renderPage(page);
} catch (Exception e) {
// use error handler to handle this FOP or IO Exception
e.printStackTrace();
}
page.clear();
} else {
preparePage(page);
}
// check prepared pages
boolean cont = checkPreparedPages(page);
if (cont) {
renderExtensions(pendingExt);
pendingExt.clear();
}
}
/**
* Check prepared pages
* @return true if the current page should be rendered
* false if the renderer doesn't support out of order
* rendering and there are pending pages
*/
protected boolean checkPreparedPages(PageViewport newpage) {
for (Iterator iter = prepared.iterator(); iter.hasNext();) {
PageViewport p = (PageViewport)iter.next();
if (p.isResolved()) {
try {
renderer.renderPage(p);
} catch (Exception e) {
// use error handler to handle this FOP or IO Exception
e.printStackTrace();
}
p.clear();
iter.remove();
} else {
// if keeping order then stop at first page not resolved
if (!renderer.supportsOutOfOrder()) {
break;
}
}
}
return renderer.supportsOutOfOrder() || prepared.isEmpty();
}
/**
* Prepare a page.
* An unresolved page can be prepared if the renderer supports
* it and the page will be rendered later.
* @param page the page to prepare
*/
protected void preparePage(PageViewport page) {
if (renderer.supportsOutOfOrder()) {
renderer.preparePage(page);
}
prepared.add(page);
}
/**
* 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
*/
public void addExtension(TreeExt ext, int when) {
switch(when) {
case TreeExt.IMMEDIATELY:
renderer.renderExtension(ext);
break;
case TreeExt.AFTER_PAGE:
pendingExt.add(ext);
break;
case TreeExt.END_OF_DOC:
endDocExt.add(ext);
break;
}
}
private void renderExtensions(List list) {
for (int count = 0; count < list.size(); count++) {
TreeExt ext = (TreeExt)list.get(count);
renderer.renderExtension(ext);
}
}
/**
* End the document. Render any end document extensions.
*/
public void endDocument() {
// render any pages that had unresolved ids
checkPreparedPages(null);
renderExtensions(pendingExt);
pendingExt.clear();
renderExtensions(endDocExt);
}
}
1.1 xml-fop/src/org/apache/fop/area/StorePagesModel.java
Index: StorePagesModel.java
===================================================================
/*
* $Id: StorePagesModel.java,v 1.1 2002/12/22 22:40:31 olegt Exp $
* Copyright (C) 2002 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.area;
// Java
import java.util.List;
import java.util.ArrayList;
/**
* This class stores all the pages in the document
* for interactive agents.
* The pages are stored and can be retrieved in any order.
*/
public class StorePagesModel extends AreaTreeModel {
private List pageSequence = null;
private List titles = new ArrayList();
private List currSequence;
private List extensions = new ArrayList();
/**
* Create a new store pages model
*/
public StorePagesModel() {
}
/**
* Start a new page sequence.
* This creates a new list for the pages in the new page sequence.
* @param title the title of the page sequence.
*/
public void startPageSequence(Title title) {
titles.add(title);
if (pageSequence == null) {
pageSequence = new ArrayList();
}
currSequence = new ArrayList();
pageSequence.add(currSequence);
}
/**
* Add a page.
* @param page the page to add to the current page sequence
*/
public void addPage(PageViewport page) {
currSequence.add(page);
}
/**
* Get the page sequence count.
* @return the number of page sequences in the document.
*/
public int getPageSequenceCount() {
return pageSequence.size();
}
/**
* Get the title for a page sequence.
* @param count the page sequence count
* @return the title of the page sequence
*/
public Title getTitle(int count) {
return (Title) titles.get(count);
}
/**
* Get the page count.
* @param seq the page sequence to count.
* @return returns the number of pages in a page sequence
*/
public int getPageCount(int seq) {
List sequence = (List) pageSequence.get(seq);
return sequence.size();
}
/**
* Get the page for a position in the document.
* @param seq the page sequence number
* @param count the page count in the sequence
* @return the PageViewport for the particular page
*/
public PageViewport getPage(int seq, int count) {
List sequence = (List) pageSequence.get(seq);
return (PageViewport) sequence.get(count);
}
/**
* 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
*/
public void addExtension(TreeExt ext, int when) {
int seq, page;
switch(when) {
case TreeExt.IMMEDIATELY:
seq = pageSequence == null ? 0 : pageSequence.size();
page = currSequence == null ? 0 : currSequence.size();
break;
case TreeExt.AFTER_PAGE:
break;
case TreeExt.END_OF_DOC:
break;
}
extensions.add(ext);
}
/**
* Get the list of extensions that apply at a particular
* position in the document.
* @param seq the page sequence number
* @param count the page count in the sequence
* @return the list of extensions
*/
public List getExtensions(int seq, int count) {
return null;
}
/**
* Get the end of document extensions for this stroe pages model.
* @return the list of end extensions
*/
public List getEndExtensions() {
return extensions;
}
/**
* End document, do nothing.
*/
public void endDocument() {
}
}
1.14 +11 -8 xml-fop/src/org/apache/fop/tools/AreaTreeBuilder.java
Index: AreaTreeBuilder.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/tools/AreaTreeBuilder.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- AreaTreeBuilder.java 4 Sep 2002 08:36:36 -0000 1.13
+++ AreaTreeBuilder.java 22 Dec 2002 22:40:31 -0000 1.14
@@ -7,7 +7,7 @@
package org.apache.fop.tools;
-import org.apache.fop.apps.*;
+// FOP
import org.apache.fop.area.*;
import org.apache.fop.area.inline.*;
import org.apache.fop.area.inline.Character;
@@ -21,21 +21,24 @@
import org.apache.fop.fo.FOUserAgent;
import org.apache.fop.fo.properties.RuleStyle;
+// Avalon
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+// Java
import java.io.*;
import java.util.*;
-
import java.awt.geom.Rectangle2D;
import java.util.StringTokenizer;
+// JAXP
import javax.xml.parsers.DocumentBuilderFactory;
+// DOM
import org.w3c.dom.*;
+// Batik
import org.apache.batik.dom.svg.SVGDOMImplementation;
-import org.apache.batik.dom.util.DOMUtilities;
/**
* Area tree tester.
@@ -88,7 +91,7 @@
setupLogger(ua);
rend.setUserAgent(ua);
- AreaTree.StorePagesModel sm = AreaTree.createStorePagesModel();
+ StorePagesModel sm = AreaTree.createStorePagesModel();
TreeLoader tl = new TreeLoader(fi);
tl.setTreeModel(sm);
try {
@@ -101,7 +104,7 @@
}
}
- protected void renderAreaTree(AreaTree.StorePagesModel sm,
+ protected void renderAreaTree(StorePagesModel sm,
Renderer rend, String out) {
try {
OutputStream os =
@@ -153,7 +156,7 @@
// the xml format is the same as the xml renderer output
class TreeLoader {
AreaTree areaTree;
- AreaTree.AreaTreeModel model;
+ AreaTreeModel model;
FontInfo fontInfo;
FontState currentFontState;
@@ -161,7 +164,7 @@
fontInfo = fi;
}
- public void setTreeModel(AreaTree.AreaTreeModel mo) {
+ public void setTreeModel(AreaTreeModel mo) {
model = mo;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org