Hi all,

Sorry if this is a dumb question but I was under the impression that Batik
could let me convert a swing component into an svg document (that I could
later edit, resize et.) in a headless environment (server-side).

So I tried the following code:

   JFrame f = new JFrame("test");
    f.add(new JLabel("Some text"));
    f.setPreferredSize(new Dimension(500,500));
    f.pack();
    f.setVisible(true);

    DOMImplementation domImpl =
            GenericDOMImplementation.getDOMImplementation();
    final String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document document = domImpl.createDocument(svgNS, "svg", null);
    SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

    f.paint(svgGenerator);

    boolean useCSS = true;
    Writer out = new OutputStreamWriter(System.out, "UTF-8");
    svgGenerator.stream(out, useCSS);

But much to my chagrin 1) it generates a png image inside a <svg> tag, and
2) it doesn't work if I don't call the setVisible(true) method.

If when I call:
    svgGenerator.fill(new Rectangle(10, 10, 100, 100));
the library generates:
  <rect x="10" width="100" height="100" y="10" style="stroke:none;"/>
Instead of a png representing the rectangle. How come it does not do the
same thing with my JFrame?


Thanks,

-Toto.

Reply via email to