keiron 02/03/08 03:00:20 Modified: src/org/apache/fop/fo/flow ExternalGraphic.java src/org/apache/fop/image AbstractFopImage.java FopImage.java ImageFactory.java src/org/apache/fop/image/analyser ImageReaderFactory.java SVGReader.java src/org/apache/fop/render/pdf PDFRenderer.java src/org/apache/fop/svg PDFGraphics2D.java SVGElementMapping.java Added: src/org/apache/fop/image XMLImage.java src/org/apache/fop/image/analyser XMLReader.java src/org/apache/fop/render/pdf PDFXMLHandler.java Removed: src/org/apache/fop/image SVGImage.java Log: renders images and ifo to pdf doc added xml reader for external graphics Revision Changes Path 1.19 +6 -4 xml-fop/src/org/apache/fop/fo/flow/ExternalGraphic.java Index: ExternalGraphic.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/flow/ExternalGraphic.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- ExternalGraphic.java 26 Feb 2002 12:43:09 -0000 1.18 +++ ExternalGraphic.java 8 Mar 2002 11:00:17 -0000 1.19 @@ -1,5 +1,5 @@ /* - * $Id: ExternalGraphic.java,v 1.18 2002/02/26 12:43:09 keiron Exp $ + * $Id: ExternalGraphic.java,v 1.19 2002/03/08 11:00:17 keiron Exp $ * 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. @@ -48,12 +48,14 @@ } 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 @@ return vp; } - public void setup() throws FOPException { + public void setup() { // Common Accessibility Properties AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); @@ -102,7 +104,7 @@ // 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"); } 1.8 +4 -4 xml-fop/src/org/apache/fop/image/AbstractFopImage.java Index: AbstractFopImage.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/AbstractFopImage.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- AbstractFopImage.java 25 Feb 2002 09:31:03 -0000 1.7 +++ AbstractFopImage.java 8 Mar 2002 11:00:18 -0000 1.8 @@ -1,5 +1,5 @@ /* - * $Id: AbstractFopImage.java,v 1.7 2002/02/25 09:31:03 keiron Exp $ + * $Id: AbstractFopImage.java,v 1.8 2002/03/08 11:00:18 keiron Exp $ * 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. @@ -100,7 +100,7 @@ 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 @@ 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; 1.11 +2 -1 xml-fop/src/org/apache/fop/image/FopImage.java Index: FopImage.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/FopImage.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- FopImage.java 25 Feb 2002 09:31:03 -0000 1.10 +++ FopImage.java 8 Mar 2002 11:00:18 -0000 1.11 @@ -1,5 +1,5 @@ /* - * $Id: FopImage.java,v 1.10 2002/02/25 09:31:03 keiron Exp $ + * $Id: FopImage.java,v 1.11 2002/03/08 11:00:18 keiron Exp $ * 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. @@ -70,6 +70,7 @@ public int height; public Object data; public String mimeType; + public String str; } } 1.4 +4 -2 xml-fop/src/org/apache/fop/image/ImageFactory.java Index: ImageFactory.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/ImageFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ImageFactory.java 25 Feb 2002 09:31:03 -0000 1.3 +++ ImageFactory.java 8 Mar 2002 11:00:18 -0000 1.4 @@ -1,5 +1,5 @@ /* - * $Id: ImageFactory.java,v 1.3 2002/02/25 09:31:03 keiron Exp $ + * $Id: ImageFactory.java,v 1.4 2002/03/08 11:00:18 keiron Exp $ * 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. @@ -186,7 +186,9 @@ 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 (" + 1.1 xml-fop/src/org/apache/fop/image/XMLImage.java Index: XMLImage.java =================================================================== /* * $Id: XMLImage.java,v 1.1 2002/03/08 11:00:19 keiron Exp $ * 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; // Java import java.net.URL; import org.w3c.dom.Document; // FOP import org.apache.fop.apps.Driver; import org.apache.fop.image.analyser.ImageReader; import org.apache.fop.image.analyser.SVGReader; import org.apache.fop.fo.FOUserAgent; /** * @see AbstractFopImage * @see FopImage */ public class XMLImage extends AbstractFopImage { Document doc; String ns = ""; public XMLImage(URL href, FopImage.ImageInfo imgInfo) { super(href, imgInfo); if(imgInfo.data instanceof Document) { doc = (Document)imgInfo.data; } ns = imgInfo.str; } /** * creates a SAX parser, using the value of org.xml.sax.parser * defaulting to org.apache.xerces.parsers.SAXParser * * @return the created SAX parser */ public static String getParserName() { String parserClassName = Driver.getParserClassName(); return parserClassName; } protected boolean loadData(FOUserAgent ua) { return true; } public Document getDocument() { return doc; } public String getNameSpace() { return ns; } } 1.10 +4 -1 xml-fop/src/org/apache/fop/image/analyser/ImageReaderFactory.java Index: ImageReaderFactory.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/ImageReaderFactory.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ImageReaderFactory.java 25 Feb 2002 09:31:03 -0000 1.9 +++ ImageReaderFactory.java 8 Mar 2002 11:00:19 -0000 1.10 @@ -1,5 +1,5 @@ /* - * $Id: ImageReaderFactory.java,v 1.9 2002/02/25 09:31:03 keiron Exp $ + * $Id: ImageReaderFactory.java,v 1.10 2002/03/08 11:00:19 keiron Exp $ * 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. @@ -30,7 +30,10 @@ 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 1.21 +61 -6 xml-fop/src/org/apache/fop/image/analyser/SVGReader.java Index: SVGReader.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/SVGReader.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- SVGReader.java 25 Feb 2002 09:31:03 -0000 1.20 +++ SVGReader.java 8 Mar 2002 11:00:19 -0000 1.21 @@ -1,5 +1,5 @@ /* - * $Id: SVGReader.java,v 1.20 2002/02/25 09:31:03 keiron Exp $ + * $Id: SVGReader.java,v 1.21 2002/03/08 11:00:19 keiron Exp $ * 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. @@ -15,7 +15,7 @@ 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.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 @@ * 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 @@ return info; } catch (NoClassDefFoundError ncdfe) { + try { + fis.reset(); + } catch (IOException ioe) { } batik = false; //ua.getLogger().error("Batik not in class path", ncdfe); return null; 1.1 xml-fop/src/org/apache/fop/image/analyser/XMLReader.java Index: XMLReader.java =================================================================== /* * $Id: XMLReader.java,v 1.1 2002/03/08 11:00:19 keiron Exp $ * 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); } } 1.99 +126 -5 xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java Index: PDFRenderer.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v retrieving revision 1.98 retrieving revision 1.99 diff -u -r1.98 -r1.99 --- PDFRenderer.java 26 Feb 2002 12:43:09 -0000 1.98 +++ PDFRenderer.java 8 Mar 2002 11:00:20 -0000 1.99 @@ -1,5 +1,5 @@ /* - * $Id: PDFRenderer.java,v 1.98 2002/02/26 12:43:09 keiron Exp $ + * $Id: PDFRenderer.java,v 1.99 2002/03/08 11:00:20 keiron Exp $ * 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. @@ -9,7 +9,10 @@ // 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 @@ * */ public class PDFRenderer extends PrintRenderer { + public static final String mimeType = "application/pdf"; /** * the PDF Document being created @@ -142,6 +146,14 @@ 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 @@ // 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(); @@ -447,6 +458,116 @@ this.currentFontSize = size; 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); } } 1.1 xml-fop/src/org/apache/fop/render/pdf/PDFXMLHandler.java Index: PDFXMLHandler.java =================================================================== /* * $Id: PDFXMLHandler.java,v 1.1 2002/03/08 11:00:20 keiron Exp $ * 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"); } } } 1.25 +3 -2 xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java Index: PDFGraphics2D.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/PDFGraphics2D.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- PDFGraphics2D.java 21 Feb 2002 09:54:28 -0000 1.24 +++ PDFGraphics2D.java 8 Mar 2002 11:00:20 -0000 1.25 @@ -1,5 +1,5 @@ /* - * $Id: PDFGraphics2D.java,v 1.24 2002/02/21 09:54:28 keiron Exp $ + * $Id: PDFGraphics2D.java,v 1.25 2002/03/08 11:00:20 keiron Exp $ * 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. @@ -41,7 +41,7 @@ * This takes a pdf document and draws into it. * * @author <a href="mailto:[EMAIL PROTECTED]">Keiron Liddle</a> - * @version $Id: PDFGraphics2D.java,v 1.24 2002/02/21 09:54:28 keiron Exp $ + * @version $Id: PDFGraphics2D.java,v 1.25 2002/03/08 11:00:20 keiron Exp $ * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D */ public class PDFGraphics2D extends AbstractGraphics2D { @@ -104,6 +104,7 @@ currentYPosition = ypos; currentXPosition = xpos; fontState = fs; + graphicsState = new PDFState(); } protected PDFGraphics2D(boolean textAsShapes) { 1.22 +13 -8 xml-fop/src/org/apache/fop/svg/SVGElementMapping.java Index: SVGElementMapping.java =================================================================== RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/SVGElementMapping.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- SVGElementMapping.java 13 Dec 2001 09:40:04 -0000 1.21 +++ SVGElementMapping.java 8 Mar 2002 11:00:20 -0000 1.22 @@ -1,5 +1,5 @@ /* - * $Id: SVGElementMapping.java,v 1.21 2001/12/13 09:40:04 keiron Exp $ + * $Id: SVGElementMapping.java,v 1.22 2002/03/08 11:00:20 keiron Exp $ * 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. @@ -16,10 +16,11 @@ 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 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; + } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]