Friday, February 2, 2007

Apache Batik

I'm currently using Apache Batik to draw an svg in the browser window. Part of what I need to do is create a pattern for an area using a third party svg. I was having problems creating the image tag in batik. Apparently for images you need to explicitly set the namespace for the attribute like this:

Element image = document.createElementNS("http://www.w3.org/2000/svg","image");
image.setAttributeNS(null,"width",imageWidth);
image.setAttributeNS(null,"height",imageWidth);
image.setAttributeNS("http://www.w3.org/1999/xlink","href","name.svg");
parentGroup.appendChild(image); //parentGroup needs to be an existing
node reference to a group where the images should be appended

Cool. Works now, just wish I could find a site with some good advanced batik tutorials. Like where do I find info that tells me images need the namespace explicitly set. The batik site has a few tutorials, but are basically getting started tutorials. BTW, the Apache Batik site has been re-designed. I definitely like it better than the old design.

No comments: