1 17 18 19 20 package org.apache.fop.render.svg; 21 22 import org.apache.batik.dom.svg.SVGDOMImplementation; 23 import org.apache.batik.dom.util.DOMUtilities; 24 import org.apache.batik.dom.util.XMLSupport; 25 import org.apache.fop.render.Renderer; 26 import org.apache.fop.render.RendererContext; 27 import org.apache.fop.render.XMLHandler; 28 import org.w3c.dom.DOMImplementation ; 29 import org.w3c.dom.Element ; 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.svg.SVGDocument; 32 import org.w3c.dom.svg.SVGElement; 33 import org.w3c.dom.svg.SVGSVGElement; 34 35 public class SVGSVGHandler implements XMLHandler, SVGRendererContextConstants { 36 37 38 public void handleXML(RendererContext context, 39 org.w3c.dom.Document doc, String ns) throws Exception { 40 if (getNamespace().equals(ns)) { 41 if (!(doc instanceof SVGDocument)) { 42 DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); 43 doc = DOMUtilities.deepCloneDocument(doc, impl); 44 } 45 SVGSVGElement svg = ((SVGDocument) doc).getRootElement(); 46 SVGDocument targetDoc = (SVGDocument)context.getProperty(SVG_DOCUMENT); 47 SVGElement currentPageG = (SVGElement)context.getProperty(SVG_PAGE_G); 48 Element view = targetDoc.createElementNS(getNamespace(), "svg"); 49 Node newsvg = targetDoc.importNode(svg, true); 50 int xpos = ((Integer )context.getProperty(XPOS)).intValue(); 52 int ypos = ((Integer )context.getProperty(YPOS)).intValue(); 53 view.setAttributeNS(null, "x", "" + xpos / 1000f); 54 view.setAttributeNS(null, "y", "" + ypos / 1000f); 55 56 Element ele = (Element ) newsvg; 58 ele.setAttributeNS(XMLSupport.XMLNS_NAMESPACE_URI, "xmlns", 59 getNamespace()); 60 if (ele.hasAttributeNS(null, "xmlns")) { 61 ele.removeAttributeNS(null, "xmlns"); 62 } 63 64 view.appendChild(newsvg); 65 currentPageG.appendChild(view); 66 } 67 } 68 69 70 71 public boolean supportsRenderer(Renderer renderer) { 72 return (renderer instanceof SVGRenderer); 73 } 74 75 76 public String getNamespace() { 77 return SVGRenderer.SVG_NAMESPACE; 78 } 79 80 81 } 82 | Popular Tags |