aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop
diff options
context:
space:
mode:
authorGlen Mazza <gmazza@apache.org>2004-05-18 11:42:08 +0000
committerGlen Mazza <gmazza@apache.org>2004-05-18 11:42:08 +0000
commit922918acfefd17dd6487f1f0b2bb43a016ae2be5 (patch)
treef85eb1d454d683a586b8946fba0d03e167e24eed /src/java/org/apache/fop
parente1d05fb542d88054deff0fe0ff01dd01fc401294 (diff)
downloadxmlgraphics-fop-922918acfefd17dd6487f1f0b2bb43a016ae2be5.tar.gz
xmlgraphics-fop-922918acfefd17dd6487f1f0b2bb43a016ae2be5.zip
Folded the layout strategy into apps.Document.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197605 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r--src/java/org/apache/fop/apps/Document.java141
-rw-r--r--src/java/org/apache/fop/apps/Driver.java26
-rw-r--r--src/java/org/apache/fop/layout/LayoutStrategy.java64
-rw-r--r--src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java5
-rw-r--r--src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java5
-rw-r--r--src/java/org/apache/fop/layoutmgr/LMiter.java2
-rw-r--r--src/java/org/apache/fop/layoutmgr/LayoutManager.java6
-rw-r--r--src/java/org/apache/fop/layoutmgr/LayoutManagerLS.java141
-rw-r--r--src/java/org/apache/fop/layoutmgr/PageLayoutManager.java18
9 files changed, 135 insertions, 273 deletions
diff --git a/src/java/org/apache/fop/apps/Document.java b/src/java/org/apache/fop/apps/Document.java
index 520552cad..ae3ab2a83 100644
--- a/src/java/org/apache/fop/apps/Document.java
+++ b/src/java/org/apache/fop/apps/Document.java
@@ -24,22 +24,25 @@ import java.io.IOException;
import java.util.Set;
import java.util.HashSet;
-
// FOP
-import org.apache.fop.apps.FOUserAgent;
-
import org.apache.fop.area.AreaTree;
import org.apache.fop.area.AreaTreeControl;
import org.apache.fop.area.AreaTreeModel;
+import org.apache.fop.area.Title;
-import org.apache.fop.fo.extensions.Bookmarks;
import org.apache.fop.fo.FOInputHandler;
import org.apache.fop.fo.FOTreeControl;
import org.apache.fop.fo.FOTreeEvent;
import org.apache.fop.fo.FOTreeListener;
+import org.apache.fop.fo.extensions.Bookmarks;
import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.layout.LayoutStrategy;
+import org.apache.fop.layoutmgr.AddLMVisitor;
+import org.apache.fop.layoutmgr.ContentLayoutManager;
+import org.apache.fop.layoutmgr.InlineStackingLayoutManager;
+import org.apache.fop.layoutmgr.LMiter;
+import org.apache.fop.layoutmgr.PageLayoutManager;
+
import org.apache.commons.logging.Log;
@@ -59,13 +62,6 @@ public class Document implements FOTreeControl, FOTreeListener,
/** The Font information relevant for this document */
private FontInfo fontInfo;
- /**
- * the LayoutStrategy to be used to process this document
- * TODO: this actually belongs in the RenderContext class, when it is
- * created
- */
- private LayoutStrategy layoutStrategy = null;
-
/** The current AreaTree for the PageSequence being rendered. */
public AreaTree areaTree;
@@ -74,6 +70,10 @@ public class Document implements FOTreeControl, FOTreeListener,
private Bookmarks bookmarks = null;
+ /** Useful only for allowing subclasses of AddLMVisitor to be set by those
+ extending FOP **/
+ private AddLMVisitor addLMVisitor = null;
+
/**
* The current set of id's in the FO tree.
* This is used so we know if the FO tree contains duplicates.
@@ -104,21 +104,6 @@ public class Document implements FOTreeControl, FOTreeListener,
}
/**
- * Set the LayoutStrategy to be used to process this Document
- * @param ls the LayoutStrategy object to be used to process this Document
- */
- public void setLayoutStrategy(LayoutStrategy ls) {
- this.layoutStrategy = ls;
- }
-
- /**
- * @return this Document's LayoutStrategy object
- */
- public LayoutStrategy getLayoutStrategy () {
- return layoutStrategy;
- }
-
- /**
* Public accessor for the parent Driver of this Document
* @return the parent Driver for this Document
*/
@@ -135,7 +120,7 @@ public class Document implements FOTreeControl, FOTreeListener,
public void foPageSequenceComplete (FOTreeEvent event) throws FOPException {
PageSequence pageSeq = event.getPageSequence();
areaTree.addBookmarksToAreaTree();
- layoutStrategy.format(pageSeq, areaTree);
+ format(pageSeq, areaTree);
}
/**
@@ -195,4 +180,104 @@ public class Document implements FOTreeControl, FOTreeListener,
return foInputHandler;
}
+ /**
+ * Runs the formatting of this page sequence into the given area tree
+ *
+ * @param pageSeq the PageSequence to be formatted
+ * @param areaTree the area tree to format this page sequence into
+ * @throws FOPException if there is an error formatting the contents
+ */
+ public void format(PageSequence pageSeq, AreaTree areaTree) throws FOPException {
+ Title title = null;
+ if (pageSeq.getTitleFO() != null) {
+ title = getTitleArea(pageSeq.getTitleFO());
+ }
+ areaTree.startPageSequence(title);
+ // Make a new PageLayoutManager and a FlowLayoutManager
+ // Run the PLM in a thread
+ // Wait for them to finish.
+
+ // If no main flow, nothing to layout!
+ if (pageSeq.getMainFlow() == null) {
+ return;
+ }
+
+ // Initialize if already used?
+ // this.layoutMasterSet.resetPageMasters();
+ if (pageSeq.getPageSequenceMaster() != null) {
+ pageSeq.getPageSequenceMaster().reset();
+ }
+
+ pageSeq.initPageNumber();
+
+ // This will layout pages and add them to the area tree
+ PageLayoutManager pageLM = new PageLayoutManager(areaTree, pageSeq, this);
+ pageLM.setPageCounting(pageSeq.getCurrentPageNumber(),
+ pageSeq.getPageNumberGenerator());
+
+ // For now, skip the threading and just call run directly.
+ pageLM.run();
+
+ // Thread layoutThread = new Thread(pageLM);
+ // layoutThread.start();
+ // log.debug("Layout thread started");
+
+ // // wait on both managers
+ // try {
+ // layoutThread.join();
+ // log.debug("Layout thread done");
+ // } catch (InterruptedException ie) {
+ // log.error("PageSequence.format() interrupted waiting on layout");
+ // }
+
+ pageSeq.setCurrentPageNumber(pageLM.getPageCount());
+ // Tell the root the last page number we created.
+ pageSeq.getRoot().setRunningPageNumberCounter(pageSeq.getCurrentPageNumber());
+ }
+
+ /**
+ * @return the Title area
+ */
+ public org.apache.fop.area.Title getTitleArea(org.apache.fop.fo.pagination.Title foTitle) {
+ // use special layout manager to add the inline areas
+ // to the Title.
+ InlineStackingLayoutManager lm;
+ lm = new InlineStackingLayoutManager(foTitle);
+ lm.setLMiter(new LMiter(lm, foTitle.children.listIterator()));
+ lm.initialize();
+
+ // get breaks then add areas to title
+ org.apache.fop.area.Title title =
+ new org.apache.fop.area.Title();
+
+ ContentLayoutManager clm = new ContentLayoutManager(title);
+ clm.setUserAgent(foTitle.getUserAgent());
+ lm.setParent(clm);
+
+ clm.fillArea(lm);
+
+ return title;
+ }
+
+ /**
+ * Public accessor to set the AddLMVisitor object that should be used.
+ * This allows subclasses of AddLMVisitor to be used, which can be useful
+ * for extensions to the FO Tree.
+ * @param addLMVisitor the AddLMVisitor object that should be used.
+ */
+ public void setAddLMVisitor(AddLMVisitor addLMVisitor) {
+ this.addLMVisitor = addLMVisitor;
+ }
+
+ /**
+ * Public accessor to get the AddLMVisitor object that should be used.
+ * @return the AddLMVisitor object that should be used.
+ */
+ public AddLMVisitor getAddLMVisitor() {
+ if (this.addLMVisitor == null) {
+ this.addLMVisitor = new AddLMVisitor();
+ }
+ return this.addLMVisitor;
+ }
+
}
diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java
index 51f7e7249..c86871253 100644
--- a/src/java/org/apache/fop/apps/Driver.java
+++ b/src/java/org/apache/fop/apps/Driver.java
@@ -34,7 +34,6 @@ import org.apache.fop.render.rtf.RTFHandler;
import org.apache.fop.tools.DocumentInputSource;
import org.apache.fop.tools.DocumentReader;
import org.apache.fop.tools.ProxyContentHandler;
-import org.apache.fop.layoutmgr.LayoutManagerLS;
import org.apache.commons.logging.impl.SimpleLog;
import org.apache.commons.logging.Log;
@@ -509,13 +508,6 @@ public class Driver {
}
}
currentDocument.foInputHandler = foInputHandler;
- /** LayoutStrategy is hard-wired for now, but needs to be made
- accessible through the API and/or configuration */
- if (foInputHandler instanceof FOTreeHandler) {
- if (currentDocument.getLayoutStrategy() == null) {
- currentDocument.setLayoutStrategy(new LayoutManagerLS());
- }
- }
foInputHandler.setLogger(getLogger());
@@ -561,6 +553,8 @@ public class Driver {
* This is the main render() method. The other render() methods are for
* convenience, and normalize to this form, then run this.
* Renders the FO document read by a SAX Parser from an InputSource.
+ * For versions not needing an FO Tree (e.g., Alt-Design), override this.
+ *
* @param parser the SAX parser.
* @param source the input source the parser reads from.
* @throws FOPException if anything goes wrong.
@@ -569,22 +563,6 @@ public class Driver {
throws FOPException {
parser.setContentHandler(getContentHandler());
- /**
- * The following statement handles the case of a LayoutStrategy that
- * does not wish to build an FO Tree, but wishes to parse the incoming
- * document some other way. This applies primarily to the alt-design
- * system.
- */
- if (currentDocument.getLayoutStrategy() != null) {
- if (!currentDocument.getLayoutStrategy().foTreeNeeded()) {
- currentDocument.getLayoutStrategy().format(null, null);
- return;
- }
- }
-
- /**
- * For all other cases, we wish to parse normally.
- */
try {
/**
The following statement triggers virtually all of the processing
diff --git a/src/java/org/apache/fop/layout/LayoutStrategy.java b/src/java/org/apache/fop/layout/LayoutStrategy.java
deleted file mode 100644
index 477f9c314..000000000
--- a/src/java/org/apache/fop/layout/LayoutStrategy.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- */
-
-/* $Id$ */
-
-
-package org.apache.fop.layout;
-
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.area.AreaTree;
-import org.apache.fop.fo.pagination.PageSequence;
-
-/**
- * Abstract class defining the highest-level information for a layout strategy.
- * Subclasses implement a layout strategy that converts an FO Tree into an
- * Area Tree.
- */
-public abstract class LayoutStrategy {
-
- private String name = "undefined";
-
- public LayoutStrategy() {
- }
-
- /**
- * Returns the name of this LayoutStrategy.
- * @return the String name of this LayoutStrategy
- */
- public String getName() {
- return name;
- }
-
- /**
- * Format a PageSequence into an AreaTree
- * @param pageSeq the PageSequence to be formatted
- * @param areaTree the AreaTree in which to place the formatted PageSequence
- * @throws FOPException for errors during layout
- */
- public abstract void format (PageSequence pageSeq, AreaTree areaTree)
- throws FOPException;
-
- /**
- * Indicates whether an FO Tree should be built for this layout strategy.
- * Override this in subclasses if an FO Tree is not needed.
- * @return true if an FO Tree is needed, false otherwise
- */
- public boolean foTreeNeeded() {
- return true;
- }
-
-}
diff --git a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
index 3f6e9e0e6..f6d42ae67 100644
--- a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
@@ -20,6 +20,7 @@ package org.apache.fop.layoutmgr;
import org.apache.fop.fo.FObj;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Document;
import org.apache.fop.fo.flow.Marker;
import org.apache.fop.area.Area;
import org.apache.fop.area.Resolveable;
@@ -108,8 +109,8 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants
return this.parentLM;
}
- public LayoutManagerLS getLayoutManagerLS() {
- return getParent().getLayoutManagerLS();
+ public Document getDocument() {
+ return getParent().getDocument();
}
// /**
diff --git a/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java
index 672ffc5fe..c1ee57b46 100644
--- a/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java
@@ -19,6 +19,7 @@
package org.apache.fop.layoutmgr;
import org.apache.fop.fo.FObj;
+import org.apache.fop.apps.Document;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.flow.Marker;
import org.apache.fop.area.Area;
@@ -170,8 +171,8 @@ public class ContentLayoutManager implements LayoutManager {
return this.parentLM;
}
- public LayoutManagerLS getLayoutManagerLS() {
- return getParent().getLayoutManagerLS();
+ public Document getDocument() {
+ return getParent().getDocument();
}
/** @see org.apache.fop.layoutmgr.LayoutManager */
diff --git a/src/java/org/apache/fop/layoutmgr/LMiter.java b/src/java/org/apache/fop/layoutmgr/LMiter.java
index e134eb6a0..774e03351 100644
--- a/src/java/org/apache/fop/layoutmgr/LMiter.java
+++ b/src/java/org/apache/fop/layoutmgr/LMiter.java
@@ -46,7 +46,7 @@ public class LMiter implements ListIterator {
}
protected boolean preLoadNext() {
- AddLMVisitor addLMVisitor = lp.getLayoutManagerLS().getAddLMVisitor();
+ AddLMVisitor addLMVisitor = lp.getDocument().getAddLMVisitor();
// skip over child FObj's that don't add lms
while (baseIter != null && baseIter.hasNext()) {
Object theobj = baseIter.next();
diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManager.java b/src/java/org/apache/fop/layoutmgr/LayoutManager.java
index c4662164d..54ade889a 100644
--- a/src/java/org/apache/fop/layoutmgr/LayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/LayoutManager.java
@@ -71,10 +71,10 @@ public interface LayoutManager {
LayoutManager getParent();
/**
- * Get the LayoutManagerLS object that is at the top of the LM Tree
- * @return the LayoutManagerLS object that is at the top of the LM Tree
+ * Get the Document object that is at the top of the LM Tree
+ * @return the Document object that is at the top of the LM Tree
*/
- LayoutManagerLS getLayoutManagerLS();
+ org.apache.fop.apps.Document getDocument();
/**
* Initialize this layout manager.
diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManagerLS.java b/src/java/org/apache/fop/layoutmgr/LayoutManagerLS.java
deleted file mode 100644
index 6426bdc69..000000000
--- a/src/java/org/apache/fop/layoutmgr/LayoutManagerLS.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
- */
-
-/* $Id$ */
-
-package org.apache.fop.layoutmgr;
-
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.area.AreaTree;
-import org.apache.fop.area.Title;
-import org.apache.fop.fo.pagination.PageSequence;
-import org.apache.fop.layout.LayoutStrategy;
-
-/**
- * The implementation of LayoutStrategy for the "redesign" or second generation
- * FOP layout.
- */
-public class LayoutManagerLS extends LayoutStrategy {
-
- private static String name = "layoutmgr";
- /** Useful only for allowing subclasses of AddLMVisitor to be set by those
- extending FOP **/
- private AddLMVisitor addLMVisitor = null;
-
- public LayoutManagerLS() {
- super();
- }
-
- /**
- * Runs the formatting of this page sequence into the given area tree
- *
- * @param pageSeq the PageSequence to be formatted
- * @param areaTree the area tree to format this page sequence into
- * @throws FOPException if there is an error formatting the contents
- */
- public void format(PageSequence pageSeq, AreaTree areaTree) throws FOPException {
- Title title = null;
- if (pageSeq.getTitleFO() != null) {
- title = getTitleArea(pageSeq.getTitleFO());
- }
- areaTree.startPageSequence(title);
- // Make a new PageLayoutManager and a FlowLayoutManager
- // Run the PLM in a thread
- // Wait for them to finish.
-
- // If no main flow, nothing to layout!
- if (pageSeq.getMainFlow() == null) {
- return;
- }
-
- // Initialize if already used?
- // this.layoutMasterSet.resetPageMasters();
- if (pageSeq.getPageSequenceMaster() != null) {
- pageSeq.getPageSequenceMaster().reset();
- }
-
- pageSeq.initPageNumber();
-
- // This will layout pages and add them to the area tree
- PageLayoutManager pageLM = new PageLayoutManager(areaTree, pageSeq, this);
- pageLM.setPageCounting(pageSeq.getCurrentPageNumber(),
- pageSeq.getPageNumberGenerator());
-
- // For now, skip the threading and just call run directly.
- pageLM.run();
-
- // Thread layoutThread = new Thread(pageLM);
-// layoutThread.start();
-// log.debug("Layout thread started");
-
-// // wait on both managers
-// try {
-// layoutThread.join();
-// log.debug("Layout thread done");
-// } catch (InterruptedException ie) {
-// log.error("PageSequence.format() interrupted waiting on layout");
-// }
- pageSeq.setCurrentPageNumber(pageLM.getPageCount());
- // Tell the root the last page number we created.
- pageSeq.getRoot().setRunningPageNumberCounter(pageSeq.getCurrentPageNumber());
- }
-
- /**
- * @return the Title area
- */
- public org.apache.fop.area.Title getTitleArea(org.apache.fop.fo.pagination.Title foTitle) {
- // use special layout manager to add the inline areas
- // to the Title.
- InlineStackingLayoutManager lm;
- lm = new InlineStackingLayoutManager(foTitle);
- lm.setLMiter(new LMiter(lm, foTitle.children.listIterator()));
- lm.initialize();
-
- // get breaks then add areas to title
- org.apache.fop.area.Title title =
- new org.apache.fop.area.Title();
-
- ContentLayoutManager clm = new ContentLayoutManager(title);
- clm.setUserAgent(foTitle.getUserAgent());
- lm.setParent(clm);
-
- clm.fillArea(lm);
-
- return title;
- }
-
- /**
- * Public accessor to set the AddLMVisitor object that should be used.
- * This allows subclasses of AddLMVisitor to be used, which can be useful
- * for extensions to the FO Tree.
- * @param addLMVisitor the AddLMVisitor object that should be used.
- */
- public void setAddLMVisitor(AddLMVisitor addLMVisitor) {
- this.addLMVisitor = addLMVisitor;
- }
-
- /**
- * Public accessor to get the AddLMVisitor object that should be used.
- * @return the AddLMVisitor object that should be used.
- */
- public AddLMVisitor getAddLMVisitor() {
- if (this.addLMVisitor == null) {
- this.addLMVisitor = new AddLMVisitor();
- }
- return this.addLMVisitor;
- }
-
-}
diff --git a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java
index 8313563d7..08122754d 100644
--- a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java
@@ -18,6 +18,7 @@
package org.apache.fop.layoutmgr;
+import org.apache.fop.apps.Document;
import org.apache.fop.apps.FOPException;
import org.apache.fop.area.CTM;
@@ -106,6 +107,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
*/
private AreaTree areaTree;
private PageSequence pageSequence;
+ private Document doc;
/**
* This is the SimplePageMaster that should be used to create the page. It
@@ -121,8 +123,6 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
*/
private HashMap staticContentLMs = new HashMap(4);
- private LayoutManagerLS lmls;
-
/**
* This is the top level layout manager.
* It is created by the PageSequence FO.
@@ -131,11 +131,11 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
* @param pageseq the page sequence fo
*/
public PageLayoutManager(AreaTree areaTree, PageSequence pageseq,
- LayoutManagerLS lmls) {
+ Document doc) {
super(pageseq);
this.areaTree = areaTree;
pageSequence = pageseq;
- this.lmls = lmls;
+ this.doc = doc;
}
/**
@@ -895,9 +895,11 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
staticContentLMs.put(sc.getFlowName(), lm);
return lm;
}
-
- public LayoutManagerLS getLayoutManagerLS() {
- return lmls;
+
+ /**
+ * @return the apps.Document object controlling this generation
+ */
+ public Document getDocument() {
+ return doc;
}
-
}