Hello,

     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.

 

     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).

 

After doing that, displaying the resultant XML doesn’t look correct.  Here is output from a line, a box, and an oval:

 

<?xml version="1.0" encoding="UTF-8"?>

 

<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>

<svg stroke-dasharray="none" shape-rendering="auto" xmlns="http://www.w3.org/2000/svg" font-family="&apos;sansserif&apos;" width="400" text-rendering="auto" fill-opacity="1" contentScriptType="text/ecmascript" color-rendering="auto" color-interpolation="auto" preserveAspectRatio="xMidYMid meet" font-size="12" fill="black" xmlns:xlink="http://www.w3.org/1999/xlink" stroke="black" image-rendering="auto" stroke-miterlimit="10" zoomAndPan="magnify" version="1.0" stroke-linecap="square" stroke-linejoin="miter" contentStyleType="text/css" font-style="normal" height="400" stroke-width="1" stroke-dashoffset="0" font-weight="normal" stroke-opacity="1">

  <!--Generated by the Batik Graphics2D SVG Generator-->

  <defs id="genericDefs" />

  <g>

    <g>

      <line y2="168" fill="none" x1="31" x2="91" y1="38" />

    </g>

  </g>

  <!--Generated by the Batik Graphics2D SVG Generator-->

  <defs id="genericDefs" />

  <g>

    <g>

      <rect fill="none" width="172" x="78" height="199" y="52" />

    </g>

  </g>

  <!--Generated by the Batik Graphics2D SVG Generator-->

  <defs id="genericDefs" />

  <g>

    <g>

      <ellipse rx="101" fill="none" ry="124.5" cx="261" cy="247.5" />

    </g>

  </g>

  <!--Generated by the Batik Graphics2D SVG Generator-->

  <defs id="genericDefs" />

  <g />

</svg>

 

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.

 

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?

 

Thanks for any help that can be provided.

 

Michael Bishop

 

 

Reply via email to