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 George Armhold <ar...@cs.rutgers.edu> on 2003/08/21 16:02:58 UTC

problem with getViewBoxTransform in 1.5 CVS

Greetings,

We are trying to implement a whiteboard-like scribble tool using
JSVGComponent.  In order to get mouse events we extend JSVGComponent
and implement MouseListener & MouseMotionListener.  Then the trick is
to convert the AWT coordinates into viewbox coords, so that the SVG
doc can be appropriately modified.  (We are saving the drawing events
directly to the SVG for later playback.)  Here is how we are doing the
coordinate translation:

   /**
    * get an AffineTransform which will convert AWT screen coords to
    * viewbox coords for the current document.
    */
   private void getInverseAFT() {
     try {
       AffineTransform aft = getViewBoxTransform();
       inverseAFT = aft.createInverse();
     } catch(NoninvertibleTransformException err) {
       err.printStackTrace(System.err);  // FIXME: better error handling
     }
   }


   /**
    * Convert an AWT screen coordinate to a SVG viewbox coord for the
    * current document.
    */
   private Point2D screenToViewBox(java.awt.event.MouseEvent e) {
     if (inverseAFT == null) {
       getInverseAFT();
     }

     Point2D p = new Point2D.Float(e.getX(), e.getY());
     return inverseAFT.transform(p, p);
   }

The problem: if the JSVGComponent has not been resized,
getViewBoxTransform() seems to return an AffineTransform that
does not do the proper scaling- the AWT coords end up rendering in the
upper-left hand corner of the SVG doc.  If I resize the component by
dragging the resize bar on the frame (or force a resize using
setSize()) it works fine.

Can anyone comment on this?  We are using the latest batik 1.5 from
CVS.

Thanks for your help.



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


Re: problem with getViewBoxTransform in 1.5 CVS

Posted by Thomas DeWeese <Th...@Kodak.com>.
George Armhold wrote:
> Greetings,
> 
> We are trying to implement a whiteboard-like scribble tool using
> JSVGComponent.  In order to get mouse events we extend JSVGComponent
> and implement MouseListener & MouseMotionListener.  Then the trick is
> to convert the AWT coordinates into viewbox coords, so that the SVG
> doc can be appropriately modified.  (We are saving the drawing events
> directly to the SVG for later playback.)  Here is how we are doing the
> coordinate translation:
> 
>   /**
>    * get an AffineTransform which will convert AWT screen coords to
>    * viewbox coords for the current document.
>    */
>   private void getInverseAFT() {
>     try {
>       AffineTransform aft = getViewBoxTransform();
>       inverseAFT = aft.createInverse();
>     } catch(NoninvertibleTransformException err) {
>       err.printStackTrace(System.err);  // FIXME: better error handling
>     }
>   }
> 
> 
>   /**
>    * Convert an AWT screen coordinate to a SVG viewbox coord for the
>    * current document.
>    */
>   private Point2D screenToViewBox(java.awt.event.MouseEvent e) {
>     if (inverseAFT == null) {
>       getInverseAFT();
>     }
> 
>     Point2D p = new Point2D.Float(e.getX(), e.getY());
>     return inverseAFT.transform(p, p);
>   }
> 
> The problem: if the JSVGComponent has not been resized,
> getViewBoxTransform() seems to return an AffineTransform that
> does not do the proper scaling- the AWT coords end up rendering in the
> upper-left hand corner of the SVG doc.  If I resize the component by
> dragging the resize bar on the frame (or force a resize using
> setSize()) it works fine.
> 
> Can anyone comment on this?  We are using the latest batik 1.5 from
> CVS.

   The caching of the inverseAFT seems like it might be problematic.
I would always get the viewbox transform and get it's inverse (for
a 2x2 matrix this is pretty light weight really).  Otherwise this
code looks almost exactly like the code in JSVGViewerFrame that is
used to show mouse coordinates in the status bar - and that seems to
work.




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