]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
move startup of laying out a PageSequence from PageSequence.format() and Document...
authorWilliam Victor Mote <vmote@apache.org>
Wed, 20 Aug 2003 17:25:44 +0000 (17:25 +0000)
committerWilliam Victor Mote <vmote@apache.org>
Wed, 20 Aug 2003 17:25:44 +0000 (17:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196815 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/control/Document.java
src/java/org/apache/fop/fo/pagination/PageSequence.java
src/java/org/apache/fop/fo/pagination/Root.java
src/java/org/apache/fop/layout/LayoutStrategy.java
src/java/org/apache/fop/layoutmgr/LayoutManagerLS.java

index 279dc49b375e201d521a66ba295fc61a830e27c2..f30bde00d490e7fceec2ff42f513af6e10ede461 100644 (file)
@@ -63,7 +63,6 @@ import org.apache.fop.fo.FOTreeControl;
 import org.apache.fop.fo.FOTreeEvent;
 import org.apache.fop.fo.FOTreeListener;
 import org.apache.fop.fo.pagination.PageSequence;
-import org.apache.fop.area.Title;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontMetrics;
 import org.apache.fop.layout.LayoutStrategy;
@@ -94,7 +93,7 @@ public class Document implements FOTreeControl, FOTreeListener {
      * TODO: this actually belongs in the RenderContext class, when it is
      * created
      */
-    private LayoutStrategy ls = null;
+    private LayoutStrategy layoutStrategy = null;
 
     /**
      * The current AreaTree for the PageSequence being rendered.
@@ -294,14 +293,14 @@ public class Document implements FOTreeControl, FOTreeListener {
      * @param ls the LayoutStrategy object to be used to process this Document
      */
     public void setLayoutStrategy(LayoutStrategy ls) {
-        this.ls = ls;
+        this.layoutStrategy = ls;
     }
 
     /**
      * @return this Document's LayoutStrategy object
      */
     public LayoutStrategy getLayoutStrategy () {
-        return ls;
+        return layoutStrategy;
     }
 
     public Driver getDriver() {
@@ -316,12 +315,7 @@ public class Document implements FOTreeControl, FOTreeListener {
      */
     public void foPageSequenceComplete (FOTreeEvent event) throws FOPException {
         PageSequence pageSeq = event.getPageSequence();
-        Title title = null;
-        if (pageSeq.getTitleFO() != null) {
-            title = pageSeq.getTitleFO().getTitleArea();
-        }
-        areaTree.startPageSequence(title);
-        pageSeq.format(areaTree);
+        layoutStrategy.format(pageSeq, areaTree);
     }
 
     /**
index 8ee2a86c51d71e34ed384893c300f8f4583c95b1..6de86c7688cdc32644f2ab98d24efa789adb7408 100644 (file)
@@ -357,60 +357,10 @@ public class PageSequence extends FObj {
         }
     }
 
-    /**
-     * Runs the formatting of this page sequence into the given area tree
-     *
-     * @param areaTree the area tree to format this page sequence into
-     * @throws FOPException if there is an error formatting the contents
-     */
-    public void format(AreaTree areaTree) throws FOPException {
-        // 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 (this.mainFlow == null) {
-            return;
-        }
-
-        // Initialize if already used?
-        //    this.layoutMasterSet.resetPageMasters();
-        if (pageSequenceMaster != null) {
-            pageSequenceMaster.reset();
-        }
-
-        int firstAvailPageNumber = 0;
-        initPageNumber();
-
-        // This will layout pages and add them to the area tree
-        PageLayoutManager pageLM = new PageLayoutManager(areaTree, this);
-        pageLM.setUserAgent(getUserAgent());
-        pageLM.setFObj(this);
-        pageLM.setPageCounting(currentPageNumber, pageNumberGenerator);
-
-        // 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");
-// }
-        this.currentPageNumber = pageLM.getPageCount();
-        // Tell the root the last page number we created.
-        this.root.setRunningPageNumberCounter(this.currentPageNumber);
-    }
-
     /**
      * Initialize the current page number for the start of the page sequence.
      */
-    private void initPageNumber() {
+    public void initPageNumber() {
         this.currentPageNumber = this.root.getRunningPageNumberCounter() + 1;
 
         if (this.pageNumberType == AUTO_ODD) {
@@ -826,5 +776,23 @@ public class PageSequence extends FObj {
         fotv.serveVisitor(this);
     }
 
-}
+    public Flow getMainFlow() {
+        return mainFlow;
+    }
+
+    public PageSequenceMaster getPageSequenceMaster() {
+        return pageSequenceMaster;
+    }
+
+    public PageNumberGenerator getPageNumberGenerator() {
+        return pageNumberGenerator;
+    }
 
+    public void setCurrentPageNumber(int currentPageNumber) {
+        this.currentPageNumber = currentPageNumber;
+    }
+
+    public Root getRoot() {
+        return root;
+    }
+}
index 139cbd414f01071d57952412cccec463f679073c..415c3de4e80ee7ce58261e138a05be1348944c9e 100644 (file)
@@ -97,7 +97,7 @@ public class Root extends FObj {
      * Sets the overall page number counter.
      * @param count the new page count
      */
-    protected void setRunningPageNumberCounter(int count) {
+    public void setRunningPageNumberCounter(int count) {
         this.runningPageNumberCounter = count;
     }
 
index 1d31cd300838d0bd8f96b0b98e35b594cc97ced9..aa522a3a8fdf490593bdcb99a20f292bc7d4b5ff 100644 (file)
 
 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
@@ -68,4 +72,6 @@ public abstract class LayoutStrategy {
         return name;
     }
 
+    public abstract void format (PageSequence pageSeq, AreaTree areaTree)
+            throws FOPException;
 }
index 9f177a4c5d589230c798efb94ac1ff0d5899b6db..9b59bab88fbe829e6890d36f29446f2095e09b96 100644 (file)
  */
 package org.apache.fop.layoutmgr;
 
+import org.apache.fop.apps.FOPException;
 import org.apache.fop.layout.LayoutStrategy;
+import org.apache.fop.area.AreaTree;
+import org.apache.fop.area.Title;
+import org.apache.fop.fo.pagination.PageSequence;
 
 /**
  * The implementation of LayoutStrategy for the "redesign" or second generation
@@ -60,4 +64,60 @@ public class LayoutManagerLS extends LayoutStrategy {
 
     private static String name = "layoutmgr";
 
+    /**
+     * Runs the formatting of this page sequence into the given area tree
+     *
+     * @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 = pageSeq.getTitleFO().getTitleArea();
+        }
+        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();
+        }
+
+        int firstAvailPageNumber = 0;
+        pageSeq.initPageNumber();
+
+        // This will layout pages and add them to the area tree
+        PageLayoutManager pageLM = new PageLayoutManager(areaTree, pageSeq);
+        pageLM.setUserAgent(pageSeq.getUserAgent());
+        pageLM.setFObj(pageSeq);
+        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());
+    }
+
 }