xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tonny Kohar" <tonny.ko...@gmail.com>
Subject Re: Wrapping a string or image in an <a href>
Date Tue, 09 Sep 2008 08:13:26 GMT
Hi,

On Sun, Aug 31, 2008 at 10:10 AM, etem <cavenier17@yahoo.co.uk> wrote:
>
> Hello!
>
> 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?
>
> Here's what I'm using up top :
>
>
> DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
> Document document = domImpl.createDocument(svgNS, "svg", null);
> SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
> GenericImageHandler ihandler = new CachedImageHandlerBase64Encoder();
> ctx.setGenericImageHandler(ihandler);
> SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
>
> v.paint(svgGenerator);
>
> boolean useCSS = true;
> Writer out = new OutputStreamWriter(new FileOutputStream("E:/grrarg.svg"),
> "UTF-8");
> svgGenerator.stream(out, useCSS);
>
>
> ... which is patched together from the examples on the Batik homepage.
>
> Here's my paint()...
>
> public void paintComponent(Graphics g)
> {
> ...
> Graphics2D g2d = (Graphics2D)g;
> SVGGraphics2D svg2d = null;
> if (g instanceof SVGGraphics2D) svg2d = (SVGGraphics2D)g;
>
> g2d.setBackground(Color.RED);
> g2d.clearRect(0,0, getWidth(), getHeight());
>
> g2d.drawString(blah, x, y);
> ...
> }
>
>
>
> I'd like to wrap the (for a start, at least), the drawString in an < a href
>>, and specify where that link goes.
>

Not sure about the SVGGraphics2D stuff, but once you get the access
the SVG DOM object, you can easily add <a href> element using the
standard DOM API call eg: createElement() or createElementNS()

Cheers
Tonny Kohar
-- 
Sketsa SVG Editor
imagine, design, create ...
http://www.kiyut.com

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


Mime
View raw message