xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ezra Jennings <ezra...@go.com>
Subject SVGGenerator id attribute, style attribute
Date Fri, 17 Aug 2001 21:18:08 GMT
Hello list,

I have two questions about the SVGGenerator.
Below is a copy of the test program from the xml.apache.org/batik web site followed by the
output of that prorgram when I run it to help illustrate my questions.

1. Is it possible to tell the SVGGenerator to not have the style of the rect be applied at
the g element that is the parent of the rect, but instead have the style be applied on the
rect itself?  (I realize I could do DOM manipulations myself to do this, but want to know
if the SVG generator can do that automatically.)

instead of what's below in the output, have:
      <rect x="10" y="10" width="100" height="100" style="fill:red; stroke:red;" />

(and maybe get rid of the <g> </g> tags then)

2. Is it possible to have the id attribute of the rect element set in the SVGGraphics2D object
before the SVG is generated so when the SVG is generated, the SVG output
has an id attribute in it?

      <rect x="10" y="10" width="100" height="100" id="MyRectangleNumber1"
style="fill:red; stroke:red;" />

If that is not possible, can anyone suggest a good way to add id attributes to elements (shapes)
in a systematic ordered fashion.  e.g. If I paint 50 rectangles in my paint method, can I
then attach id attributes to those 50
rectangles such that the first rectangle painted has the id attribute "MyRectangleNumber1"
and on to the 50th rectangle which will have the id attribute "MyRectangleNumber50"?

I'll confess that I'm a novice, so I apologize in advance if I'm asking a stupid question.

Ezra Jennings

import java.awt.Rectangle;
import java.awt.Graphics2D;
import java.awt.Color;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.IOException;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.dom.GenericDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;

public class TestSVGGen {

    public void paint(Graphics2D g2d) {
        g2d.fill(new Rectangle(10, 10, 100, 100));

    public static void main(String [] args) throws IOException {

        // Get a DOMImplementation
        DOMImplementation domImpl =

        // Create an instance of org.w3c.dom.Document
        Document document = domImpl.createDocument(null, "svg", null);

        // Create an instance of the SVG Generator
        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

        // Ask the test to render into the SVG Graphics2D implementation
        TestSVGGen test = new TestSVGGen();

        // Finally, stream out SVG to the standard output using UTF-8
        // character to byte encoding
        boolean useCSS = true; // we want to use CSS style attribute
        Writer out = new OutputStreamWriter(System.out, "UTF-8");
        svgGenerator.stream(out, useCSS);

<?xml version="1.0"?>

<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20001102//EN'
<svg style="fill-opacity:1; color-interpolation:sRGB; color-rendering:auto;
text-rendering:auto; stroke:black; stroke-linecap:square;
stroke-miterlimit:10; stroke-opacity:1; shape-rendering:auto; fill:black;
stroke-dasharray:none; font-weight:normal; stroke-width:1;
font-family:&apos;Arial&apos;; font-style:normal; stroke-linejoin:miter;
font-size:12; image-rendering:auto; stroke-dashoffset:0;" width="2147483647"
  <!--Generated by the Batik Graphics2D SVG Generator-->
  <defs id="genericDefs" />
    <g style="fill:red; stroke:red;">
      <rect x="10" y="10" width="100" style="stroke:none;" height="100" />

GO.com Mail                                    
Get Your Free, Private E-mail at http://mail.go.com

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

View raw message