// 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;
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;
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;
private AreaTree areaTree;
private AreaTreeModel atModel;
+ private Document currentDocument = null;
+
/**
* Main constructor for the Driver class.
*/
// 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());
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;
* @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();
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;
/** 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();
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;
+ }
}
}
// 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);
}
*/
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;
}
/**
*/
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.
* @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();
}
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"));
}
* @return the font information
*/
public Document getFontInfo() {
- return this.fontInfo;
+ return this.doc;
}
/**
protected MIFFile mifFile;
/** the OutputStream to write to */
protected OutputStream outStream;
- private Document fontInfo = new Document();
// current state elements
private MIFElement textFlow;
* 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);
}
/**
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);
*/
public class RTFHandler extends FOInputHandler {
- private Document fontInfo = new Document();
private RtfFile rtfFile;
private final OutputStream os;
private RtfSection sect;
* 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()
*/
* ============================================================================
* 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;
*/
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;
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);
*/
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);
this.pdfDoc.setFilterMap(
PDFFilterList.buildFilterMapFromConfiguration(cfg));
}
-
+
graphicsState = new PDFState();
currentFontName = "";
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();
rend = new SVGRenderer();
}
setupLogger(rend);
- Document fi = new Document();
+ Document fi = new Document(null);
rend.setupFontInfo(fi);
FOUserAgent ua = new FOUserAgent();
setupLogger(ua);