xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From George Armhold <armh...@cs.rutgers.edu>
Subject SVGGraphics2D.getRoot() truncates SVG document?
Date Fri, 14 Sep 2001 21:21:02 GMT
I'm trying to manipulate the DOM generated by an SVGGraphics2D in order
to add some javascript.  I find that if I call SVGGraphics.getRoot(), it
wipes out any existing tags in the DOM.  The example below will
demonstrate this.  If you comment out the two lines starting with
g.getRoot(), it'll generate an SVG doc with some simple drawing code. 
When the getRoot() line is active, the drawing code gets truncated.    I
get this behaviour with Batik 1.0 as well as 1.1 RC2.  Am I supposed to
somehow add the node returned from getRoot() back into the DOM? If so,

Any explanations appreciated.

import javax.xml.parsers.*; 
import java.io.*;
import org.w3c.dom.*;
import java.awt.*;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.dom.svg.SVGDOMImplementation;

public class Simple {

  public static void main(String[] args) {
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    DOMImplementation impl =
    Document doc = impl.createDocument(svgNS, "svg", null);

    // Create an instance of the SVG Generator
    SVGGraphics2D g = new SVGGraphics2D(doc);

    // define the size of the SVG
    Dimension d = new Dimension(1024, 1024);

    // set background color
    g.fill(new Rectangle(0, 0, d.width, d.height));

    // now do our drawing
    Rectangle rect = new Rectangle(0, 0, 100, 100);
    Element scriptElement = doc.createElement("script");
    scriptElement.setAttribute("type", "text/ecmascript");

    // this call to getRoot() appears to corrupt the SVG document:
    Element svgRoot = g.getRoot();

    try {
      PrintWriter writer = new PrintWriter(System.out);
      g.stream(writer, false);
    } catch (Exception e) {


George Armhold
Rutgers University
Bioinformatics Initiative

To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org

View raw message