git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194436 13f79535-47bb-0310-9956-ffa450edef68pull/33/head
import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||
// FOP | // FOP | ||||
import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.configuration.Configuration; | import org.apache.fop.configuration.Configuration; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
// FOP | // FOP | ||||
import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.configuration.Configuration; | import org.apache.fop.configuration.Configuration; | ||||
/** | /** |
_treeBuilder.setLogger(log); | _treeBuilder.setLogger(log); | ||||
} | } | ||||
private Logger getLogger() { | |||||
if(log == null) { | |||||
Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); | |||||
PatternFormatter formatter = new PatternFormatter( | |||||
"[%{priority}]: %{message}\n%{throwable}" ); | |||||
LogTarget target = null; | |||||
target = new StreamTarget(System.out, formatter); | |||||
hierarchy.setDefaultLogTarget(target); | |||||
log = hierarchy.getLoggerFor("fop"); | |||||
log.setPriority(Priority.INFO); | |||||
log.error("Logger not set"); | |||||
} | |||||
return log; | |||||
} | |||||
/** | /** | ||||
* Resets the Driver so it can be reused. Property and element | * Resets the Driver so it can be reused. Property and element | ||||
* mappings are reset to defaults. | * mappings are reset to defaults. | ||||
* @param renderer the renderer instance to use | * @param renderer the renderer instance to use | ||||
*/ | */ | ||||
public void setRenderer(Renderer renderer) { | public void setRenderer(Renderer renderer) { | ||||
renderer.setLogger(getLogger()); | |||||
_renderer = renderer; | _renderer = renderer; | ||||
} | } | ||||
* events but isn't a SAX Parser itself. | * events but isn't a SAX Parser itself. | ||||
*/ | */ | ||||
public ContentHandler getContentHandler() { | public ContentHandler getContentHandler() { | ||||
if(log == null) { | |||||
Hierarchy hierarchy = Hierarchy.getDefaultHierarchy(); | |||||
PatternFormatter formatter = new PatternFormatter( | |||||
"[%{priority}]: %{message}\n%{throwable}" ); | |||||
LogTarget target = null; | |||||
target = new StreamTarget(System.out, formatter); | |||||
hierarchy.setDefaultLogTarget(target); | |||||
log = hierarchy.getLoggerFor("fop"); | |||||
log.setPriority(Priority.INFO); | |||||
log.error("Logger not set"); | |||||
} | |||||
StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer); | StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer); | ||||
streamRenderer.setLogger(log); | |||||
streamRenderer.setLogger(getLogger()); | |||||
_treeBuilder.setStreamRenderer(streamRenderer); | _treeBuilder.setStreamRenderer(streamRenderer); | ||||
return _treeBuilder; | return _treeBuilder; | ||||
*/ | */ | ||||
public void dumpError(Exception e) { | public void dumpError(Exception e) { | ||||
if (_errorDump) { | if (_errorDump) { | ||||
Logger log = getLogger(); | |||||
if (e instanceof SAXException) { | if (e instanceof SAXException) { | ||||
log.error("", e); | log.error("", e); | ||||
if (((SAXException)e).getException() != null) { | if (((SAXException)e).getException() != null) { |
import org.xml.sax.InputSource; | import org.xml.sax.InputSource; | ||||
import org.xml.sax.XMLReader; | import org.xml.sax.XMLReader; | ||||
// fop | |||||
import org.apache.fop.messaging.MessageHandler; | |||||
// java | // java | ||||
import java.io.File; | import java.io.File; | ||||
import java.net.URL; | import java.net.URL; |
import java.io.*; | import java.io.*; | ||||
import java.net.URL; | import java.net.URL; | ||||
// FOP | |||||
import org.apache.fop.messaging.MessageHandler; | |||||
/** | /** | ||||
* abstract super class | * abstract super class | ||||
* Creates a SAX Parser (defaulting to Xerces). | * Creates a SAX Parser (defaulting to Xerces). |
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.File; | import java.io.File; | ||||
// FOP | |||||
import org.apache.fop.messaging.MessageHandler; | |||||
/** | /** | ||||
* XSLTInputHandler basically takes an xmlfile and transforms it with an xsltfile | * XSLTInputHandler basically takes an xmlfile and transforms it with an xsltfile | ||||
* and the resulting xsl:fo document is input for Fop. | * and the resulting xsl:fo document is input for Fop. |
import java.io.*; | import java.io.*; | ||||
// FOP | // FOP | ||||
import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.tools.xslt.XSLTransform; | import org.apache.fop.tools.xslt.XSLTransform; | ||||
/** | /** |
/* | |||||
* $Id$ | |||||
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | |||||
* For details on use and redistribution please refer to the | |||||
* LICENSE file included with these sources." | |||||
*/ | |||||
package org.apache.fop.render; | |||||
// FOP | |||||
import org.apache.fop.pdf.PDFPathPaint; | |||||
import org.apache.fop.pdf.PDFColor; | |||||
import org.apache.fop.image.ImageArea; | |||||
import org.apache.fop.apps.FOPException; | |||||
import org.apache.fop.fo.properties.*; | |||||
import org.apache.fop.layout.*; | |||||
import org.apache.fop.layout.inline.*; | |||||
import org.apache.fop.datatypes.*; | |||||
import org.apache.fop.render.pdf.FontSetup; | |||||
import org.apache.fop.svg.SVGArea; | |||||
import org.apache.log.Logger; | |||||
// Java | |||||
import java.io.IOException; | |||||
import java.io.OutputStream; | |||||
import java.util.Enumeration; | |||||
/** | |||||
* Abstract base class for all renderers. | |||||
* | |||||
*/ | |||||
public abstract class AbstractRenderer implements Renderer { | |||||
protected Logger log; | |||||
public void setLogger(Logger logger) { | |||||
log = logger; | |||||
} | |||||
} |
/*--- formatted by Jindent 2.1, (www.c-lab.de/~jindent) ---*/ | |||||
/* | /* | ||||
* $Id$ | * $Id$ | ||||
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | ||||
// FOP | // FOP | ||||
import org.apache.fop.pdf.PDFPathPaint; | import org.apache.fop.pdf.PDFPathPaint; | ||||
import org.apache.fop.pdf.PDFColor; | import org.apache.fop.pdf.PDFColor; | ||||
// import org.apache.fop.render.Renderer; | |||||
// import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.image.ImageArea; | import org.apache.fop.image.ImageArea; | ||||
// import org.apache.fop.image.FopImage; | // import org.apache.fop.image.FopImage; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
* is not mentioned in this class but it is inherited from | * is not mentioned in this class but it is inherited from | ||||
* the Renderer interface. | * the Renderer interface. | ||||
*/ | */ | ||||
public abstract class PrintRenderer implements Renderer { | |||||
public abstract class PrintRenderer extends AbstractRenderer { | |||||
// vvv These are not currently referenced by the PrintRenderer, but are common to PCL and PDF renderers - so declare here. | // vvv These are not currently referenced by the PrintRenderer, but are common to PCL and PDF renderers - so declare here. | ||||
/** | /** |
/*--- formatted by Jindent 2.1, (www.c-lab.de/~jindent) ---*/ | |||||
/* | /* | ||||
* -- $Id$ -- | |||||
* ============================================================================ | |||||
* The Apache Software License, Version 1.1 | |||||
* ============================================================================ | |||||
* | |||||
* Copyright (C) 1999 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 | |||||
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- | |||||
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | |||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||||
* (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/>. | |||||
* | |||||
* $Id$ | |||||
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | |||||
* For details on use and redistribution please refer to the | |||||
* LICENSE file included with these sources. | |||||
*/ | */ | ||||
package org.apache.fop.render; | package org.apache.fop.render; | ||||
import org.apache.fop.layout.*; | import org.apache.fop.layout.*; | ||||
import org.apache.fop.layout.inline.*; | import org.apache.fop.layout.inline.*; | ||||
import org.apache.log.Logger; | |||||
// Java | // Java | ||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
*/ | */ | ||||
public interface Renderer { | public interface Renderer { | ||||
/** | |||||
* Set the logger | |||||
*/ | |||||
public void setLogger(Logger logger); | |||||
/** | /** | ||||
* set up the given FontInfo | * set up the given FontInfo | ||||
*/ | */ |
import org.apache.fop.layout.*; | import org.apache.fop.layout.*; | ||||
import org.apache.fop.layout.inline.*; | import org.apache.fop.layout.inline.*; | ||||
import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.datatypes.*; | import org.apache.fop.datatypes.*; | ||||
import org.apache.fop.image.*; | import org.apache.fop.image.*; | ||||
import org.apache.fop.svg.*; | import org.apache.fop.svg.*; | ||||
import java.awt.image.BufferedImage; | import java.awt.image.BufferedImage; | ||||
import java.text.*; | import java.text.*; | ||||
import org.apache.fop.render.Renderer; | |||||
import org.apache.fop.render.AbstractRenderer; | |||||
/** | /** | ||||
Modified by Mark Lillywhite mark-fop@inomial.com. Did lots of | Modified by Mark Lillywhite mark-fop@inomial.com. Did lots of | ||||
interface. This class could also do with a general audit, | interface. This class could also do with a general audit, | ||||
and I suspect it's not swing-thread-safe either. | and I suspect it's not swing-thread-safe either. | ||||
*/ | */ | ||||
public class AWTRenderer implements Renderer, Printable, Pageable { | |||||
public class AWTRenderer extends AbstractRenderer implements Printable, Pageable { | |||||
protected int pageWidth = 0; | protected int pageWidth = 0; | ||||
protected int pageHeight = 0; | protected int pageHeight = 0; | ||||
FopImage img = area.getImage(); | FopImage img = area.getImage(); | ||||
if (img == null) { | if (img == null) { | ||||
MessageHandler.logln("Error while loading image : area.getImage() is null"); | |||||
log.error("Error while loading image : area.getImage() is null"); | |||||
// correct integer roundoff | // correct integer roundoff | ||||
// graphics.drawRect(x / 1000, pageHeight - y / 1000, | // graphics.drawRect(x / 1000, pageHeight - y / 1000, | ||||
* (int) height, imageIcon.getImageObserver()); | * (int) height, imageIcon.getImageObserver()); | ||||
* graphics.drawImage(bi, bop, (int) x, (int) y); | * graphics.drawImage(bi, bop, (int) x, (int) y); | ||||
* } catch (Exception ex) { | * } catch (Exception ex) { | ||||
* MessageHandler.errorln("AWTRenderer: renderImage(): " + | |||||
* ex.getMessage()); | |||||
* log.error("AWTRenderer: renderImage(): " + | |||||
* ex.getMessage(), ex); | |||||
* } | * } | ||||
* } | * } | ||||
*/ | */ |
// FOP | // FOP | ||||
import org.apache.fop.render.Renderer; | import org.apache.fop.render.Renderer; | ||||
import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.render.AbstractRenderer; | |||||
import org.apache.fop.image.ImageArea; | import org.apache.fop.image.ImageArea; | ||||
import org.apache.fop.image.FopImage; | import org.apache.fop.image.FopImage; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
* it should still work. I don't have an MIF view to test it with, | * it should still work. I don't have an MIF view to test it with, | ||||
* you see. | * you see. | ||||
*/ | */ | ||||
public class MIFRenderer implements Renderer { | |||||
public class MIFRenderer extends AbstractRenderer { | |||||
private String currentFontName; | private String currentFontName; | ||||
private String currentFontSize; | private String currentFontSize; | ||||
* } | * } | ||||
*/ | */ | ||||
MessageHandler.logln("Warning: SVG images not supported in this version"); | |||||
log.warn("SVG images not supported in this version"); | |||||
} else { | } else { | ||||
String url = img.getURL(); | String url = img.getURL(); | ||||
this.mifDoc.addImage(url, x, pageHeight - y, w, h); | this.mifDoc.addImage(url, x, pageHeight - y, w, h); | ||||
*/ | */ | ||||
public void startRenderer(OutputStream outputStream) | public void startRenderer(OutputStream outputStream) | ||||
throws IOException { | throws IOException { | ||||
MessageHandler.logln("rendering areas to MIF"); | |||||
log.info("rendering areas to MIF"); | |||||
} | } | ||||
/** | /** | ||||
*/ | */ | ||||
public void stopRenderer(OutputStream outputStream) | public void stopRenderer(OutputStream outputStream) | ||||
throws IOException { | throws IOException { | ||||
MessageHandler.logln("writing out MIF"); | |||||
log.info("writing out MIF"); | |||||
this.mifDoc.output(outputStream); | this.mifDoc.output(outputStream); | ||||
outputStream.flush(); | outputStream.flush(); | ||||
} | } |
// FOP | // FOP | ||||
import org.apache.fop.render.PrintRenderer; | import org.apache.fop.render.PrintRenderer; | ||||
import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.image.ImageArea; | import org.apache.fop.image.ImageArea; | ||||
import org.apache.fop.image.FopImage; | import org.apache.fop.image.FopImage; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
int xpos = xoffset + (x / 100); | int xpos = xoffset + (x / 100); | ||||
if (xpos < 0) { | if (xpos < 0) { | ||||
xpos = 0; | xpos = 0; | ||||
MessageHandler.errorln("PCLRenderer.addRect() WARNING: Horizontal position out of bounds."); | |||||
log.error("PCLRenderer.addRect() WARNING: Horizontal position out of bounds."); | |||||
} | } | ||||
currentStream.add("\033*v1O\033&a" + xpos + "h" | currentStream.add("\033*v1O\033&a" + xpos + "h" | ||||
xpos = xoffset + ((x + 240) / 100); | xpos = xoffset + ((x + 240) / 100); | ||||
if (xpos < 0) { | if (xpos < 0) { | ||||
xpos = 0; | xpos = 0; | ||||
MessageHandler.errorln("PCLRenderer.addRect() WARNING: Horizontal position out of bounds."); | |||||
log.error("PCLRenderer.addRect() WARNING: Horizontal position out of bounds."); | |||||
} | } | ||||
currentStream.add("\033&a" + xpos + "h" | currentStream.add("\033&a" + xpos + "h" | ||||
+ (pageHeight - ((y + 240)) / 100) + "V" | + (pageHeight - ((y + 240)) / 100) + "V" | ||||
int xpos = xoffset + (x / 100); | int xpos = xoffset + (x / 100); | ||||
if (xpos < 0) { | if (xpos < 0) { | ||||
xpos = 0; | xpos = 0; | ||||
MessageHandler.errorln("PCLRenderer.renderImageArea() WARNING: Horizontal position out of bounds."); | |||||
log.error("PCLRenderer.renderImageArea() WARNING: Horizontal position out of bounds."); | |||||
} | } | ||||
currentStream.add("\033&a" + xpos + "h" + (pageHeight - (y / 100)) | currentStream.add("\033&a" + xpos + "h" + (pageHeight - (y / 100)) | ||||
printBMP(img, x, y, w, h); | printBMP(img, x, y, w, h); | ||||
} catch (FopImageException e) { | } catch (FopImageException e) { | ||||
// e.printStackTrace(System.out); | // e.printStackTrace(System.out); | ||||
MessageHandler.errorln("PCLRenderer.renderImageArea() Error printing BMP (" | |||||
log.error("PCLRenderer.renderImageArea() Error printing BMP (" | |||||
+ e.toString() + ")"); | + e.toString() + ")"); | ||||
} | } | ||||
} | } | ||||
int xpos = xoffset + (rx / 100); | int xpos = xoffset + (rx / 100); | ||||
if (xpos < 0) { | if (xpos < 0) { | ||||
xpos = 0; | xpos = 0; | ||||
MessageHandler.errorln("PCLRenderer.renderWordArea() WARNING: Horizontal position out of bounds."); | |||||
log.error("PCLRenderer.renderWordArea() WARNING: Horizontal position out of bounds."); | |||||
} | } | ||||
currentStream.add("\033&a" + xpos + "h" + (pageHeight - (bl / 100)) | currentStream.add("\033&a" + xpos + "h" + (pageHeight - (bl / 100)) | ||||
+ "V" + s); | + "V" + s); | ||||
} | } | ||||
public void startRenderer(OutputStream outputStream) | public void startRenderer(OutputStream outputStream) | ||||
throws IOException { | throws IOException { | ||||
MessageHandler.logln("rendering areas to PCL"); | |||||
log.info("rendering areas to PCL"); | |||||
currentStream = new PCLStream(outputStream); | currentStream = new PCLStream(outputStream); | ||||
// Set orientation. | // Set orientation. | ||||
public void stopRenderer(OutputStream outputStream) | public void stopRenderer(OutputStream outputStream) | ||||
throws IOException { | throws IOException { | ||||
MessageHandler.logln("writing out PCL"); | |||||
log.info("writing out PCL"); | |||||
outputStream.flush(); | outputStream.flush(); | ||||
} | } | ||||
// FOP | // FOP | ||||
import org.apache.fop.render.PrintRenderer; | import org.apache.fop.render.PrintRenderer; | ||||
import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.image.ImageArea; | import org.apache.fop.image.ImageArea; | ||||
import org.apache.fop.image.FopImage; | import org.apache.fop.image.FopImage; | ||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
root.paint(graphics, rc); | root.paint(graphics, rc); | ||||
currentStream.add(graphics.getString()); | currentStream.add(graphics.getString()); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
MessageHandler.errorln("Error: svg graphic could not be rendered: " | |||||
+ e.getMessage()); | |||||
log.error("svg graphic could not be rendered: " | |||||
+ e.getMessage(), e); | |||||
} | } | ||||
currentAnnotList = graphics.getAnnotList(); | currentAnnotList = graphics.getAnnotList(); | ||||
public void render(Page page, OutputStream outputStream) | public void render(Page page, OutputStream outputStream) | ||||
throws FOPException, IOException { | throws FOPException, IOException { | ||||
// MessageHandler.logln("rendering single page to PDF"); | |||||
// log.debug("rendering single page to PDF"); | |||||
this.idReferences = page.getIDReferences(); | this.idReferences = page.getIDReferences(); | ||||
this.pdfResources = this.pdfDoc.getResources(); | this.pdfResources = this.pdfDoc.getResources(); | ||||
this.pdfDoc.setIDReferences(idReferences); | this.pdfDoc.setIDReferences(idReferences); | ||||
// TODO: this needs to be implemented | // TODO: this needs to be implemented | ||||
renderRootExtensions(page); | renderRootExtensions(page); | ||||
// MessageHandler.logln("writing out PDF"); | |||||
// log.debug("writing out PDF"); | |||||
this.pdfDoc.output(outputStream); | this.pdfDoc.output(outputStream); | ||||
} | } | ||||
PDFOutline pdfParentOutline = | PDFOutline pdfParentOutline = | ||||
(PDFOutline)parent.getRendererObject(); | (PDFOutline)parent.getRendererObject(); | ||||
if (pdfParentOutline == null) { | if (pdfParentOutline == null) { | ||||
MessageHandler.errorln("Error: pdfParentOutline is null"); | |||||
log.error("pdfParentOutline is null"); | |||||
} else { | } else { | ||||
pdfOutline = | pdfOutline = | ||||
this.pdfDoc.makeOutline(pdfParentOutline, | this.pdfDoc.makeOutline(pdfParentOutline, |
package org.apache.fop.render.ps; | package org.apache.fop.render.ps; | ||||
// FOP | // FOP | ||||
import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.svg.SVGArea; | import org.apache.fop.svg.SVGArea; | ||||
import org.apache.fop.render.AbstractRenderer; | |||||
import org.apache.fop.render.Renderer; | import org.apache.fop.render.Renderer; | ||||
import org.apache.fop.image.ImageArea; | import org.apache.fop.image.ImageArea; | ||||
import org.apache.fop.image.FopImage; | import org.apache.fop.image.FopImage; | ||||
import org.apache.batik.gvt.filter.*; | import org.apache.batik.gvt.filter.*; | ||||
import org.apache.batik.gvt.event.*; | import org.apache.batik.gvt.event.*; | ||||
import org.apache.log.Logger; | |||||
// SVG | // SVG | ||||
import org.w3c.dom.svg.SVGSVGElement; | import org.w3c.dom.svg.SVGSVGElement; | ||||
import org.w3c.dom.svg.SVGDocument; | import org.w3c.dom.svg.SVGDocument; | ||||
* | * | ||||
* @author Jeremias Märki | * @author Jeremias Märki | ||||
*/ | */ | ||||
public class PSRenderer implements Renderer { | |||||
public class PSRenderer extends AbstractRenderer { | |||||
/** | /** | ||||
* the application producing the PostScript | * the application producing the PostScript | ||||
write(sx + " " + sy + " " + " scale"); | write(sx + " " + sy + " " + " scale"); | ||||
UserAgent userAgent = new MUserAgent(new AffineTransform()); | |||||
UserAgent userAgent = new MUserAgent(new AffineTransform(), log); | |||||
GVTBuilder builder = new GVTBuilder(); | GVTBuilder builder = new GVTBuilder(); | ||||
GraphicsNodeRenderContext rc = getRenderContext(); | GraphicsNodeRenderContext rc = getRenderContext(); | ||||
root = builder.build(ctx, doc); | root = builder.build(ctx, doc); | ||||
root.paint(graphics, rc); | root.paint(graphics, rc); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
MessageHandler.errorln("Error: svg graphic could not be rendered: " | |||||
+ e.getMessage()); | |||||
// e.printStackTrace(); | |||||
log.error("svg graphic could not be rendered: " | |||||
+ e.getMessage(), e); | |||||
} | } | ||||
write(""); | write(""); | ||||
write("grestore"); | write("grestore"); | ||||
} catch (FopImageException e) { | } catch (FopImageException e) { | ||||
e.printStackTrace(); | |||||
MessageHandler.errorln("PSRenderer.renderImageArea(): Error rendering bitmap (" | |||||
+ e.toString() + ")"); | |||||
log.error("PSRenderer.renderImageArea(): Error rendering bitmap (" | |||||
+ e.getMessage() + ")", e); | |||||
} | } | ||||
} | } | ||||
break; | break; | ||||
case LeaderPattern.DOTS: | case LeaderPattern.DOTS: | ||||
comment("% --- Leader dots NYI"); | comment("% --- Leader dots NYI"); | ||||
MessageHandler.errorln("Leader dots: Not yet implemented"); | |||||
log.error("Leader dots: Not yet implemented"); | |||||
break; | break; | ||||
case LeaderPattern.USECONTENT: | case LeaderPattern.USECONTENT: | ||||
comment("% --- Leader use-content NYI"); | comment("% --- Leader use-content NYI"); | ||||
MessageHandler.errorln("Leader use-content: Not yet implemented"); | |||||
log.error("Leader use-content: Not yet implemented"); | |||||
break; | break; | ||||
} | } | ||||
this.currentXPosition += area.getContentWidth(); | this.currentXPosition += area.getContentWidth(); | ||||
protected class MUserAgent implements UserAgent { | protected class MUserAgent implements UserAgent { | ||||
AffineTransform currentTransform = null; | AffineTransform currentTransform = null; | ||||
Logger log; | |||||
/** | /** | ||||
* Creates a new SVGUserAgent. | * Creates a new SVGUserAgent. | ||||
*/ | */ | ||||
protected MUserAgent(AffineTransform at) { | |||||
protected MUserAgent(AffineTransform at, Logger logger) { | |||||
currentTransform = at; | currentTransform = at; | ||||
log = logger; | |||||
} | } | ||||
/** | /** | ||||
* Displays an error message. | * Displays an error message. | ||||
*/ | */ | ||||
public void displayError(String message) { | public void displayError(String message) { | ||||
System.err.println(message); | |||||
log.error(message); | |||||
} | } | ||||
/** | /** | ||||
* Displays an error resulting from the specified Exception. | * Displays an error resulting from the specified Exception. | ||||
*/ | */ | ||||
public void displayError(Exception ex) { | public void displayError(Exception ex) { | ||||
ex.printStackTrace(System.err); | |||||
log.error("SVG Error" + ex.getMessage(), ex); | |||||
} | } | ||||
/** | /** | ||||
* The given message is typically displayed in a status bar. | * The given message is typically displayed in a status bar. | ||||
*/ | */ | ||||
public void displayMessage(String message) { | public void displayMessage(String message) { | ||||
System.out.println(message); | |||||
log.info(message); | |||||
} | } | ||||
/** | /** | ||||
*/ | */ | ||||
public void startRenderer(OutputStream outputStream) | public void startRenderer(OutputStream outputStream) | ||||
throws IOException { | throws IOException { | ||||
MessageHandler.logln("rendering areas to PostScript"); | |||||
log.debug("rendering areas to PostScript"); | |||||
this.out = new PSStream(outputStream); | this.out = new PSStream(outputStream); | ||||
write("%!PS-Adobe-3.0"); | write("%!PS-Adobe-3.0"); | ||||
write("%%Trailer"); | write("%%Trailer"); | ||||
write("%%EOF"); | write("%%EOF"); | ||||
this.out.flush(); | this.out.flush(); | ||||
MessageHandler.logln("written out PostScript"); | |||||
log.debug("written out PostScript"); | |||||
} | } | ||||
public void render(Page page, OutputStream outputStream) { | public void render(Page page, OutputStream outputStream) { |
// FOP | // FOP | ||||
import org.apache.fop.render.PrintRenderer; | import org.apache.fop.render.PrintRenderer; | ||||
import org.apache.fop.render.pcl.*; | import org.apache.fop.render.pcl.*; | ||||
import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.apps.FOPException; | import org.apache.fop.apps.FOPException; | ||||
import org.apache.fop.fo.properties.*; | import org.apache.fop.fo.properties.*; | ||||
import org.apache.fop.layout.*; | import org.apache.fop.layout.*; | ||||
printBMP(img, x, y, w, h); | printBMP(img, x, y, w, h); | ||||
} catch (FopImageException e) { | } catch (FopImageException e) { | ||||
// e.printStackTrace(System.out); | // e.printStackTrace(System.out); | ||||
MessageHandler.errorln("TXTRenderer.renderImageArea() Error printing BMP (" | |||||
+ e.toString() + ")."); | |||||
log.error("TXTRenderer.renderImageArea() printing BMP (" | |||||
+ e.toString() + ").", e); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
MessageHandler.errorln("could not add image to SVG: " + href); | |||||
log.error("could not add image to SVG: " + href, e); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public void startRenderer(OutputStream outputStream) | public void startRenderer(OutputStream outputStream) | ||||
throws IOException { | throws IOException { | ||||
MessageHandler.logln("rendering areas to TEXT"); | |||||
log.info("rendering areas to TEXT"); | |||||
currentStream = new PCLStream(outputStream); | currentStream = new PCLStream(outputStream); | ||||
firstPage=true; | firstPage=true; | ||||
} | } | ||||
public void stopRenderer(OutputStream outputStream) | public void stopRenderer(OutputStream outputStream) | ||||
throws IOException { | throws IOException { | ||||
MessageHandler.logln("writing out TEXT"); | |||||
log.info("writing out TEXT"); | |||||
outputStream.flush(); | outputStream.flush(); | ||||
} | } | ||||
// FOP | // FOP | ||||
import org.apache.fop.svg.*; | import org.apache.fop.svg.*; | ||||
import org.apache.fop.messaging.MessageHandler; | |||||
import org.apache.fop.render.Renderer; | import org.apache.fop.render.Renderer; | ||||
import org.apache.fop.render.AbstractRenderer; | |||||
import org.apache.fop.image.ImageArea; | import org.apache.fop.image.ImageArea; | ||||
import org.apache.fop.layout.*; | import org.apache.fop.layout.*; | ||||
import org.apache.fop.layout.inline.*; | import org.apache.fop.layout.inline.*; | ||||
* Modified by Mark Lillywhite mark-fop@inomial.com to use the | * Modified by Mark Lillywhite mark-fop@inomial.com to use the | ||||
* new renderer interface. Not 100% certain that this is correct. | * new renderer interface. Not 100% certain that this is correct. | ||||
*/ | */ | ||||
public class XMLRenderer implements Renderer { | |||||
public class XMLRenderer extends AbstractRenderer { | |||||
/** | /** | ||||
* indentation to use for pretty-printing the XML | * indentation to use for pretty-printing the XML | ||||
*/ | */ | ||||
public void startRenderer(OutputStream outputStream) | public void startRenderer(OutputStream outputStream) | ||||
throws IOException { | throws IOException { | ||||
MessageHandler.logln("rendering areas to XML"); | |||||
log.info("rendering areas to XML"); | |||||
this.writer = new PrintWriter(outputStream); | this.writer = new PrintWriter(outputStream); | ||||
this.writer.write( "<?xml version=\"1.0\"?>\n<!-- produced by " + | this.writer.write( "<?xml version=\"1.0\"?>\n<!-- produced by " + | ||||
this.producer + " -->\n"); | this.producer + " -->\n"); | ||||
throws IOException { | throws IOException { | ||||
writeEndTag("</AreaTree>"); | writeEndTag("</AreaTree>"); | ||||
this.writer.flush(); | this.writer.flush(); | ||||
MessageHandler.errorln("written out XML"); | |||||
log.error("written out XML"); | |||||
} | } | ||||
} | } |
} | } | ||||
private void setupLogging() { | private void setupLogging() { | ||||
log = Hierarchy.getDefaultHierarchy().getLoggerFor("testing"); | |||||
log = Hierarchy.getDefaultHierarchy().getLoggerFor("test"); | |||||
} | } | ||||
public void setOutputPDF(boolean pdf) { | public void setOutputPDF(boolean pdf) { |
} | } | ||||
} | } | ||||
/* | |||||
class MessageLogger implements MessageListener { | class MessageLogger implements MessageListener { | ||||
MessageHandler handler; | MessageHandler handler; | ||||
Task task; | Task task; | ||||
} | } | ||||
} | } | ||||
*/ |