]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
1. integrate Document and LayoutStrategy into workflow
authorWilliam Victor Mote <vmote@apache.org>
Fri, 15 Aug 2003 15:52:10 +0000 (15:52 +0000)
committerWilliam Victor Mote <vmote@apache.org>
Fri, 15 Aug 2003 15:52:10 +0000 (15:52 +0000)
2. make Document a child of Driver and start integrating this hierarchy

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196803 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/apps/Driver.java
src/java/org/apache/fop/control/Document.java
src/java/org/apache/fop/extensions/Bookmarks.java
src/java/org/apache/fop/fo/FOInputHandler.java
src/java/org/apache/fop/fo/FOTreeHandler.java
src/java/org/apache/fop/mif/MIFHandler.java
src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java
src/java/org/apache/fop/rtf/renderer/RTFHandler.java
src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
src/java/org/apache/fop/svg/PDFGraphics2D.java
src/java/org/apache/fop/tools/AreaTreeBuilder.java

index d4f1c9782d51ed201dbfbc41bba70e3fdbd29410..f03645d4587ea83a421c1a63ecc8fab8406e4798 100644 (file)
@@ -53,6 +53,7 @@ package org.apache.fop.apps;
 // FOP
 import org.apache.fop.area.AreaTree;
 import org.apache.fop.area.AreaTreeModel;
+import org.apache.fop.control.Document;
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.fo.FOTreeBuilder;
 import org.apache.fop.fo.FOUserAgent;
@@ -68,6 +69,8 @@ import org.apache.fop.render.awt.AWTRenderer;
 import org.apache.fop.rtf.renderer.RTFHandler;
 import org.apache.fop.tools.DocumentInputSource;
 import org.apache.fop.tools.DocumentReader;
+import org.apache.fop.layout.LayoutStrategy;
+import org.apache.fop.layoutmgr.LayoutManagerLS;
 
 // Avalon
 import org.apache.avalon.framework.logger.ConsoleLogger;
@@ -75,7 +78,8 @@ import org.apache.avalon.framework.logger.LogEnabled;
 import org.apache.avalon.framework.logger.Logger;
 
 // DOM
-import org.w3c.dom.Document;
+/* org.w3c.dom.Document is not imported to reduce confusion with
+   org.apache.fop.control.Document */
 
 // SAX
 import org.xml.sax.ContentHandler;
@@ -233,6 +237,8 @@ public class Driver implements LogEnabled, FOTreeListener {
     private AreaTree areaTree;
     private AreaTreeModel atModel;
 
+    private Document currentDocument = null;
+
     /**
      * Main constructor for the Driver class.
      */
@@ -540,15 +546,15 @@ public class Driver implements LogEnabled, FOTreeListener {
         // TODO: - do this stuff in a better way
         // PIJ: I guess the structure handler should be created by the renderer.
         if (rendererType == RENDER_MIF) {
-            foInputHandler = new MIFHandler(this, stream);
+            foInputHandler = new MIFHandler(currentDocument, stream);
         } else if (rendererType == RENDER_RTF) {
-            foInputHandler = new RTFHandler(this, stream);
+            foInputHandler = new RTFHandler(currentDocument, stream);
         } else {
             if (renderer == null) {
                 throw new IllegalStateException(
                         "Renderer not set when using standard foInputHandler");
             }
-            foInputHandler = new FOTreeHandler(this, stream, renderer, true);
+            foInputHandler = new FOTreeHandler(currentDocument, stream, renderer, true);
         }
 
         foInputHandler.enableLogging(getLogger());
@@ -584,7 +590,17 @@ public class Driver implements LogEnabled, FOTreeListener {
         if (!isInitialized()) {
             initialize();
         }
+        /** Document creation is hard-wired for now, but needs to be made
+         accessible through the API and/or configuration */
+        if (currentDocument == null) {
+            currentDocument = new Document(this);
+        }
         parser.setContentHandler(getContentHandler());
+        /** LayoutStrategy is hard-wired for now, but needs to be made
+        accessible through the API and/or configuration */
+        if (foInputHandler instanceof FOTreeHandler) {
+            currentDocument.setLayoutStrategy(new LayoutManagerLS());
+        }
         try {
             if (foInputHandler instanceof FOTreeHandler) {
                 FOTreeHandler foTreeHandler = (FOTreeHandler)foInputHandler;
@@ -631,7 +647,7 @@ public class Driver implements LogEnabled, FOTreeListener {
      * @param document the DOM document to read from
      * @throws FOPException if anything goes wrong.
      */
-    public synchronized void render(Document document)
+    public synchronized void render(org.w3c.dom.Document document)
                 throws FOPException {
         DocumentInputSource source = new DocumentInputSource(document);
         DocumentReader reader = new DocumentReader();
index 364ba559dde0915feed18d38c2d1e8b558be2474..a72de0b45e735443c11abb845cc38addbfd22c67 100644 (file)
@@ -54,20 +54,20 @@ package org.apache.fop.control;
 import java.util.Map;
 
 // FOP
+import org.apache.fop.apps.Driver;
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontMetrics;
+import org.apache.fop.layout.LayoutStrategy;
 
 /**
- * The FontInfo for the layout and rendering of a fo document.
- * This stores the list of available fonts that are setup by
- * the renderer. The font name can be retrieved for the
- * family style and weight.
- * <br>
- * Currently font supported font-variant small-caps is not
- * implemented.
+ * Class storing information for the FOP Document being processed, and managing
+ * the processing of it.
  */
 public class Document {
 
+    /** The parent Driver object */
+    private Driver driver;
+
     /** Map containing fonts that have been used */
     private Map usedFonts;
 
@@ -77,10 +77,18 @@ public class Document {
     /** look up a font-name to get a font (that implements FontMetrics at least) */
     private Map fonts;
 
+    /**
+     * the LayoutStrategy to be used to process this document
+     * TODO: this actually belongs in the RenderContext class, when it is
+     * created
+     */
+    private LayoutStrategy ls = null;
+
     /**
      * Main constructor
      */
-    public Document() {
+    public Document(Driver driver) {
+        this.driver = driver;
         this.triplets = new java.util.HashMap();
         this.fonts = new java.util.HashMap();
         this.usedFonts = new java.util.HashMap();
@@ -262,5 +270,24 @@ public class Document {
         usedFonts.put(fontName, fonts.get(fontName));
         return (FontMetrics)fonts.get(fontName);
     }
+
+    /**
+     * 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.ls = ls;
+    }
+
+    /**
+     * @return this Document's LayoutStrategy object
+     */
+    public LayoutStrategy getLayoutStrategy () {
+        return ls;
+    }
+
+    public Driver getDriver() {
+        return driver;
+    }
 }
 
index 0fa44f524c074f57682a0ec339179ec10939b17f..9152b7a5671523ba67d0c522be82d90fc3dad756 100644 (file)
@@ -109,7 +109,7 @@ public class Bookmarks extends ExtensionObj {
         }
         // add data to area tree for resolving and handling
         if (foInputHandler instanceof FOTreeHandler) {
-            AreaTree at = ((FOTreeHandler)foInputHandler).driver.getAreaTree();
+            AreaTree at = ((FOTreeHandler)foInputHandler).doc.getDriver().getAreaTree();
             at.addTreeExtension(data);
             data.setAreaTree(at);
         }
index 8e06247f4c7c1d30b2ce9e54f749ed63133d514b..e5eb711153c8c072c52af9437658df6df146ad88 100644 (file)
@@ -94,13 +94,15 @@ public abstract class FOInputHandler extends AbstractLogEnabled {
      */
     private Set idReferences = new HashSet();
 
-    public Driver driver = null;
+//    public Driver driver = null;
+
+    public Document doc = null;
 
     /**
      * Main constructor
      */
-    public FOInputHandler(Driver driver) {
-        this.driver = driver;
+    public FOInputHandler(Document document) {
+        this.doc = document;
     }
 
     /**
index f3fede6a038431fa10596b028bb3f8ea4d156e90..b1f09c01d28a2d7aa17ddd70d81914b92bd782c4 100644 (file)
@@ -127,11 +127,6 @@ public class FOTreeHandler extends FOInputHandler {
      */
     private Renderer renderer;
 
-    /**
-     * The FontInfo for this renderer.
-     */
-    private Document fontInfo = new Document();
-
     /**
      * Collection of objects that have registered to be notified about
      * FOTreeEvent firings.
@@ -145,9 +140,9 @@ public class FOTreeHandler extends FOInputHandler {
      * @param store if true then use the store pages model and keep the
      *              area tree in memory
      */
-    public FOTreeHandler(Driver driver, OutputStream outputStream, Renderer renderer,
+    public FOTreeHandler(Document document, OutputStream outputStream, Renderer renderer,
                          boolean store) {
-        super(driver);
+        super(document);
         if (collectStatistics) {
             runtime = Runtime.getRuntime();
         }
@@ -174,9 +169,9 @@ public class FOTreeHandler extends FOInputHandler {
             startTime = System.currentTimeMillis();
         }
         try {
-            renderer.setupFontInfo(fontInfo);
+            renderer.setupFontInfo(doc);
             // check that the "any,normal,400" font exists
-            if (!fontInfo.isSetupValid()) {
+            if (!doc.isSetupValid()) {
                 throw new SAXException(new FOPException(
                         "No default font defined by OutputConverter"));
             }
@@ -478,7 +473,7 @@ public class FOTreeHandler extends FOInputHandler {
      * @return the font information
      */
     public Document getFontInfo() {
-        return this.fontInfo;
+        return this.doc;
     }
 
     /**
index a5b65b4c0737c9a594d790df449c8d6e1f3472b9..7496ef90c150c435d1f76c5126cd885638fb0a5c 100644 (file)
@@ -91,7 +91,6 @@ public class MIFHandler extends FOInputHandler {
     protected MIFFile mifFile;
     /** the OutputStream to write to */
     protected OutputStream outStream;
-    private Document fontInfo = new Document();
 
     // current state elements
     private MIFElement textFlow;
@@ -101,18 +100,11 @@ public class MIFHandler extends FOInputHandler {
      * Creates a new MIF handler on a given OutputStream.
      * @param os OutputStream to write to
      */
-    public MIFHandler(Driver driver, OutputStream os) {
-        super(driver);
+    public MIFHandler(Document doc, OutputStream os) {
+        super(doc);
         outStream = os;
         // use pdf fonts for now, this is only for resolving names
-        org.apache.fop.render.pdf.FontSetup.setup(fontInfo, null);
-    }
-
-    /**
-     * @see org.apache.fop.fo.FOInputHandler#getFontInfo()
-     */
-    public Document getFontInfo() {
-        return fontInfo;
+        org.apache.fop.render.pdf.FontSetup.setup(doc, null);
     }
 
     /**
index c48fe82aa13ee394cb2bbe4bcd018c22a357ff05..0312c3129c9525be21f8b6874f659538644d7c4c 100644 (file)
@@ -94,7 +94,7 @@ public class PSDocumentGraphics2D extends PSGraphics2D {
         super(textAsShapes);
 
         if (!textAsShapes) {
-            fontInfo = new Document();
+            fontInfo = new Document(null);
             FontSetup.setup(fontInfo, null);
             //FontState fontState = new FontState("Helvetica", "normal",
             //                          FontInfo.NORMAL, 12, 0);
index 0d9933973bb2d184805f7d6fd3e92008ec531d73..881f9561921247c760a27aebdeea6fbd3296037b 100644 (file)
@@ -90,7 +90,6 @@ import org.xml.sax.SAXException;
  */
 public class RTFHandler extends FOInputHandler {
 
-    private Document fontInfo = new Document();
     private RtfFile rtfFile;
     private final OutputStream os;
     private RtfSection sect;
@@ -111,21 +110,14 @@ public class RTFHandler extends FOInputHandler {
      * Creates a new RTF structure handler.
      * @param os OutputStream to write to
      */
-    public RTFHandler(Driver driver, OutputStream os) {
-        super(driver);
+    public RTFHandler(Document doc, OutputStream os) {
+        super(doc);
         this.os = os;
         // use pdf fonts for now, this is only for resolving names
-        org.apache.fop.render.pdf.FontSetup.setup(fontInfo, null);
+        org.apache.fop.render.pdf.FontSetup.setup(doc, null);
         System.err.println(ALPHA_WARNING);
     }
 
-    /**
-     * @see org.apache.fop.fo.FOInputHandler#getFontInfo()
-     */
-    public Document getFontInfo() {
-        return this.fontInfo;
-    }
-
     /**
      * @see org.apache.fop.fo.FOInputHandler#startDocument()
      */
index 458c58e0346d137c5a93a4bfea5f1a8f12b03d29..93880f1b4fc2f0e53225efeb6dd99f22beaea2d6 100644 (file)
@@ -3,34 +3,34 @@
  * ============================================================================
  *                    The Apache Software License, Version 1.1
  * ============================================================================
- * 
+ *
  * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
- * 
+ *
  * Redistribution and use in source and binary forms, with or without modifica-
  * tion, are permitted provided that the following conditions are met:
- * 
+ *
  * 1. Redistributions of source code must retain the above copyright notice,
  *    this list of conditions and the following disclaimer.
- * 
+ *
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- * 
+ *
  * 3. The end-user documentation included with the redistribution, if any, must
  *    include the following acknowledgment: "This product includes software
  *    developed by the Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself, if
  *    and wherever such third-party acknowledgments normally appear.
- * 
+ *
  * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  *    endorse or promote products derived from this software without prior
  *    written permission. For written permission, please contact
  *    apache@apache.org.
- * 
+ *
  * 5. Products derived from this software may not be called "Apache", nor may
  *    "Apache" appear in their name, without prior written permission of the
  *    Apache Software Foundation.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  * ============================================================================
- * 
+ *
  * This software consists of voluntary contributions made by many individuals
  * on behalf of the Apache Software Foundation and was originally created by
  * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  * Software Foundation, please see <http://www.apache.org/>.
- */ 
+ */
 package org.apache.fop.svg;
 
 import org.apache.fop.pdf.PDFDocument;
@@ -93,13 +93,13 @@ import java.util.List;
  */
 public class PDFDocumentGraphics2D extends PDFGraphics2D
             implements LogEnabled, Configurable, Initializable {
-    
+
     private PDFPage currentPage;
     private PDFStream pdfStream;
     private int width;
     private int height;
     private List fontList;
-    
+
     //Avalon-dependent stuff
     private Logger logger;
     private Configuration cfg;
@@ -119,7 +119,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
         super(textAsShapes);
 
         if (!textAsShapes) {
-            fontInfo = new Document();
+            fontInfo = new Document(null);
             FontSetup.setup(fontInfo, null);
             //FontState fontState = new FontState("Helvetica", "normal",
             //                          FontInfo.NORMAL, 12, 0);
@@ -195,7 +195,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
      */
     public void initialize() throws Exception {
         if (this.fontInfo == null) {
-            fontInfo = new Document();
+            fontInfo = new Document(null);
             FontSetup.setup(fontInfo, this.fontList);
             //FontState fontState = new FontState("Helvetica", "normal",
             //                          FontInfo.NORMAL, 12, 0);
@@ -207,7 +207,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
             this.pdfDoc.setFilterMap(
                 PDFFilterList.buildFilterMapFromConfiguration(cfg));
         }
-        
+
         graphicsState = new PDFState();
 
         currentFontName = "";
index c992d51aaf18b1ff3153bf6b275f10b809980b5a..07e01dbfbfc56306cd30bff2dfcd56f340f8b224 100644 (file)
@@ -983,7 +983,7 @@ public class PDFGraphics2D extends AbstractGraphics2D {
     private void createPattern(PatternPaint pp, boolean fill) {
         Rectangle2D rect = pp.getPatternRect();
 
-        Document fi = new Document();
+        Document fi = new Document(null);
         FontSetup.setup(fi, null);
 
         PDFResources res = pdfDoc.getFactory().makeResources();
index 0c64bbd1a3437f296b53d5528c5ed922d6d0c793..07b3683ff44ea1e469b8b6772ec06c7c8aca9888 100644 (file)
@@ -169,7 +169,7 @@ public class AreaTreeBuilder extends AbstractLogEnabled {
             rend = new SVGRenderer();
         }
         setupLogger(rend);
-        Document fi = new Document();
+        Document fi = new Document(null);
         rend.setupFontInfo(fi);
         FOUserAgent ua = new FOUserAgent();
         setupLogger(ua);