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;
* 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.
* @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() {
*/
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);
}
/**
}
}
- /**
- * 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) {
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;
+ }
+}
* 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;
}
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
return name;
}
+ public abstract void format (PageSequence pageSeq, AreaTree areaTree)
+ throws FOPException;
}
*/
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
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());
+ }
+
}