1 18 package org.apache.batik.svggen; 19 20 import java.awt.Color ; 21 import java.awt.Dimension ; 22 import java.awt.Shape ; 23 import java.awt.geom.Ellipse2D ; 24 25 import org.w3c.dom.DOMImplementation ; 26 import org.w3c.dom.Element ; 27 import org.w3c.dom.svg.SVGDocument; 28 29 import org.apache.batik.bridge.BaseScriptingEnvironment; 30 import org.apache.batik.bridge.BridgeContext; 31 import org.apache.batik.bridge.GVTBuilder; 32 import org.apache.batik.bridge.UserAgentAdapter; 33 import org.apache.batik.dom.svg.SVGDOMImplementation; 34 import org.apache.batik.test.AbstractTest; 35 import org.apache.batik.test.TestReport; 36 37 44 public class ShowGraphics2DOutput extends AbstractTest { 45 public TestReport runImpl() throws Exception { 46 47 DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); 48 String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; 49 SVGDocument doc = (SVGDocument)impl.createDocument(svgNS, "svg", null); 50 51 SVGGraphics2D g = new SVGGraphics2D(doc); 52 53 Shape circle = new Ellipse2D.Double (0,0,50,50); 54 g.setPaint(Color.red); 55 g.fill(circle); 56 g.translate(60,0); 57 g.setPaint(Color.green); 58 g.fill(circle); 59 g.translate(60,0); 60 g.setPaint(Color.blue); 61 g.fill(circle); 62 g.setSVGCanvasSize(new Dimension (180,50)); 63 64 Element root = doc.getDocumentElement(); 65 66 g.getRoot(root); 69 70 root.setAttribute("onload", "System.out.println('hello')"); 71 72 TestUserAgent userAgent = new TestUserAgent(); 75 GVTBuilder builder = new GVTBuilder(); 76 BridgeContext ctx = new BridgeContext(userAgent); 77 ctx.setDynamic(true); 78 79 builder.build(ctx, doc); 80 BaseScriptingEnvironment scriptEnvironment 81 = new BaseScriptingEnvironment(ctx); 82 scriptEnvironment.loadScripts(); 83 scriptEnvironment.dispatchSVGLoadEvent(); 84 85 if (!userAgent.failed) { 86 return reportSuccess(); 87 } else { 88 return reportError("Got exception while processing document"); 89 } 90 } 91 92 class TestUserAgent extends UserAgentAdapter { 93 boolean failed; 94 95 public void displayError(Exception e) { 96 failed = true; 97 } 98 } 99 } 100 | Popular Tags |