jfree / jfreesvg

A fast, lightweight Java library for creating Scalable Vector Graphics (SVG) output.

Home Page:http://www.jfree.org/jfreesvg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

draw a element can set a id or class?

touchmii opened this issue · comments

like this, can help web identify element name.

This would be better in Discussions.

Anyway, setting the id for an element is supported. Since JFreeSVG targets the Graphics2D API, it makes use of the rendering hints facility (slightly non-obvious, but it has the advantage that your code will still run against other Graphics2D implementations - the hints get ignored, but otherwise the rendering is the same). You can do something like this:

Graphics2D g2 = ... (from wherever you create your Graphics2D instance)
g2.setRenderingHint(SVGHints.KEY_ELEMENT_ID, "XYZ");
g2.fill(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));

...and then the rectangle in the SVG output will be tagged with the specified element ID.