Hi Michael,

 

I do a similar drawing application and I’m creating my elements using the SVGGraphics2D (to what you already posted a message)

 

Basically I’m creating a path-element out of my Java2D GeneralPath… and it works fine… here’s the code

 

    Element polygonLayer = canvas.getElementById(LayerManager.POLYGON_LAYER);

    Shape shape = (Shape) object;

    //  Transform the shape from screen to viewbox coordinates

    try {

      AffineTransform at = canvas.getViewBoxTransform().createInverse();

      shape = at.createTransformedShape(shape);

    } catch (NoninvertibleTransformException e1) {

      e1.printStackTrace();

    }

 

    // create the path element

    SVGGraphics2D svgGenerator = new SVGGraphics2D(canvas.getSVGDocument());

    svgGenerator.setSVGCanvasSize((Dimension) canvas.getSVGDocumentSize());

    Element svgShape = svgGenerator.getShapeConverter().toSVG(shape);

 

    // set the elements attributes

    svgShape.setAttributeNS(null, SVGConstants.SVG_ID_ATTRIBUTE, id);

    svgShape.setAttributeNS(null, SVGConstants.SVG_FILL_ATTRIBUTE,

        SVGConstants.SVG_NONE_VALUE);

    svgShape.setAttributeNS(null, SVGConstants.SVG_STROKE_ATTRIBUTE, "blue");

    svgShape.setAttributeNS(null, SVGConstants.CSS_CURSOR_PROPERTY,

        SVGConstants.CSS_CROSSHAIR_VALUE);

    svgShape.setAttributeNS(null, SVGConstants.SVG_STROKE_WIDTH_ATTRIBUTE, "5");

    polygonLayer.appendChild(svgShape);

 

I hope this helps….

 

Dominik

 


Von: Bishop, Michael W. CONTR J9C880 [mailto:[EMAIL PROTECTED]
Gesendet: Mittwoch, 21. September 2005 22:24
An: [email protected]
Betreff: Possible bug with JSVGCanvas and certain Elements?

 

I’m implementing a “free-form” line where the user can draw by pressing and holding the mouse.  This is for a whiteboard application.  I sample the mouse locations, get a collection of Points, and then create a “polyline” element from the results and append it to the document (in the RunnableQueue) which should update my JSVGCanvas (set to ALWAYS_DYNAMIC).  This will not update the screen!  I can draw other shapes using the SVGShape class (Ellipse, Rectangle, Line) and they all work fine.  Even drawing after the polyline does not cause the polyline to be rendered.  However, if I save the SVGDocument to a file, then load it, the polyline shows up??

 

In essence, appending a polyline Element to a document does not seem to update the JSVGCanvas while other Element types seem to work.  Any suggestions?

 

SVG Before (Empty Canvas):

<svg contentScriptType="text/ecmascript" fill="none" width="480" xmlns:xlink="http://www.w3.org/1999/xlink" zoomAndPan="magnify" contentStyleType="text/css" height="272" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" version="1.0"></svg>

 

SVG After (Polyline drawn, no updates):

<svg contentScriptType="text/ecmascript" fill="none" width="480" xmlns:xlink="http://www.w3.org/1999/xlink" zoomAndPan="magnify" contentStyleType="text/css" height="272" preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg" version="1.0">

 

<polyline stroke-opacity="1" points="23,16 32,26 45,38 67,57 89,76 111,90 145,92 176,84 184,73" stroke="black"></polyline>

</svg>

 

Michael Bishop

Reply via email to