Hi Etem,
> I'm using the Batik SVG Generator to render some custom components
> to a .svg file. This is excellent and wonderful. However, I would
> like to put some < a href > links in the SVG file, and I absolutely
> cannot figure out how. Can anyone lend a hand?
Sure, but it's not real easy unfortunately.
> I'd like to wrap the (for a start, at least), the drawString in an <
> a href >, and specify where that link goes.
> I've searched batik-users, and I've tried all manner of incantations
> - usually variants of createElementNS, and getRoot - but either the
> resulting .svg is unchanged, or it's truncated to the header.
This is the right path, but what you are missing is that in order to
accomplish this goal you will need to assemble your DOM yourself
using the pieces produced by the SVGGraphics2D. The most
critical thing to realize is that 'getRoot()' clears the SVGGraphics2D
which is why you get 'truncated' SVG.
So the basic approach should be append what is returned
by getRoot() to your document (I would probably create a
subclass of SVGGraphics2D to carry this document) before
drawing the items you want to wrap in the svg:a element.
This will preserve that drawing in the document and let you
isolate the items to be wrapped. Then draw what you wanted
wrapped in the svg:a element. Call getRoot again and append
that to an svg:a element that you create (with createElementNS)
then append your svg:a element to the 'master' document.
Then when all of your drawing is complete call 'getRoot'
one last time and append that to your master document. Then
instead of using the 'stream' methods on the SVGGraphics2D
(which will give you nothing) use
batik.dom.util.DOMUtilities.writeDocument.