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 Kai Grabfelder <Ka...@in-gmbh.de> on 2005/04/13 14:48:46 UTC

modify existing svg via SVGGraphics2D

hello there, 

i'm trying to load an existing svg file and add some drawings to it, using
the SVGGraphics2D class

normally i would instantiate a SVGGraphics2D class like this:

Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
//following some drawings on the svgGenerator object 

but i want to have an existing svg document as a template (i just want to
draw on top of it) and so i tried

String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
String uri = "test.svg";
Document document = f.createDocument(uri);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
//following some drawings on the svgGenerator object

but the resulting svg document does not consists of any elements present in
the test.svg input file. 

my question:

is it possible to draw on top of an existing svg file using SVGGraphics2D
and if not how is it possible then? Do i have to use JSVGCanvas? (since i
only need to create the svgs on the server side i thought this would not be
neccessary...)

thanks for your help in advance

Kai

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


Re: modify existing svg via SVGGraphics2D

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Kai,

Kai Grabfelder wrote:

> i'm trying to load an existing svg file and add some drawings to it, using
> the SVGGraphics2D class

> but i want to have an existing svg document as a template (i just want to
> draw on top of it) and so i tried
> 
> String parser = XMLResourceDescriptor.getXMLParserClassName();
> SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
> String uri = "test.svg";
> Document document = f.createDocument(uri);
> SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
> //following some drawings on the svgGenerator object
> 
> but the resulting svg document does not consists of any elements present in
> the test.svg input file. 

    This is what you want to do but the SVGGraphics2D only uses the
given Document as a factory it does not automatically append it's
output into the Document.  You would need to do this when the drawing is
done with something like:

     svgGenerator.getRoot(document.getDocumentElement());

> my question:
> 
> is it possible to draw on top of an existing svg file using SVGGraphics2D
> and if not how is it possible then? Do i have to use JSVGCanvas? (since i
> only need to create the svgs on the server side i thought this would not be
> neccessary...)

    No you don't need to use the JSVGCanvas.


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