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 Dominik Lindner <ba...@dominik-lindner.de> on 2006/05/15 15:05:33 UTC

SVGGraphics2D resetting and streaming

Hi,

I have few problems with SVGGraphics2D.
I want to create a SVG document, draw in it's graphics context, stream it out, 
reset the graphic content, redraw, and so on.

Example:

DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
Document document = domImpl.createDocument(null, "svg", null);
SVGGraphics2D g = new SVGGraphics2D(document);
// draw graphics in g
// ...
FileWriter out = new FileWriter("/home/dominik/test.svg");
g.stream(out, false);
//...
g.dispose() //delete graphics content
// redraw graphics in g
//...
out = new FileWriter("/home/dominik/test2.svg");
g.stream(out, false);

There seem's to be a known bug in batik, so that streaming out results in a 
corrupted document. So I tried the work-around:
Element e = document.getDocumentElement();
g.getRoot(e);
g.stream(root, out, false);
But this has the consequence that I cannot reset SVGGraphics2D, I can't delete 
the graphics content. SVGGraphics2D.dispose() seems to have no effect.
How can I delete the graphics content of SVGGraphics2D? Is there a way for 
doing this task?

Hope you can help me!

Thanks,
Dominik


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


Re: SVGGraphics2D resetting and streaming

Posted by Dominik Lindner <ba...@dominik-lindner.de>.
Am Dienstag, 16. Mai 2006 04:16 schrieb Cameron McCormack:
> > There seem's to be a known bug in batik, so that streaming out results in
> > a corrupted document. So I tried the work-around:
>
> What do you mean that it results in a corrupted document?

I mean http://issues.apache.org/bugzilla/show_bug.cgi?id=35202
Calling stream() has the effect that the document's content gets lost. But 
maybe that's a feature than a bug.

> The javadoc for the dispose method says:
>
>   A Graphics object cannot be used after dispose has been called.

Ah, thanks, I didn't read that.

> Otherwise, is there any reason you don't want to create a new
> SVGGraphics2D object?  There's maybe a slight overhead, but I don't
> think it's too great.

The overhead is too great, it takes between 1000-2000ms to create the 
SVGGraphics2D object.
But you are right, my problem was the dispose() call. Without dispose() it 
works, because of stream() also resets the documents content but without 
'corrupting' it as I thought.

So problem solved. Thank's for your hints!

Regards,
Dominik Lindner


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


Re: SVGGraphics2D resetting and streaming

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Dominik.

Dominik Lindner:
> I have few problems with SVGGraphics2D.
> I want to create a SVG document, draw in it's graphics context, stream it out, 
> reset the graphic content, redraw, and so on.
> 
> Example:
> 
> DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
> Document document = domImpl.createDocument(null, "svg", null);
> SVGGraphics2D g = new SVGGraphics2D(document);
> // draw graphics in g
> // ...
> FileWriter out = new FileWriter("/home/dominik/test.svg");
> g.stream(out, false);
> //...
> g.dispose() //delete graphics content
> // redraw graphics in g
> //...
> out = new FileWriter("/home/dominik/test2.svg");
> g.stream(out, false);
> 
> There seem's to be a known bug in batik, so that streaming out results in a 
> corrupted document. So I tried the work-around:

What do you mean that it results in a corrupted document?

> Element e = document.getDocumentElement();
> g.getRoot(e);
> g.stream(root, out, false);
> But this has the consequence that I cannot reset SVGGraphics2D, I can't delete 
> the graphics content. SVGGraphics2D.dispose() seems to have no effect.
> How can I delete the graphics content of SVGGraphics2D? Is there a way for 
> doing this task?

The javadoc for the dispose method says:

  A Graphics object cannot be used after dispose has been called.

so presumably can't use that to do what you want.

But the getTopLevelGroup method, which returns the 'g' element into
which the SVG elements so far have been stored, claims that it will
"also cause this object to start working with a new topLevelGroup", so
perhaps this will do what you want.

Otherwise, is there any reason you don't want to create a new
SVGGraphics2D object?  There's maybe a slight overhead, but I don't
think it's too great.

Cameron

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

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