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 André Rüdiger <an...@web.de> on 2006/11/10 12:54:25 UTC
DOM node from SVGGraphics2D
Hello List!
I want to export an org.w3c.dom.Node from a SVGGraphics2D object.
What I'm currently trying to do is:
DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
Document doc = domImpl.createDocument(svgNS, "svg", null);
ImageHandler imageHandler = new DefaultImageHandler();
ExtensionHandler extensionHandler = new DefaultExtensionHandler();
SVGGeneratorContext ctx = SVGGraphics2D.buildSVGGeneratorContext(doc,
imageHandler, extensionHandler);
SVGGraphics2D g = new SVGGraphics2D(ctx, false);
Dimension dim = [...];
g.setSVGCanvasSize(dim);
[paint something]
Element rootNode = doc.getDocumentElement();
g.getRoot(rootNode);
g.dispose();
return rootNode;
The problem with this is that getRoot() seems to overwrite doc's already set
namespace and I've to manually do a rootNode.setAttributeNS(null, "xmlns",
svgNS) to set the namespace correctly.
Now my question: Is there a more elegant solution to my problem? Am I
probably thinking too complicated here?
A further question would be if it's possible to generate SAX-events for a
SVGGraphics2D object. I'm currently converting the dom to sax events for
further transformations.
Thanks a lot!
André
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
AW: DOM node from SVGGraphics2D
Posted by André Rüdiger <an...@web.de>.
> Von: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
>
> andreruediger@web.de wrote on 11/10/2006 06:54:25 AM:
>
> >
> > Hello List!
> >
> > I want to export an org.w3c.dom.Node from a SVGGraphics2D object.
> >
> > What I'm currently trying to do is:
>
> [ code that looks ok deleted ]
>
> > Element rootNode = doc.getDocumentElement();
> > g.getRoot(rootNode);
>
> > return rootNode;
> >
> > The problem with this is that getRoot() seems to overwrite doc's
> > already
> set
> > namespace and I've to manually do a rootNode.setAttributeNS(null,
> "xmlns",
> > svgNS) to set the namespace correctly.
>
> I don't think I follow. AFAIK 'getRoot(rootNode)'
> appends the SVG content as children of the rootNode, it
> doesn't touch the attributes on 'rootNode'. Also I think it
> always set's the xmlns attribute on the node it appends.
You're right. It turned out that the testing code for storing the element
was incorrect.
>
> > Now my question: Is there a more elegant solution to my
> problem? Am I
> > probably thinking too complicated here?
>
> This depends a lot on what you are trying to do. The
> SVGGraphics2D is really designed to act as a sort of 'print
> to SVG' engine, not a 'simple' factory interface for SVG.
> If you are only interested in creating simple 'rect',
> 'circles' or 'lines', you may be better off just writing the
> code yourself, but if you have a big blob of existing Java
> drawing code and you just want to spit out a high quality SVG
> version of that drawing SVGGraphics2D is a great tool.
There's a lot of drawing going on and the resulting SVGs grow up to several
MBs so I'm stuck with SVGGraphics2D whicj is a great too indeed.
>
> > A further question would be if it's possible to generate SAX-events
> > for
> a
> > SVGGraphics2D object. I'm currently converting the dom to
> sax events
> > for further transformations.
>
> No the SVGGraphics2D (for a variety of good reasons) is
> fairly well tied to outputing DOM.
>
No Problem. I'm converting the DOM to SAX.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: DOM node from SVGGraphics2D
Posted by th...@kodak.com.
andreruediger@web.de wrote on 11/10/2006 06:54:25 AM:
>
> Hello List!
>
> I want to export an org.w3c.dom.Node from a SVGGraphics2D object.
>
> What I'm currently trying to do is:
[ code that looks ok deleted ]
> Element rootNode = doc.getDocumentElement();
> g.getRoot(rootNode);
> return rootNode;
>
> The problem with this is that getRoot() seems to overwrite doc's already
set
> namespace and I've to manually do a rootNode.setAttributeNS(null,
"xmlns",
> svgNS) to set the namespace correctly.
I don't think I follow. AFAIK 'getRoot(rootNode)' appends the SVG
content as children of the rootNode, it doesn't touch the attributes on
'rootNode'. Also I think it always set's the xmlns attribute on the node
it appends.
> Now my question: Is there a more elegant solution to my problem? Am I
> probably thinking too complicated here?
This depends a lot on what you are trying to do. The SVGGraphics2D
is really designed to act as a sort of 'print to SVG' engine, not a
'simple' factory interface for SVG.
If you are only interested in creating simple 'rect', 'circles' or
'lines', you may be better off just writing the code yourself, but if
you have a big blob of existing Java drawing code and you just want to
spit out a high quality SVG version of that drawing SVGGraphics2D is a
great tool.
> A further question would be if it's possible to generate SAX-events for
a
> SVGGraphics2D object. I'm currently converting the dom to sax events for
> further transformations.
No the SVGGraphics2D (for a variety of good reasons) is fairly well
tied to outputing DOM.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org