gmazza      2004/05/18 04:42:08

  Modified:    src/java/org/apache/fop/apps Document.java Driver.java
               src/java/org/apache/fop/layoutmgr AbstractLayoutManager.java
                        ContentLayoutManager.java LMiter.java
                        LayoutManager.java PageLayoutManager.java
  Removed:     src/java/org/apache/fop/layout LayoutStrategy.java
               src/java/org/apache/fop/layoutmgr LayoutManagerLS.java
  Log:
  Folded the layout strategy into apps.Document.
  
  Revision  Changes    Path
  1.14      +114 -29   xml-fop/src/java/org/apache/fop/apps/Document.java
  
  Index: Document.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Document.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Document.java     22 Apr 2004 21:38:39 -0000      1.13
  +++ Document.java     18 May 2004 11:42:07 -0000      1.14
  @@ -24,22 +24,25 @@
   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 @@
       /** 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 @@
   
       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 @@
       }
   
       /**
  -     * 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 void foPageSequenceComplete (FOTreeEvent event) throws FOPException {
           PageSequence pageSeq = event.getPageSequence();
           areaTree.addBookmarksToAreaTree();
  -        layoutStrategy.format(pageSeq, areaTree);
  +        format(pageSeq, areaTree);
       }
   
       /**
  @@ -195,4 +180,104 @@
           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;
  +    }
  +    
   }
  
  
  
  1.59      +3 -25     xml-fop/src/java/org/apache/fop/apps/Driver.java
  
  Index: Driver.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Driver.java,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- Driver.java       12 May 2004 23:19:52 -0000      1.58
  +++ Driver.java       18 May 2004 11:42:07 -0000      1.59
  @@ -34,7 +34,6 @@
   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 @@
               }
           }
           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 @@
        * 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 @@
                   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
  
  
  
  1.13      +3 -2      
xml-fop/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java
  
  Index: AbstractLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- AbstractLayoutManager.java        15 May 2004 21:51:59 -0000      1.12
  +++ AbstractLayoutManager.java        18 May 2004 11:42:08 -0000      1.13
  @@ -20,6 +20,7 @@
   
   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 @@
           return this.parentLM;
       }
   
  -    public LayoutManagerLS getLayoutManagerLS() {
  -        return getParent().getLayoutManagerLS();
  +    public Document getDocument() {
  +        return getParent().getDocument();
       }
   
       //     /**
  
  
  
  1.9       +3 -2      
xml-fop/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java
  
  Index: ContentLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ContentLayoutManager.java 21 Mar 2004 12:03:08 -0000      1.8
  +++ ContentLayoutManager.java 18 May 2004 11:42:08 -0000      1.9
  @@ -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 @@
           return this.parentLM;
       }
   
  -    public LayoutManagerLS getLayoutManagerLS() {
  -        return getParent().getLayoutManagerLS();
  +    public Document getDocument() {
  +        return getParent().getDocument();
       }
   
       /** @see org.apache.fop.layoutmgr.LayoutManager */
  
  
  
  1.6       +1 -1      xml-fop/src/java/org/apache/fop/layoutmgr/LMiter.java
  
  Index: LMiter.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/LMiter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LMiter.java       21 Mar 2004 12:03:08 -0000      1.5
  +++ LMiter.java       18 May 2004 11:42:08 -0000      1.6
  @@ -46,7 +46,7 @@
       }
   
       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();
  
  
  
  1.6       +3 -3      xml-fop/src/java/org/apache/fop/layoutmgr/LayoutManager.java
  
  Index: LayoutManager.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/LayoutManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LayoutManager.java        15 May 2004 21:52:00 -0000      1.5
  +++ LayoutManager.java        18 May 2004 11:42:08 -0000      1.6
  @@ -71,10 +71,10 @@
       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.
  
  
  
  1.37      +10 -8     xml-fop/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java
  
  Index: PageLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- PageLayoutManager.java    15 May 2004 21:52:00 -0000      1.36
  +++ PageLayoutManager.java    18 May 2004 11:42:08 -0000      1.37
  @@ -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 @@
        */
       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 @@
        */
       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 @@
        * @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 @@
           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;
       }
  -
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to