xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From George Armhold <armh...@taproot.rutgers.edu>
Subject trouble setting attributes with SVGGraphics2D
Date Thu, 16 Aug 2001 15:11:03 GMT
Hello,

I'm having trouble setting width and height attributes while using
SVGGraphics2D.  It seems that the default width and height get set to
"2147483647" when using SVGGraphics2D.  When I try to set these
attributes by manipulating the DOM I get strange results.  In the
following code, I attempt to set the attributes by hand.  However when
run (with Batik 1.0, JDK 1.3.0, RedHat Linux 7.1) my changes never
appear in the resulting XML output.



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

public class SVGTest {

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

    // get the root element (the svg element)
    Element svgRoot = doc.getDocumentElement();

    // set the width and height attribute on the root svg element
    svgRoot.setAttributeNS(svgNS, "width", "1024");
    svgRoot.setAttributeNS(svgNS, "height", "768");


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

    // set background to white
    g.setColor(Color.white);
    g.fill(new Rectangle(0, 0, 1024, 768));
    g.setColor(Color.red);
    g.fill(new Rectangle(100, 100, 100, 100));

    try {
      FileWriter writer = new FileWriter(new File("svgtest.xml"));
      g.stream(writer, false);
      writer.flush();
      writer.close();
    } catch (IOException e) {
      System.err.println(e.getMessage());
      System.exit(1);
    }

    System.exit(0);
  }

}


Also, I notice that I need to explicitly call System.exit(), else my
main never exits... are there lingering threads in the batik code?

Thanks for your help.

PS: I'd like to say thanks to all the Batik developers; this is a
great package!  I've been meaning to send a "thank you" email to you
guys ever since the JavaOne talk back in June.  Great job!



--
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


Mime
View raw message