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
Hi,

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)
	factory.createDocument(file.toURI().toString());
jSVGCanvasBackground.setSVGDocument(doc);

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);
um.getUpdateRunnableQueue().invokeLater(r);

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);	
	image.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");
	image.setAttribute("xlink:href",pngBase64);
	image.setAttribute("xlink:show","embed");
	image.setAttribute("xlink:type","simple");
	image.setAttribute("xlink:actuate","onLoad");

	g.appendChild(image);
	root.appendChild(g);
	
	jSVGCanvasBackground.setSVGDocument(doc);
}

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
NullPointerException:

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?


Regards,

Keywan


-- 
Keywan Najafi Tonekaboni
http://www.prometoys.net

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


Mime
View raw message