You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by etem <ca...@yahoo.co.uk> on 2008/08/31 05:10:36 UTC

Wrapping a string or image in an

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.

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.

Can anyone point me in the right direction, or to some good examples?

Thanks,

-- 
View this message in context: http://www.nabble.com/Wrapping-a-string-or-image-in-an-%3Ca-href%3E-tp19234883p19234883.html
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: Wrapping a string or image in an

Posted by Tonny Kohar <to...@gmail.com>.
Hi,

On Sun, Aug 31, 2008 at 10:10 AM, etem <ca...@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