public static double [ ] getRelativeCoordinates ( Event evt , Element reference ) { if ( evt instanceof DOMMouseEvent && reference instanceof SVGLocatable && reference instanceof SVGElement ) { // Get the screen (pixel!) coordinates DOMMouseEvent gnme = ( DOMMouseEvent ) evt ; SVGMatrix mat = ( ( SVGLocatable ) reference ) . getScreenCTM ( ) ; SVGMatrix imat = mat . inverse ( ) ; SVGPoint cPt = ( ( SVGElement ) reference ) . getOwnerSVGElement ( ) . createSVGPoint ( ) ; cPt . setX ( gnme . getClientX ( ) ) ; cPt . setY ( gnme . getClientY ( ) ) ; // Have Batik transform the screen (pixel!) coordinates into SVG element // coordinates cPt = cPt . matrixTransform ( imat ) ; return new double [ ] { cPt . getX ( ) , cPt . getY ( ) } ; } return null ; }
Get the relative coordinates of a point within the coordinate system of a particular SVG Element .