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 "Georg A." <at...@eva.mpg.de> on 2003/03/19 15:44:24 UTC

stream a SVGDocument

I have created a SVGDocument from an existing svg file and I added 
something to the
DOM Tree (using SVGGraphics2D),
-----
try {
       String parser = XMLResourceDescriptor.getXMLParserClassName();
       SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
       String uri = "file:" + new 
File("/0_Samples/world8.svg").getAbsolutePath();
       Document doc2 = f.createDocument(uri);
       g = new SVGGraphics2D(doc2);
       double left = 99;
       double top = 222;
       int width = 10;
       int height = 10;
       Shape circle = new Ellipse2D.Double(left,top,width,height);
       g.setPaint(Color.red);
       g.fill(circle);
       g.translate(10,0);//distance, ancle

       // The following populates the document root with the
       // generated SVG content.
       Element root = doc2.getDocumentElement();
       g.getRoot(root);

       doc = (SVGDocument)doc2;
       svgCanvas.setSVGDocument(doc);// invokes the rendering
       //this works splendid and is rendered just as I want it, the file 
plus the red dot
       streamsvg(g);
	  }
	 catch (Exception ex) {}
-----
now I want to stream out the SVGDocument.

When I do so using a FileWriter, the file just contains the parts I 
added with the SVGGraphics2D and not the
original DOM Tree from my svg file
----
public void streamsvg(SVGGraphics2D out){
       try
       {
         boolean useCSS = true;
         Writer raus = new OutputStreamWriter(System.out, "UTF-8");
         out.stream(raus, useCSS);
         Writer file = new FileWriter("bert.svg");
         out.stream(file, useCSS);
		System.out.println("geschrieben");

       }
         catch(Exception ex){}

     }
-----

thanks a lot for any suggestions!!!!

cheers

Georg
-- 



Georg Apitz

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WALS Project
Executive Programmer

Max Planck Institute for Evolutionary Anthropology
Inselstrasse 22
04103 Leipzig
Germany
Phone: +49 (0) 341 99 52 - 257
Telefax: +49 (0) 341 99 52 - 119

georg@apitz.de
www.eva.mpg.de
www.ge-org.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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


Re: stream a SVGDocument

Posted by Vincent Hardy <vi...@sun.com>.
Hello Georg,

After you used the getRoot method, the 'content' of the SVGGraphics2D 
has been moved over to your doc2's document element and is no longer 
contained in the SVGGraphics2D internal DOM structures.

What you could do is stream method on SVGGraphics2D that takes an 
Element parameter and pass your doc2's document element.

Vincent.

Georg A. wrote:
> I have created a SVGDocument from an existing svg file and I added 
> something to the
> DOM Tree (using SVGGraphics2D),
> -----
> try {
>       String parser = XMLResourceDescriptor.getXMLParserClassName();
>       SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
>       String uri = "file:" + new 
> File("/0_Samples/world8.svg").getAbsolutePath();
>       Document doc2 = f.createDocument(uri);
>       g = new SVGGraphics2D(doc2);
>       double left = 99;
>       double top = 222;
>       int width = 10;
>       int height = 10;
>       Shape circle = new Ellipse2D.Double(left,top,width,height);
>       g.setPaint(Color.red);
>       g.fill(circle);
>       g.translate(10,0);//distance, ancle
> 
>       // The following populates the document root with the
>       // generated SVG content.
>       Element root = doc2.getDocumentElement();
>       g.getRoot(root);
> 
>       doc = (SVGDocument)doc2;
>       svgCanvas.setSVGDocument(doc);// invokes the rendering
>       //this works splendid and is rendered just as I want it, the file 
> plus the red dot
>       streamsvg(g);
>       }
>      catch (Exception ex) {}
> -----
> now I want to stream out the SVGDocument.
> 
> When I do so using a FileWriter, the file just contains the parts I 
> added with the SVGGraphics2D and not the
> original DOM Tree from my svg file
> ----
> public void streamsvg(SVGGraphics2D out){
>       try
>       {
>         boolean useCSS = true;
>         Writer raus = new OutputStreamWriter(System.out, "UTF-8");
>         out.stream(raus, useCSS);
>         Writer file = new FileWriter("bert.svg");
>         out.stream(file, useCSS);
>         System.out.println("geschrieben");
> 
>       }
>         catch(Exception ex){}
> 
>     }
> -----
> 
> thanks a lot for any suggestions!!!!
> 
> cheers
> 
> Georg



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