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 "Baron, Randy {PRG~Basel}" <RA...@Roche.COM> on 2003/04/02 15:30:38 UTC

getCharNumAtPosition() and transformations

hi-
   I am using the getCharNumAtPosition() method from
SVGOMTextContentElement
<file:///C:\JavaDev\Other%20Packages\BATIK\batik-docs-1.5beta5\docs\java
doc\org\apache\batik\dom\svg\SVGOMTextContentElement.html> .  The user
clicks on some text on the SVG display, the program gets the element
clicked on from the target of the event, uses the MouseEvent's
getClientX() and getClientY() to pass the point to
getCharNumAtPosition(). It works very well...up to a point.  I can get
the index of a character at a given position in the string but if I zoom
or pan or rotate the canvas,  getCharNumAtPosition returns either a -1
or, in some cases, a number corresponding to a kind of virtual character
that would have been on that location if the original display were still
showing.  Does anyone know if this is the intended behavior?  Is it
possible to have it continue finding the actual character that is
clicked on after a transformation?
 
-Randy

RE: getCharNumAtPosition() and transformations

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "BR" == Baron, Randy {PRG~Basel} <RA...@Roche.COM> writes:

BR> hi- I am using the getCharNumAtPosition() method from
BR> SVGOMTextContentElement
BR> <file:///C:\JavaDev\Other%20Packages\BATIK\batik-docs-1.5beta5\docs\java
BR> doc\org\apache\batik\dom\svg\SVGOMTextContentElement.html> .  

BR> The user clicks on some text on the SVG display, the program gets
BR> the element clicked on from the target of the event, uses the
BR> MouseEvent's getClientX() and getClientY() to pass the point to
BR> getCharNumAtPosition(). 

    getClientX/Y return the mouse click in the viewport coordinate
system (essentially screen pixel locations).  You need to transform it
to the text element's coordinate system.

    This can be done by calling 'getScreenCTM()' on the text element
you want to call 'getCharNumAtPosition()' on, get the inverse of that
affine transform and apply that transform to the getClientX/Y point.

    Take a look at:
        xml-batik/samples/tests/spec/scripting/currentScaleTranslate.svg

    In particular the function 'mouseOver' does almost exactly what
you want.

BR> It works very well...up to a point.  I can get the index of a
BR> character at a given position in the string but if I zoom or pan
BR> or rotate the canvas, getCharNumAtPosition returns either a -1 or,
BR> in some cases, a number corresponding to a kind of virtual
BR> character that would have been on that location if the original
BR> display were still showing.  Does anyone know if this is the
BR> intended behavior?  Is it possible to have it continue finding the
BR> actual character that is clicked on after a transformation?
 


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