xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas DeWeese <Thomas.DeWe...@Kodak.com>
Subject Re: Basic SVG management in Batik with white-boarding.
Date Fri, 09 Sep 2005 10:38:08 GMT
Hi Michael,

Bishop, Michael W. CONTR J9C880 wrote:

>      I’m trying to develop a simple white-boarding style program with 
> Batik and have run into a couple fundamental problems.  Here is a brief 
> outline of the steps used:
> -           User draws a shape or line on the application’s glass pane.
> -           X and Y coordinates are saved and then drawn to an 
> SVGDocument via SVGGraphics2D object.
> -           SVGCanvas “sets” the SVGDocument and the resulting changes 
> are shown on the screen.

    You should probably just append the new SVG object to the current
document.  If you tell Batik to treat the document as ALWAYS_DYNAMIC
and do the append in the UpdateManager's RunnableQueue (just search
the list for these things for examples) Batik will much more efficiently
update the display.

>      Now this works fine until I try to “save” the results to an SVG 
> file.  The interaction with the document doesn’t work as expected for me.
> I have to do the following to get anything to render on the screen:
> Element root = svgDocument.getDocumentElement();
> svgGraphics2D.getRoot(root);
> Only when I make these calls, will anything show when I call 
> svgCanvas.setDocument(svgDocument).

    Yes, it's important to know that the SVGGraphics2D only
uses the document you give it as a 'factory' for elements.
It does not insert it's elements into the document.

> After doing that, displaying the resultant XML doesn’t look correct.  
> Here is output from a line, a box, and an oval:
>   <!--Generated by the Batik Graphics2D SVG Generator-->
>   <!--Generated by the Batik Graphics2D SVG Generator-->
>   <!--Generated by the Batik Graphics2D SVG Generator-->
>   <!--Generated by the Batik Graphics2D SVG Generator-->

> Again, I have to make the call to SVGGraphics2D.getRoot(…) to display 
> anything at all.  I don’t understand why I have separate definitions and 
> doubly-nested <g> elements for each shape.  It also looks like the SVG 
> generator is generating a different document fragment for every paint 
> operation which may be what it’s supposed to do.

    This is exactly what it does.  The real purpose of the SVGGraphics2D
is to turn 'complex' drawing operations into SVG.  For simple primitives
you can do a much better job of creating the elements and making a
'pretty' document.

> A related question is, how can I identify each object I draw?  I’ve seen 
> in the SVG specs, an “id” can be given to a <g> element.  In a later 
> iteration, I may want to identify and “move” or “delete” a shape I’ve 
> already drawn.  Does the Batik toolkit allow me to give an ID to a draw 
> operation and manipulate it later, or will I have to dig through the XML 
> document myself to gain that functionality?

     Well you can call getRoot without an SVG Element in which case
it will construct an SVG Element for you which you can add your
'id' to - which isn't much mucking with the document.

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

View raw message