diff options
-rw-r--r-- | src/org/apache/fop/fo/flow/ExternalGraphic.java | 8 | ||||
-rw-r--r-- | src/org/apache/fop/image/AbstractFopImage.java | 6 | ||||
-rw-r--r-- | src/org/apache/fop/image/FopImage.java | 1 | ||||
-rw-r--r-- | src/org/apache/fop/image/ImageFactory.java | 4 | ||||
-rw-r--r-- | src/org/apache/fop/image/XMLImage.java (renamed from src/org/apache/fop/image/SVGImage.java) | 30 | ||||
-rw-r--r-- | src/org/apache/fop/image/analyser/ImageReaderFactory.java | 3 | ||||
-rw-r--r-- | src/org/apache/fop/image/analyser/SVGReader.java | 65 | ||||
-rw-r--r-- | src/org/apache/fop/image/analyser/XMLReader.java | 98 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFRenderer.java | 129 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFXMLHandler.java | 173 | ||||
-rw-r--r-- | src/org/apache/fop/svg/PDFGraphics2D.java | 1 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGElementMapping.java | 19 |
12 files changed, 496 insertions, 41 deletions
diff --git a/src/org/apache/fop/fo/flow/ExternalGraphic.java b/src/org/apache/fop/fo/flow/ExternalGraphic.java index f3b6e59b0..1183afdea 100644 --- a/src/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/org/apache/fop/fo/flow/ExternalGraphic.java @@ -48,12 +48,14 @@ public class ExternalGraphic extends FObj { } protected InlineArea getInlineArea() { + setup(); if(url == null) { return null; } url = ImageFactory.getURL(url); // if we need to load this image to get its size - // FopImage fopimage = ImageFactory.getImage(url, userAgent); + ImageFactory fact = ImageFactory.getInstance(); + FopImage fopimage = fact.getImage(url, userAgent); // if(fopimage == null) { // error // } @@ -65,7 +67,7 @@ public class ExternalGraphic extends FObj { return vp; } - public void setup() throws FOPException { + public void setup() { // Common Accessibility Properties AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); @@ -102,7 +104,7 @@ public class ExternalGraphic extends FObj { // this.properties.get("overflow"); // this.properties.get("scaling"); // this.properties.get("scaling-method"); - // this.properties.get("src"); + url = this.properties.get("src").getString(); // this.properties.get("text-align"); // this.properties.get("width"); } diff --git a/src/org/apache/fop/image/AbstractFopImage.java b/src/org/apache/fop/image/AbstractFopImage.java index 3fa021eea..9b3a91d73 100644 --- a/src/org/apache/fop/image/AbstractFopImage.java +++ b/src/org/apache/fop/image/AbstractFopImage.java @@ -100,7 +100,7 @@ public abstract class AbstractFopImage implements FopImage { this.imageInfo = info; this.m_width = this.imageInfo.width; this.m_height = this.imageInfo.height; - loaded = loaded & DIMENSIONS; + loaded = loaded | DIMENSIONS; } public String getMimeType() { @@ -121,12 +121,12 @@ public abstract class AbstractFopImage implements FopImage { if(!success) { return false; } - loaded = loaded & DIMENSIONS; + loaded = loaded | DIMENSIONS; } if(((type & BITMAP) != 0) && ((loaded & BITMAP) == 0)) { success = success && loadBitmap(ua); if(success) { - loaded = loaded & BITMAP; + loaded = loaded | BITMAP; } } return success; diff --git a/src/org/apache/fop/image/FopImage.java b/src/org/apache/fop/image/FopImage.java index 703616aae..d7b60a62c 100644 --- a/src/org/apache/fop/image/FopImage.java +++ b/src/org/apache/fop/image/FopImage.java @@ -70,6 +70,7 @@ public interface FopImage { public int height; public Object data; public String mimeType; + public String str; } } diff --git a/src/org/apache/fop/image/ImageFactory.java b/src/org/apache/fop/image/ImageFactory.java index e2217ba56..6eccd37c2 100644 --- a/src/org/apache/fop/image/ImageFactory.java +++ b/src/org/apache/fop/image/ImageFactory.java @@ -186,7 +186,9 @@ public class ImageFactory { imgClassName = "org.apache.fop.image.JimiImage"; // imgClassName = "org.apache.fop.image.JAIImage"; } else if ("image/svg+xml".equals(imgMimeType)) { - imgClassName = "org.apache.fop.image.SVGImage"; + imgClassName = "org.apache.fop.image.XMLImage"; + } else if ("text/xml".equals(imgMimeType)) { + imgClassName = "org.apache.fop.image.XMLImage"; } if (imgClassName == null) { log.error("Unsupported image type (" + diff --git a/src/org/apache/fop/image/SVGImage.java b/src/org/apache/fop/image/XMLImage.java index 95d7b5d09..a6e47df50 100644 --- a/src/org/apache/fop/image/SVGImage.java +++ b/src/org/apache/fop/image/XMLImage.java @@ -9,7 +9,7 @@ package org.apache.fop.image; // Java import java.net.URL; -import org.w3c.dom.svg.SVGDocument; +import org.w3c.dom.Document; // FOP import org.apache.fop.apps.Driver; @@ -17,20 +17,20 @@ import org.apache.fop.image.analyser.ImageReader; import org.apache.fop.image.analyser.SVGReader; import org.apache.fop.fo.FOUserAgent; -import org.apache.batik.dom.svg.SAXSVGDocumentFactory; - /** * @see AbstractFopImage * @see FopImage */ -public class SVGImage extends AbstractFopImage { - SVGDocument doc; +public class XMLImage extends AbstractFopImage { + Document doc; + String ns = ""; - public SVGImage(URL href, FopImage.ImageInfo imgInfo) { + public XMLImage(URL href, FopImage.ImageInfo imgInfo) { super(href, imgInfo); - if(imgInfo.data instanceof SVGDocument) { - doc = (SVGDocument)imgInfo.data; + if(imgInfo.data instanceof Document) { + doc = (Document)imgInfo.data; } + ns = imgInfo.str; } /** @@ -45,20 +45,14 @@ public class SVGImage extends AbstractFopImage { } protected boolean loadData(FOUserAgent ua) { - try { - SAXSVGDocumentFactory factory = - new SAXSVGDocumentFactory(SVGImage.getParserName()); - doc = factory.createDocument(this.m_href.toExternalForm()); - } catch (Exception e) { - ua.getLogger().error("Could not load external SVG: " - + e.getMessage(), e); - return false; - } return true; } - public SVGDocument getSVGDocument() { + public Document getDocument() { return doc; } + public String getNameSpace() { + return ns; + } } diff --git a/src/org/apache/fop/image/analyser/ImageReaderFactory.java b/src/org/apache/fop/image/analyser/ImageReaderFactory.java index 8d45e48a7..66d6aeb35 100644 --- a/src/org/apache/fop/image/analyser/ImageReaderFactory.java +++ b/src/org/apache/fop/image/analyser/ImageReaderFactory.java @@ -30,7 +30,10 @@ public class ImageReaderFactory { formats.add(new PNGReader()); formats.add(new TIFFReader()); formats.add(new EPSReader()); + // the xml parser through batik closes the stream when finished + // so there is a workaround in the SVGReader formats.add(new SVGReader()); + formats.add(new XMLReader()); }; // TODO - a way to add other readers diff --git a/src/org/apache/fop/image/analyser/SVGReader.java b/src/org/apache/fop/image/analyser/SVGReader.java index feecadcb2..8791b3420 100644 --- a/src/org/apache/fop/image/analyser/SVGReader.java +++ b/src/org/apache/fop/image/analyser/SVGReader.java @@ -15,7 +15,7 @@ import org.w3c.dom.svg.SVGDocument; import org.w3c.dom.svg.SVGSVGElement; // FOP -import org.apache.fop.image.SVGImage; +import org.apache.fop.image.XMLImage; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; @@ -38,6 +38,7 @@ import org.w3c.dom.DOMImplementation; import org.apache.batik.dom.svg.SVGDOMImplementation; import java.io.File; +import java.io.InputStream; import java.net.URL; import java.util.List; import java.util.ArrayList; @@ -94,18 +95,69 @@ public class SVGReader implements ImageReader { * the SVGReader class. */ class Loader { - private FopImage.ImageInfo getImage(String uri, BufferedInputStream fis, + private FopImage.ImageInfo getImage(String uri, InputStream fis, FOUserAgent ua) { // parse document and get the size attributes of the svg element try { + int length = 5; + fis.mark(length); + byte[] b = new byte[length]; + fis.read(b); + String start = new String(b); + fis.reset(); + + if(start.equals("<?xml")) { + // we have xml, might be another doc + // so stop batik from closing the stream + final InputStream input = fis; + fis = new InputStream() { + public int read() throws IOException { + return input.read(); + } + + public int read(byte[] b) throws IOException { + return input.read(b); + } + + public int read(byte[] b, int off, int len) throws IOException { + return input.read(b, off, len); + } + + public long skip(long n) throws IOException { + return input.skip(n); + } + + public int available() throws IOException { + return input.available(); + } + + public void mark(int rl) { + input.mark(rl); + } + + public boolean markSupported() { + return input.markSupported(); + } + + public void reset() throws IOException { + input.reset(); + } + + public void close() throws IOException { + } + }; + } + FopImage.ImageInfo info = new FopImage.ImageInfo(); + info.mimeType = getMimeType(); + info.str = SVGDOMImplementation.SVG_NAMESPACE_URI; - int length = fis.available(); - fis.mark(length); + length = fis.available(); + fis.mark(length + 1); SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory( - SVGImage.getParserName()); + XMLImage.getParserName()); SVGDocument doc = factory.createDocument(uri, fis); info.data = doc; @@ -138,6 +190,9 @@ public class SVGReader implements ImageReader { return info; } catch (NoClassDefFoundError ncdfe) { + try { + fis.reset(); + } catch (IOException ioe) { } batik = false; //ua.getLogger().error("Batik not in class path", ncdfe); return null; diff --git a/src/org/apache/fop/image/analyser/XMLReader.java b/src/org/apache/fop/image/analyser/XMLReader.java new file mode 100644 index 000000000..ab66be981 --- /dev/null +++ b/src/org/apache/fop/image/analyser/XMLReader.java @@ -0,0 +1,98 @@ +/* + * $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.image.analyser; + +// Java +import java.io.BufferedInputStream; +import java.io.IOException; + +import org.xml.sax.InputSource; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.*; +import org.w3c.dom.DOMImplementation; + +import java.io.File; +import java.net.URL; +import java.util.HashMap; + +import org.apache.fop.image.FopImage; +import org.apache.fop.fo.FOUserAgent; +import org.apache.fop.image.XMLImage; + +/** + * ImageReader object for XML document image type. + */ +public class XMLReader implements ImageReader { + private static HashMap converters = new HashMap(); + + public static void setConverter(String ns, Converter conv) { + converters.put(ns, conv); + } + + public XMLReader() { + } + + public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis, + FOUserAgent ua) throws IOException { + return loadImage(uri, fis, ua); + } + + public String getMimeType() { + return "text/xml"; + } + + /** + * This means the external svg document will be loaded twice. + * Possibly need a slightly different design for the image stuff. + */ + protected FopImage.ImageInfo loadImage(String uri, BufferedInputStream fis, + FOUserAgent ua) { + return createDocument(fis, ua); + } + + public FopImage.ImageInfo createDocument(BufferedInputStream is, FOUserAgent ua) { + Document doc = null; + FopImage.ImageInfo info = new FopImage.ImageInfo(); + info.mimeType = getMimeType(); + + try { + int length = is.available(); + is.mark(length); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + doc = dbf.newDocumentBuilder().parse(is); + info.data = doc; + + Element root = doc.getDocumentElement(); + ua.getLogger().debug("ns:" + root.getAttribute("xmlns")); + String ns = root.getAttribute("xmlns"); + info.str = ns; + + Converter conv = (Converter)converters.get(ns); + if(conv != null) { + FopImage.ImageInfo i = conv.convert(doc); + if(i != null) { + info = i; + } + } + } catch (Exception e) { + e.printStackTrace(); + try { + is.reset(); + } catch (IOException ioe) { } + return null; + } + return info; + } + + public static interface Converter { + public FopImage.ImageInfo convert(Document doc); + } +} + diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 1aadad141..4713c38ef 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -9,7 +9,10 @@ package org.apache.fop.render.pdf; // FOP import org.apache.fop.render.PrintRenderer; -import org.apache.fop.image.FopImage; +import org.apache.fop.render.XMLHandler; +import org.apache.fop.render.RendererContext; +import org.apache.fop.fo.FOUserAgent; +import org.apache.fop.image.*; import org.apache.fop.apps.FOPException; import org.apache.fop.fo.properties.*; import org.apache.fop.datatypes.*; @@ -54,6 +57,7 @@ text decoration * */ public class PDFRenderer extends PrintRenderer { + public static final String mimeType = "application/pdf"; /** * the PDF Document being created @@ -142,6 +146,14 @@ public class PDFRenderer extends PrintRenderer { producer = prod; } + public void setUserAgent(FOUserAgent agent) { + super.setUserAgent(agent); + PDFXMLHandler xmlHandler = new PDFXMLHandler(); + //userAgent.setDefaultXMLHandler(mimeType, xmlHandler); + String svg = "http://www.w3.org/2000/svg"; + userAgent.addXMLHandler(mimeType, svg, xmlHandler); + } + public void startRenderer(OutputStream stream) throws IOException { ostream = stream; this.pdfDoc = new PDFDocument(); @@ -225,21 +237,20 @@ public class PDFRenderer extends PrintRenderer { // multiply with current CTM currentStream.add(ctm.toPDFctm() + " cm\n"); // Set clip? + currentStream.add("BT\n"); } protected void endVParea() { + currentStream.add("ET\n"); currentStream.add("Q\n"); } protected void renderRegion(RegionReference region) { // Draw a rectangle so we can see it! // x=0,y=0,w=ipd,h=bpd - currentStream.add("BT\n"); super.renderRegion(region); - currentStream.add("ET\n"); } - protected void renderLineArea(LineArea line) { super.renderLineArea(line); closeText(); @@ -448,5 +459,115 @@ public class PDFRenderer extends PrintRenderer { pdf = pdf.append("/" + name + " " + (size / 1000) + " Tf\n"); } } + + public void renderImage(Image image) { + String url = image.getURL(); + ImageFactory fact = ImageFactory.getInstance(); + FopImage fopimage = fact.getImage(url, userAgent); + if(fopimage == null) { + return; + } + if(!fopimage.load(FopImage.DIMENSIONS, userAgent)) { + return; + } + String mime = fopimage.getMimeType(); + if("text/xml".equals(mime)) { + if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) { + return; + } + Document doc = ((XMLImage)fopimage).getDocument(); + String ns = ((XMLImage)fopimage).getNameSpace(); + + renderDocument(doc, ns); + + } else if("image/svg+xml".equals(mime)) { + if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) { + return; + } + Document doc = ((XMLImage)fopimage).getDocument(); + String ns = ((XMLImage)fopimage).getNameSpace(); + + renderDocument(doc, ns); + + } else if("image/eps".equals(mime)) { + if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) { + return; + } + int xobj = pdfDoc.addImage(fopimage); + fact.releaseImage(url, userAgent); + } else if("image/jpg".equals(mime)) { + if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) { + return; + } + int xobj = pdfDoc.addImage(fopimage); + fact.releaseImage(url, userAgent); + } else { + if(!fopimage.load(FopImage.BITMAP, userAgent)) { + return; + } + int xobj = pdfDoc.addImage(fopimage); + fact.releaseImage(url, userAgent); + + closeText(); + int w = fopimage.getWidth(); + int h = fopimage.getHeight(); + + currentStream.add("ET\nq\n" + ((float)w) + " 0 0 " + + ((float)-h) + " " + + (((float)currentBlockIPPosition) / 1000f) + " " + + (((float)(currentBPPosition - 1000 * h)) / 1000f) + " cm\n" + "/Im" + + xobj + " Do\nQ\nBT\n"); + } + + } + + public void renderForeignObject(ForeignObject fo) { + Document doc = fo.getDocument(); + String ns = fo.getNameSpace(); + renderDocument(doc, ns); + } + + public void renderDocument(Document doc, String ns) { + RendererContext context; + context = new RendererContext(mimeType); + context.setLogger(log); + + context.setProperty(PDFXMLHandler.PDF_DOCUMENT, pdfDoc); + context.setProperty(PDFXMLHandler.PDF_STREAM, currentStream); + context.setProperty(PDFXMLHandler.PDF_X, new Integer(currentBlockIPPosition)); + context.setProperty(PDFXMLHandler.PDF_Y, new Integer(currentBPPosition)); + FontState fs = null; + try { + fs = new FontState(fontInfo, "Helvetica", "", + "", 12 * 1000, 0); + } catch (org.apache.fop.apps.FOPException fope) { + fope.printStackTrace(); + } + + context.setProperty(PDFXMLHandler.PDF_FONT_STATE, fs); + context.setProperty(PDFXMLHandler.PDF_FONT_NAME, currentFontName); + context.setProperty(PDFXMLHandler.PDF_FONT_SIZE, new Integer(currentFontSize)); + context.setProperty(PDFXMLHandler.PDF_XPOS, new Integer(currentBlockIPPosition)); + context.setProperty(PDFXMLHandler.PDF_YPOS, new Integer(currentBPPosition)); + closeText(); + currentStream.add("ET\n"); + userAgent.renderXML(context, doc, ns); + currentStream.add("BT\n"); + + } + + public void renderViewport(Viewport viewport) { + /*if (clip && w != 0 && h != 0) { + currentStream.add(x / 1000f + " " + y / 1000f + " m\n"); + currentStream.add((x + w) / 1000f + " " + y / 1000f + " l\n"); + currentStream.add((x + w) / 1000f + " " + (y - h) / 1000f + + " l\n"); + currentStream.add(x / 1000f + " " + (y - h) / 1000f + " l\n"); + currentStream.add("h\n"); + currentStream.add("W\n"); + currentStream.add("n\n"); + }*/ + super.renderViewport(viewport); + } } diff --git a/src/org/apache/fop/render/pdf/PDFXMLHandler.java b/src/org/apache/fop/render/pdf/PDFXMLHandler.java new file mode 100644 index 000000000..6d983203c --- /dev/null +++ b/src/org/apache/fop/render/pdf/PDFXMLHandler.java @@ -0,0 +1,173 @@ +/* + * $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.pdf; + +import org.apache.fop.fo.FOUserAgent; +import org.apache.fop.render.XMLHandler; +import org.apache.fop.render.RendererContext; +import org.apache.fop.pdf.*; +import org.apache.fop.svg.*; +import org.apache.fop.layout.FontState; + +import org.apache.log.Logger; + +import org.apache.batik.dom.util.DOMUtilities; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Attr; + +import java.io.Writer; +import java.io.IOException; + +import org.apache.batik.bridge.*; +import org.apache.batik.swing.svg.*; +import org.apache.batik.swing.gvt.*; +import org.apache.batik.gvt.*; +import org.apache.batik.gvt.renderer.*; +import org.apache.batik.gvt.filter.*; +import org.apache.batik.gvt.event.*; + +import org.w3c.dom.*; +import org.w3c.dom.svg.*; +import org.w3c.dom.css.*; +import org.w3c.dom.svg.SVGLength; + +import java.awt.geom.AffineTransform; + +/** + */ +public class PDFXMLHandler implements XMLHandler { +public static final String PDF_DOCUMENT = "pdfDoc"; +public static final String PDF_STREAM = "pdfStream"; +public static final String PDF_X = "x"; +public static final String PDF_Y = "y"; +public static final String PDF_FONT_STATE = "fontState"; +public static final String PDF_FONT_NAME = "fontName"; +public static final String PDF_FONT_SIZE = "fontSize"; +public static final String PDF_XPOS = "xpos"; +public static final String PDF_YPOS = "ypos"; + + public PDFXMLHandler() { + } + + public void handleXML(RendererContext context, Document doc, + String ns) throws Exception { + PDFDocument pdfDoc = (PDFDocument) context.getProperty(PDF_DOCUMENT); + PDFInfo pdfi = new PDFInfo(); + pdfi.pdfDoc = (PDFDocument)context.getProperty(PDF_DOCUMENT); + pdfi.currentStream = (PDFStream)context.getProperty(PDF_STREAM); + pdfi.x = ((Integer)context.getProperty(PDF_X)).intValue(); + pdfi.y = ((Integer)context.getProperty(PDF_Y)).intValue(); + pdfi.fs = (FontState)context.getProperty(PDF_FONT_STATE); + pdfi.currentFontName = (String)context.getProperty(PDF_FONT_NAME); + pdfi.currentFontSize = ((Integer)context.getProperty(PDF_FONT_SIZE)).intValue(); + pdfi.currentXPosition = ((Integer)context.getProperty(PDF_XPOS)).intValue(); + pdfi.currentYPosition = ((Integer)context.getProperty(PDF_YPOS)).intValue(); + + String svg = "http://www.w3.org/2000/svg"; + if (svg.equals(ns)) { + SVGHandler svghandler = new SVGHandler(); + svghandler.renderSVGDocument(context, doc, pdfi); + } else { + } + } + + class PDFInfo { + PDFDocument pdfDoc; + PDFStream currentStream; + int x; + int y; + FontState fs; + String currentFontName; + int currentFontSize; + int currentXPosition; + int currentYPosition; + } + + protected class SVGHandler { + protected void renderSVGDocument(RendererContext context, Document doc, PDFInfo pdfInfo) { + float sx = 1, sy = 1; + int xOffset = pdfInfo.x, yOffset = pdfInfo.y; + + org.apache.fop.svg.SVGUserAgent ua + = new org.apache.fop.svg.SVGUserAgent(new AffineTransform()); + ua.setLogger(context.getLogger()); + + GVTBuilder builder = new GVTBuilder(); + BridgeContext ctx = new BridgeContext(ua); + TextPainter textPainter = null; + textPainter = new PDFTextPainter(pdfInfo.fs); + ctx.setTextPainter(textPainter); + + PDFAElementBridge aBridge = new PDFAElementBridge(); + aBridge.setCurrentTransform(new AffineTransform(sx, 0, 0, sy, xOffset / 1000f, yOffset / 1000f)); + ctx.putBridge(aBridge); + + GraphicsNode root; + try { + root = builder.build(ctx, doc); + } catch (Exception e) { + context.getLogger().error("svg graphic could not be built: " + + e.getMessage(), e); + return; + } + // get the 'width' and 'height' attributes of the SVG document + float w = (float)ctx.getDocumentSize().getWidth() * 1000f; + float h = (float)ctx.getDocumentSize().getHeight() * 1000f; + ctx = null; + builder = null; + + /* + * Clip to the svg area. + * Note: To have the svg overlay (under) a text area then use + * an fo:block-container + */ + pdfInfo.currentStream.add("q\n"); + // transform so that the coordinates (0,0) is from the top left + // and positive is down and to the right. (0,0) is where the + // viewBox puts it. + pdfInfo.currentStream.add(sx + " 0 0 " + sy + " " + xOffset / 1000f + " " + + yOffset / 1000f + " cm\n"); + + SVGSVGElement svg = ((SVGDocument)doc).getRootElement(); + AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg, w / 1000f, h / 1000f); + if(!at.isIdentity()) { + double[] vals = new double[6]; + at.getMatrix(vals); + pdfInfo.currentStream.add(PDFNumber.doubleOut(vals[0]) + " " + + PDFNumber.doubleOut(vals[1]) + " " + + PDFNumber.doubleOut(vals[2]) + " " + + PDFNumber.doubleOut(vals[3]) + " " + + PDFNumber.doubleOut(vals[4]) + " " + + PDFNumber.doubleOut(vals[5]) + " cm\n"); + } + + PDFGraphics2D graphics = new PDFGraphics2D(true, pdfInfo.fs, pdfInfo.pdfDoc, + pdfInfo.currentFontName, + pdfInfo.currentFontSize, + pdfInfo.currentXPosition, + pdfInfo.currentYPosition); + graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext()); + + try { + root.paint(graphics); + pdfInfo.currentStream.add(graphics.getString()); + } catch (Exception e) { + context.getLogger().error("svg graphic could not be rendered: " + + e.getMessage(), e); + } + + //currentAnnotList = graphics.getAnnotList(); + + pdfInfo.currentStream.add("Q\n"); + } + } +} + diff --git a/src/org/apache/fop/svg/PDFGraphics2D.java b/src/org/apache/fop/svg/PDFGraphics2D.java index 21e9598e2..2dd96ad34 100644 --- a/src/org/apache/fop/svg/PDFGraphics2D.java +++ b/src/org/apache/fop/svg/PDFGraphics2D.java @@ -104,6 +104,7 @@ public class PDFGraphics2D extends AbstractGraphics2D { currentYPosition = ypos; currentXPosition = xpos; fontState = fs; + graphicsState = new PDFState(); } protected PDFGraphics2D(boolean textAsShapes) { diff --git a/src/org/apache/fop/svg/SVGElementMapping.java b/src/org/apache/fop/svg/SVGElementMapping.java index c4e4a19c0..785f66080 100644 --- a/src/org/apache/fop/svg/SVGElementMapping.java +++ b/src/org/apache/fop/svg/SVGElementMapping.java @@ -16,10 +16,11 @@ import org.apache.fop.apps.Driver; import org.apache.batik.util.XMLResourceDescriptor; import org.apache.batik.dom.svg.SVGDOMImplementation; +import org.w3c.dom.DOMImplementation; public class SVGElementMapping implements ElementMapping { - private static HashMap foObjs = null; + private static boolean batik = true; private static synchronized void setupSVG() { if (foObjs == null) { @@ -36,12 +37,16 @@ public class SVGElementMapping implements ElementMapping { } public void addToBuilder(FOTreeBuilder builder) { - try { - setupSVG(); - String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; - builder.addMapping(svgNS, foObjs); - } catch (Throwable t) { - // if the classes are not available + if(batik) { + try { + setupSVG(); + String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; + builder.addMapping(svgNS, foObjs); + } catch (Throwable t) { + // if the classes are not available + // the DISPLAY is not checked + batik = false; + } } } |