]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Folded the layout strategy into apps.Document.
authorGlen Mazza <gmazza@apache.org>
Tue, 18 May 2004 11:42:08 +0000 (11:42 +0000)
committerGlen Mazza <gmazza@apache.org>
Tue, 18 May 2004 11:42:08 +0000 (11:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197605 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/apps/Document.java
src/java/org/apache/fop/apps/Driver.java
src/java/org/apache/fop/layout/LayoutStrategy.java [deleted file]
src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java
src/java/org/apache/fop/layoutmgr/LMiter.java
src/java/org/apache/fop/layoutmgr/LayoutManager.java
src/java/org/apache/fop/layoutmgr/LayoutManagerLS.java [deleted file]
src/java/org/apache/fop/layoutmgr/PageLayoutManager.java

index 520552cad399d0b9aa6c98f2240f2fa0d7782f38..ae3ab2a833a27a2d4ce0379ce378decde2f3b206 100644 (file)
@@ -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.
@@ -103,21 +103,6 @@ public class Document implements FOTreeControl, FOTreeListener,
         return this.fontInfo;
     }
 
-    /**
-     * 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;
+    }
+    
 }
index 51f7e7249e1ec1b35b250fc035f3d765a613fd73..c868712533ae64163cc10904a1629028b166636e 100644 (file)
@@ -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 (file)
index 477f9c3..0000000
+++ /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;
-    }
-
-}
index 3f6e9e0e656cb28e34f523a7b5f16442a3250f09..f6d42ae67d6fb159d82d6f4f6cefc458978824c0 100644 (file)
@@ -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();
     }
 
     //     /**
index 672ffc5fe3ca1fa7fb10e6e778e9f28c930b773f..c1ee57b460061619b52a953ebcca2e38dfa69609 100644 (file)
@@ -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 */
index e134eb6a0ec918f4035c24b4d5e70e9f8f95196e..774e03351c15e88dae48f7bc98f3f4d0faa28086 100644 (file)
@@ -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();
index c4662164d417665f18e9f6ecd9fc32e729060f61..54ade889a5b5dccfda088be9e22c2b4e15926740 100644 (file)
@@ -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 (file)
index 6426bdc..0000000
+++ /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;
-    }
-
-}
index 8313563d71636604a0c044e54599096a3ce6d395..08122754d84a4b4f9237a5e93c2ec0a17b2e118a 100644 (file)
@@ -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;
     }
-
 }