From 8e0c356d566160b71adb8eb3e96e65600f89db2a Mon Sep 17 00:00:00 2001 From: William Victor Mote Date: Fri, 15 Aug 2003 15:52:10 +0000 Subject: [PATCH] 1. integrate Document and LayoutStrategy into workflow 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 | 26 ++++++++--- src/java/org/apache/fop/control/Document.java | 43 +++++++++++++++---- .../org/apache/fop/extensions/Bookmarks.java | 2 +- .../org/apache/fop/fo/FOInputHandler.java | 8 ++-- src/java/org/apache/fop/fo/FOTreeHandler.java | 15 +++---- src/java/org/apache/fop/mif/MIFHandler.java | 14 ++---- .../fop/render/ps/PSDocumentGraphics2D.java | 2 +- .../apache/fop/rtf/renderer/RTFHandler.java | 14 ++---- .../apache/fop/svg/PDFDocumentGraphics2D.java | 30 ++++++------- .../org/apache/fop/svg/PDFGraphics2D.java | 2 +- .../org/apache/fop/tools/AreaTreeBuilder.java | 2 +- 11 files changed, 91 insertions(+), 67 deletions(-) diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index d4f1c9782..f03645d45 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -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(); diff --git a/src/java/org/apache/fop/control/Document.java b/src/java/org/apache/fop/control/Document.java index 364ba559d..a72de0b45 100644 --- a/src/java/org/apache/fop/control/Document.java +++ b/src/java/org/apache/fop/control/Document.java @@ -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. - *
- * 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; + } } diff --git a/src/java/org/apache/fop/extensions/Bookmarks.java b/src/java/org/apache/fop/extensions/Bookmarks.java index 0fa44f524..9152b7a56 100644 --- a/src/java/org/apache/fop/extensions/Bookmarks.java +++ b/src/java/org/apache/fop/extensions/Bookmarks.java @@ -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); } diff --git a/src/java/org/apache/fop/fo/FOInputHandler.java b/src/java/org/apache/fop/fo/FOInputHandler.java index 8e06247f4..e5eb71115 100644 --- a/src/java/org/apache/fop/fo/FOInputHandler.java +++ b/src/java/org/apache/fop/fo/FOInputHandler.java @@ -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; } /** diff --git a/src/java/org/apache/fop/fo/FOTreeHandler.java b/src/java/org/apache/fop/fo/FOTreeHandler.java index f3fede6a0..b1f09c01d 100644 --- a/src/java/org/apache/fop/fo/FOTreeHandler.java +++ b/src/java/org/apache/fop/fo/FOTreeHandler.java @@ -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; } /** diff --git a/src/java/org/apache/fop/mif/MIFHandler.java b/src/java/org/apache/fop/mif/MIFHandler.java index a5b65b4c0..7496ef90c 100644 --- a/src/java/org/apache/fop/mif/MIFHandler.java +++ b/src/java/org/apache/fop/mif/MIFHandler.java @@ -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); } /** diff --git a/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java b/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java index c48fe82aa..0312c3129 100644 --- a/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java +++ b/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java @@ -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); diff --git a/src/java/org/apache/fop/rtf/renderer/RTFHandler.java b/src/java/org/apache/fop/rtf/renderer/RTFHandler.java index 0d9933973..881f95619 100644 --- a/src/java/org/apache/fop/rtf/renderer/RTFHandler.java +++ b/src/java/org/apache/fop/rtf/renderer/RTFHandler.java @@ -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() */ diff --git a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java index 458c58e03..93880f1b4 100644 --- a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java @@ -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 @@ -42,12 +42,12 @@ * (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 . For more information on the Apache * Software Foundation, please see . - */ + */ 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 = ""; diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java index c992d51aa..07e01dbfb 100644 --- a/src/java/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java @@ -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(); diff --git a/src/java/org/apache/fop/tools/AreaTreeBuilder.java b/src/java/org/apache/fop/tools/AreaTreeBuilder.java index 0c64bbd1a..07b3683ff 100644 --- a/src/java/org/apache/fop/tools/AreaTreeBuilder.java +++ b/src/java/org/apache/fop/tools/AreaTreeBuilder.java @@ -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); -- 2.39.5