|
SvgSupport
Rough Paper: History, Requirements, Concepts, Obstacles
Phase-Requirements This idea came up on the piccolo2d-dev maillist. TODO: insert the options Michael mentioned and the example from the comment below. And have a look at http://wiki.svg.org/JSR_226 and http://wiki.svg.org/JSR_287 MotivationPiccolo2d is a scenegraph ZUI toolkit, svg is a 2d vector graphics description language. Both share the idea of a scene graph and the grouping and transformation concepts also look similar at a first glance. Is it possible to use svg documents e.g. generated by inkscape as input and convert them to piccolo2d scenegraphs? HistoryThere was some idea to build svg support into jazz. The v1.1 API has some svg classes. Requirements
Concepts
StepsAim for for SVG 1.1 Tiny and use the examples from the specification as test input. Development happens in the svg2009 branch. As I develop this in a local git repo and merge to svn, a finer-grained commit history can be obtained from the git://github.com/mro/piccolo2d.java.git repository.
Obstacles
Links |
Here is a simple example how Batik can be used to display SVGs with Piccolo:
import java.awt.Graphics2D; import java.io.IOException; import java.io.FileInputStream; import org.apache.batik.bridge.BridgeContext; import org.apache.batik.bridge.DocumentLoader; import org.apache.batik.bridge.GVTBuilder; import org.apache.batik.bridge.UserAgentAdapter; import org.apache.batik.dom.svg.SAXSVGDocumentFactory; import org.apache.batik.util.XMLResourceDescriptor; import org.w3c.dom.svg.SVGDocument; import org.apache.batik.gvt.GraphicsNode; import edu.umd.cs.piccolo.PNode; import edu.umd.cs.piccolo.util.PPaintContext; public class SVGNode extends PNode { private GraphicsNode svg; public SVGNode(String path) throws IOException { FileInputStream is = new FileInputStream(path); SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(XMLResourceDescriptor.getXMLParserClassName()); SVGDocument doc = (SVGDocument)f.createDocument(null, is); UserAgentAdapter ua = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(ua); BridgeContext bridge = new BridgeContext(ua,loader); GVTBuilder builder = new GVTBuilder(); svg = builder.build(bridge,doc); setBounds(svg.getBounds()); } protected void paint(PPaintContext paintContext) { Graphics2D g2 = paintContext.getGraphics(); svg.paint(g2); } }I have experiment batik solution to include SVG in piccolo, like the code above. But it's not usable because it's very very slow. I think SVG Tiny is a good way to include SVG.
I thing much better would be SVG Salamander. It can only read, not writte SVG. Jar file is 256 kb. Simple integration can be done with SVGIcon, all stuff you discusses can be done via SVG Universe.
I made implementation for SVG Salamander. http://kotek.net/blog/piccolo_and_svg
Please check the link to http://www.elementengine.com/ and remove it, as appropriate. When I clicked it on 4/16/11, it was all in some Asian script and had an inappropriate photo. Thanks.