xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Keywan Najafi Tonekaboni <li...@prometoys.net>
Subject RE: Parsing SVG and grouping actions
Date Sat, 12 Apr 2008 13:25:49 GMT

first of all, thank you for the tips and help and the patience you help
here everybody. 

I deleted SVGGraphics2D from my code and try it now with DOM. I have the
famous problem, that the JSVGCanvas didn't update. I try with the help
of the documentation, a Batik book and the mailing list archive to solve
the problem, but couldn't find the source of it.

When I try to load a SVG from file, the Canvas load the SVG, but after
this no changes are draw:

String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
SVGDocument doc = (SVGDocument)

I do all the changes in a Runnable. This Runnable is atteched to the
update Manager.

UpdateManager um = jSVGCanvasBackground.getUpdateManager();
Runnable r = new CodilirePainter(model, pm, from_remote);

CodilirePainter is my own class, which implements Runnable.

When I try to create a new SVG with a PNG inside it even don't show me
this file. But I can add shapes etc with no problems. I only cant see
them in the canvas. But when I save the file and open it again, with my
program or any other (texteditor, inkscape), the document is like i want
it and with the added shapes.

File is my PNG, read from disk:

private void genSVG(File file) throws IOException {
	DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
	String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
	SVGDocument doc = (SVGDocument) impl.createDocument(svgNS, "svg", null);
	// encode the png to Base64 to embed it
	String pngBase64 = createPNGB64String(file);
	String width = Integer.toString(model.getSize().width);
	String height = Integer.toString(model.getSize().height);
	Element root = doc.getDocumentElement();
	root.setAttribute("width", width);
	root.setAttribute("height", height);
	root.setAttribute("viewBox", "0 0 " + width + " " + height);
	Element g = doc.createElement("g");
	g.setAttribute("id", "background");
	Element image = doc.createElement("image");
	image.setAttribute("id", "ScannedDocument");
	image.setAttribute("x", "0");
	image.setAttribute("y", "0");
	image.setAttribute("width", width);
	image.setAttribute("height", height);	


I don't run it in the UpdateManager, because at this state JSVGCanvas
don't has any Document associated and so no Update Manager is available.
This is correct, or?

Did I forgot something, that UpdateManager works? 

Another question is about Document.getElementById()
Can I use it with SVGDocument? When I do this, I got a

Element element = doc.getElementById(id);

When I want to remove a shape from the document, is it enough to grab
the element and then call "doc.removeChild(element);"? Or is it better
to use SAX?



Keywan Najafi Tonekaboni

people@world:/# apt-get --purge remove dominion
After unpacking world will be freed.
You are about to do something potentially beneficial
To continue type in the phrase 'Yes, do as We say!'

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

View raw message