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 Denis Bohm <de...@fireflydesign.com> on 2003/08/19 23:22:47 UTC

getCharNumAtPosition trouble

I'm trying to track the cursor movement across some text to highlight the
character that the cursor is over.  In my svg I have a text element that
contains a tspan element.  I tried the following on mousemove for the text,
but always get -1 for the character index:

        SVGTSpanElement text = (SVGTSpanElement) event.getTarget();
        SVGTextElement parent = (SVGTextElement) text.getParentNode();
        SVGMatrix transform = parent.getScreenCTM();
        SVGMatrix inverse = transform.inverse();
        SVGDocument document = canvas_.getSVGDocument();
        SVGSVGElement root = document.getRootElement();
        SVGPoint point = root.createSVGPoint();
        point.setX(event.getScreenX());
        point.setY(event.getScreenY());
        point = point.matrixTransform(inverse);
        int index = text.getCharNumAtPosition(point);
        System.out.println(index);
        SVGRect extent = parent.getExtentOfChar(0);
        System.out.println(extent.getX() + " " + extent.getY());

So I tried the following, which also gives -1:

        point.setX(extent.getX() + 1);
        point.setY(extent.getY() + 1);
        index = parent.getCharNumAtPosition(point);
        System.out.println(index);

Any idea what I might be doing wrong?

Thanks,
  Denis


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


Re: SVGTextElement.selectSubString refresh

Posted by Thomas DeWeese <Th...@Kodak.com>.
Denis Bohm wrote:
> I'm changing the text selection from a mousemove event handler and it does
> not seem to refresh on the screen until I resize the window.  I wasn't sure
> if the event handler is called from the update manager thread, so I tried
> invokeLater also, but it didn't make any difference.  Am I missing something
> in my code that I need to do to cause the refresh?

Hi Denis,

   I'm surprised it refreshes the selection when you resize the window ;)

   The code currently only notifies the TextNode of selection changes, it should
notify the UserAgent, but those methods don't current exist.  If you could
post a bug on bugzilla with a bugzilla attachment that shows the problem that
would be extremely helpful to ensure the problem is remembered and fixed.

   Thanks!



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


SVGTextElement.selectSubString refresh

Posted by Denis Bohm <de...@fireflydesign.com>.
I'm changing the text selection from a mousemove event handler and it does
not seem to refresh on the screen until I resize the window.  I wasn't sure
if the event handler is called from the update manager thread, so I tried
invokeLater also, but it didn't make any difference.  Am I missing something
in my code that I need to do to cause the refresh?

Thanks,
  Denis


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


Re: getCharNumAtPosition trouble

Posted by Thomas DeWeese <Th...@Kodak.com>.
Denis Bohm wrote:
>>Denis Bohm wrote:
>>
>>>I checked out the lastest CVS and am trying that.  The root of the
> 
> problem
> 
>>>seems to be that I'm getting negative numbers from MouseEvent.getClientY
>>>when I point at the center of the text.  This seems wrong.  Shouldn't I
> 
> only
> 
>>>get positive values since they are with respect to the upper left of the
>>>canvas?
>>
>>   If this is before you apply the matrix yes you should only get positive
>>values.  There must be something odd about your setup as I have never seen
>>this happen.  I'm sure a standalone version of the problem would help
> 
> immensely.
> 
> The MouseEvent client coordinates seem to be in the coordinate system of the
> SVG element, not in the coordinate system of the SVG canvas as I had
> thought.  This seems incorrect according to the W3C spec.

   It turns out this was a bug that only effected Text (for text we need to
get the point in the Text coordinate system so we can figure out which tspan
element is the event target - this code accidentally modified the Point
stored in the event object), I am really surprised I never noticed this bug
before as I often have event handlers on text.

> From reading over the W3C specs again it seems to me that:
> 
> - SVGLocatable.getScreenCTM should give a transform from element coordinates
> to physical device coordinates

   I've sent a message to the SVG working group you can read that to understand
why I'm not certain this is the correct behaviour:

http://lists.w3.org/Archives/Public/www-svg/

   The server seems to be down right now so I can't reference the message
directly.

> - MouseEvent.getScreenX/Y should give physical device coordinates
> - MouseEvent.getClientX/Y should give canvas coordinates
> - physical device coordinates == screen coordinates (not top level window
> coordinates)
> 
> Does that sound right?

    Yes, mostly.



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


Re: getCharNumAtPosition trouble

Posted by Denis Bohm <de...@fireflydesign.com>.
> Denis Bohm wrote:
> > I checked out the lastest CVS and am trying that.  The root of the
problem
> > seems to be that I'm getting negative numbers from MouseEvent.getClientY
> > when I point at the center of the text.  This seems wrong.  Shouldn't I
only
> > get positive values since they are with respect to the upper left of the
> > canvas?
>
>    If this is before you apply the matrix yes you should only get positive
> values.  There must be something odd about your setup as I have never seen
> this happen.  I'm sure a standalone version of the problem would help
immensely.

The MouseEvent client coordinates seem to be in the coordinate system of the
SVG element, not in the coordinate system of the SVG canvas as I had
thought.  This seems incorrect according to the W3C spec.

>From reading over the W3C specs again it seems to me that:

- SVGLocatable.getScreenCTM should give a transform from element coordinates
to physical device coordinates
- MouseEvent.getScreenX/Y should give physical device coordinates
- MouseEvent.getClientX/Y should give canvas coordinates
- physical device coordinates == screen coordinates (not top level window
coordinates)

Does that sound right?


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


Re: getCharNumAtPosition trouble

Posted by Denis Bohm <de...@fireflydesign.com>.
I've attached a small test case to show the problem.  If I bring the cursor
down the window until it touches the top of the text then I see negative
client coordinates printed out.  (The zero point on the Y axis seems like it
may be at the baseline of the text.)  Do you see the same?

----- Original Message ----- 
From: "Thomas DeWeese" <Th...@Kodak.com>
To: "Batik Users" <ba...@xml.apache.org>
Sent: Wednesday, August 20, 2003 10:55 AM
Subject: Re: getCharNumAtPosition trouble


> Denis Bohm wrote:
> > I checked out the lastest CVS and am trying that.  The root of the
problem
> > seems to be that I'm getting negative numbers from MouseEvent.getClientY
> > when I point at the center of the text.  This seems wrong.  Shouldn't I
only
> > get positive values since they are with respect to the upper left of the
> > canvas?
>
>    If this is before you apply the matrix yes you should only get positive
> values.  There must be something odd about your setup as I have never seen
> this happen.  I'm sure a standalone version of the problem would help
immensely.
>
> > BTW:  Here is the SVG that I'm using:
> >
> > <?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 width="220" height="60" viewBox="0 0 220 60">
> >     <text id="expression.0" transform="matrix(1 0 0 1 0 20)">if (true or
> > false) then {&apos;foo&apos;} else {&apos;bar&apos;,
&apos;zip&apos;}</text>
> >     <text id="result.0" transform="matrix(1 0 0 1 0 40)">result</text>
> > </svg>
>
>      Nothing looks particularly odd (other than the use of matrix rather
> than 'translate(0,20)' or a simple y="20" on the text - but you probably
just
> cribbed from Illustrator :)
>
> > ----- Original Message ----- 
> > From: "Thomas DeWeese" <Th...@Kodak.com>
> > To: "Batik Users" <ba...@xml.apache.org>
> > Sent: Wednesday, August 20, 2003 5:03 AM
> > Subject: Re: getCharNumAtPosition trouble
> >
> >
> >
> >>Denis Bohm wrote:
> >>
> >>>I'm trying to track the cursor movement across some text to highlight
> >
> > the
> >
> >>>character that the cursor is over.  In my svg I have a text element
that
> >>>contains a tspan element.  I tried the following on mousemove for the
> >
> > text,
> >
> >>>but always get -1 for the character index:
> >>
> >>    This I believe is because you should use getClientX/Y not screenX/Y.
> >>Rereading the spec it is unclear which coordinate system getScreenCTM
> >
> > should
> >
> >>transform to (clientX/Y has 0,0 at the upper left of the canvas,
screenX/Y
> >>has 0,0 at the upper left of the physical device).
> >>
> >>    I will send a question to the SVG Working Group on this to get a
> >
> > clarification
> >
> >>of what is the correct answer.
> >>
> >>
> >>>        SVGRect extent = parent.getExtentOfChar(0);
> >>>        System.out.println(extent.getX() + " " + extent.getY());
> >>>
> >>>So I tried the following, which also gives -1:
> >>>
> >>>        point.setX(extent.getX() + 1);
> >>>        point.setY(extent.getY() + 1);
> >>>        index = parent.getCharNumAtPosition(point);
> >>>        System.out.println(index);
> >>>
> >>>Any idea what I might be doing wrong?
> >>
> >>    There was a bug in getExtentOfChar which I just fixed in CVS.  You
can
> >>check the commit message to get the patches, or just use CVS to update.
> >>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> >>For additional commands, e-mail: batik-users-help@xml.apache.org
> >>
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> > For additional commands, e-mail: batik-users-help@xml.apache.org
> >
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
>

Re: getCharNumAtPosition trouble

Posted by Thomas DeWeese <Th...@Kodak.com>.
Denis Bohm wrote:
> I checked out the lastest CVS and am trying that.  The root of the problem
> seems to be that I'm getting negative numbers from MouseEvent.getClientY
> when I point at the center of the text.  This seems wrong.  Shouldn't I only
> get positive values since they are with respect to the upper left of the
> canvas?

   If this is before you apply the matrix yes you should only get positive
values.  There must be something odd about your setup as I have never seen
this happen.  I'm sure a standalone version of the problem would help immensely.

> BTW:  Here is the SVG that I'm using:
> 
> <?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 width="220" height="60" viewBox="0 0 220 60">
>     <text id="expression.0" transform="matrix(1 0 0 1 0 20)">if (true or
> false) then {&apos;foo&apos;} else {&apos;bar&apos;, &apos;zip&apos;}</text>
>     <text id="result.0" transform="matrix(1 0 0 1 0 40)">result</text>
> </svg>

     Nothing looks particularly odd (other than the use of matrix rather
than 'translate(0,20)' or a simple y="20" on the text - but you probably just
cribbed from Illustrator :)

> ----- Original Message ----- 
> From: "Thomas DeWeese" <Th...@Kodak.com>
> To: "Batik Users" <ba...@xml.apache.org>
> Sent: Wednesday, August 20, 2003 5:03 AM
> Subject: Re: getCharNumAtPosition trouble
> 
> 
> 
>>Denis Bohm wrote:
>>
>>>I'm trying to track the cursor movement across some text to highlight
> 
> the
> 
>>>character that the cursor is over.  In my svg I have a text element that
>>>contains a tspan element.  I tried the following on mousemove for the
> 
> text,
> 
>>>but always get -1 for the character index:
>>
>>    This I believe is because you should use getClientX/Y not screenX/Y.
>>Rereading the spec it is unclear which coordinate system getScreenCTM
> 
> should
> 
>>transform to (clientX/Y has 0,0 at the upper left of the canvas, screenX/Y
>>has 0,0 at the upper left of the physical device).
>>
>>    I will send a question to the SVG Working Group on this to get a
> 
> clarification
> 
>>of what is the correct answer.
>>
>>
>>>        SVGRect extent = parent.getExtentOfChar(0);
>>>        System.out.println(extent.getX() + " " + extent.getY());
>>>
>>>So I tried the following, which also gives -1:
>>>
>>>        point.setX(extent.getX() + 1);
>>>        point.setY(extent.getY() + 1);
>>>        index = parent.getCharNumAtPosition(point);
>>>        System.out.println(index);
>>>
>>>Any idea what I might be doing wrong?
>>
>>    There was a bug in getExtentOfChar which I just fixed in CVS.  You can
>>check the commit message to get the patches, or just use CVS to update.
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>>For additional commands, e-mail: batik-users-help@xml.apache.org
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 




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


Re: newbie troubles - Thank you Mr. DeWeese!

Posted by Vladimir Georgiev <Vl...@bioanalyte.com>.
It worked!
Ant is high on my list of things to look into.
Thanks again.

Thomas DeWeese wrote:

> Vladimir Georgiev wrote:
>
>> Hi,
>>
>> I just downloaded the source distro of Batik 1.5
>> I'm on Debian 3.0 and build.sh svgbrowser works fine.
>> The resulting batik works great.
>>
>> I have the SVGApplication.java file (courtesy
>> of http://xml.apache.org/batik/javaScripting.html)
>> in the sources directory of batik, i.e. xml-batik/sources/
>>
>> And I get an SVG Error pop-up that says:
>>
>> SAX2 driver class org.apache.xerces.parsers.SAXParser not found
>
> [...]
>
>> I have a strong suspicion that there exists an easy fix for this that 
>> is going to make me feel even more like a newbie,
>> but I will be very grateful to be made feel like that if the fix works.
>
>
> > It compiles fine. I execute it with:
> >
> > java -cp ../resources/:../lib/:. SVGApplication
>
>   You need to have the jar files in lib explicitly on the path.
> I've attached a small shell script you can run from the top level of 
> batik
> and provide a class name and args.  I would suggest getting 
> comfortable with
> something like Ant or Eclipse as typing the java command line by hand is
> a mind boggling waste of time :)
>
>   As a UNIX guy you will probably prefer Ant with it's text based 
> config file
> (it's really simple and very powerful).  However if you like IDE's 
> eclipse can
> be nice.
>
>> Has anyone had this problem before?
>> Anyone know how to fix it?
>>
>> Thanks.
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>> For additional commands, e-mail: batik-users-help@xml.apache.org
>>
>>
>
>------------------------------------------------------------------------
>
>#!/bin/sh
>
># OS specific support.  $var _must_ be set to either true or false.
>cygwin=false;
>case "`uname`" in
>  CYGWIN*) cygwin=true ;;
>esac
>
># Basic runtime path from class files.
>CP=lib/xml-apis.jar:lib/xerces_2_5_0.jar:lib/js.jar:classes:resources
>
>if $cygwin; then
>  JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
>  CP=`cygpath --path --windows "$CP"`
>fi
>
>java -classpath $CP "$*"
>
>  
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: batik-users-help@xml.apache.org
>



Re: newbie troubles

Posted by Thomas DeWeese <Th...@Kodak.com>.
Vladimir Georgiev wrote:
> Hi,
> 
> I just downloaded the source distro of Batik 1.5
> I'm on Debian 3.0 and build.sh svgbrowser works fine.
> The resulting batik works great.
> 
> I have the SVGApplication.java file (courtesy
> of http://xml.apache.org/batik/javaScripting.html)
> in the sources directory of batik, i.e. xml-batik/sources/
> 
> And I get an SVG Error pop-up that says:
> 
> SAX2 driver class org.apache.xerces.parsers.SAXParser not found
[...]
> I have a strong suspicion that there exists an easy fix for this that is 
> going to make me feel even more like a newbie,
> but I will be very grateful to be made feel like that if the fix works.

 > It compiles fine. I execute it with:
 >
 > java -cp ../resources/:../lib/:. SVGApplication

   You need to have the jar files in lib explicitly on the path.
I've attached a small shell script you can run from the top level of batik
and provide a class name and args.  I would suggest getting comfortable with
something like Ant or Eclipse as typing the java command line by hand is
a mind boggling waste of time :)

   As a UNIX guy you will probably prefer Ant with it's text based config file
(it's really simple and very powerful).  However if you like IDE's eclipse can
be nice.

> Has anyone had this problem before?
> Anyone know how to fix it?
> 
> Thanks.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 


newbie troubles

Posted by Vladimir Georgiev <Vl...@bioanalyte.com>.
Hi,

I just downloaded the source distro of Batik 1.5
I'm on Debian 3.0 and build.sh svgbrowser works fine.
The resulting batik works great.

I have the SVGApplication.java file (courtesy
of http://xml.apache.org/batik/javaScripting.html)
in the sources directory of batik, i.e. xml-batik/sources/

It compiles fine. I execute it with:

java -cp ../resources/:../lib/:. SVGApplication

And I get an SVG Error pop-up that says:

SAX2 driver class org.apache.xerces.parsers.SAXParser not found

java.io.IOException: SAX2 driver class 
org.apache.xerces.parsers.SAXParser not found
    at 
org.apache.batik.dom.util.SAXDocumentFactory.createDocument(SAXDocumentFactory.java:379)
    at 
org.apache.batik.dom.util.SAXDocumentFactory.createDocument(SAXDocumentFactory.java:299)
    at 
org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument(SAXSVGDocumentFactory.java:186)
    at 
org.apache.batik.dom.svg.SAXSVGDocumentFactory.createSVGDocument(SAXSVGDocumentFactory.java:111)
    at 
org.apache.batik.bridge.DocumentLoader.loadDocument(DocumentLoader.java:96)
    at 
org.apache.batik.swing.svg.SVGDocumentLoader.run(SVGDocumentLoader.java:82)

I have a strong suspicion that there exists an easy fix for this that is 
going to make me feel even more like a newbie,
but I will be very grateful to be made feel like that if the fix works.

Has anyone had this problem before?
Anyone know how to fix it?

Thanks.



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


Re: getCharNumAtPosition trouble

Posted by Denis Bohm <de...@fireflydesign.com>.
I checked out the lastest CVS and am trying that.  The root of the problem
seems to be that I'm getting negative numbers from MouseEvent.getClientY
when I point at the center of the text.  This seems wrong.  Shouldn't I only
get positive values since they are with respect to the upper left of the
canvas?

BTW:  Here is the SVG that I'm using:

<?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 width="220" height="60" viewBox="0 0 220 60">
    <text id="expression.0" transform="matrix(1 0 0 1 0 20)">if (true or
false) then {&apos;foo&apos;} else {&apos;bar&apos;, &apos;zip&apos;}</text>
    <text id="result.0" transform="matrix(1 0 0 1 0 40)">result</text>
</svg>

----- Original Message ----- 
From: "Thomas DeWeese" <Th...@Kodak.com>
To: "Batik Users" <ba...@xml.apache.org>
Sent: Wednesday, August 20, 2003 5:03 AM
Subject: Re: getCharNumAtPosition trouble


> Denis Bohm wrote:
> > I'm trying to track the cursor movement across some text to highlight
the
> > character that the cursor is over.  In my svg I have a text element that
> > contains a tspan element.  I tried the following on mousemove for the
text,
> > but always get -1 for the character index:
>
>     This I believe is because you should use getClientX/Y not screenX/Y.
> Rereading the spec it is unclear which coordinate system getScreenCTM
should
> transform to (clientX/Y has 0,0 at the upper left of the canvas, screenX/Y
> has 0,0 at the upper left of the physical device).
>
>     I will send a question to the SVG Working Group on this to get a
clarification
> of what is the correct answer.
>
> >         SVGRect extent = parent.getExtentOfChar(0);
> >         System.out.println(extent.getX() + " " + extent.getY());
> >
> > So I tried the following, which also gives -1:
> >
> >         point.setX(extent.getX() + 1);
> >         point.setY(extent.getY() + 1);
> >         index = parent.getCharNumAtPosition(point);
> >         System.out.println(index);
> >
> > Any idea what I might be doing wrong?
>
>     There was a bug in getExtentOfChar which I just fixed in CVS.  You can
> check the commit message to get the patches, or just use CVS to update.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
>


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


Re: getCharNumAtPosition trouble

Posted by Thomas DeWeese <Th...@Kodak.com>.
Denis Bohm wrote:
> I'm trying to track the cursor movement across some text to highlight the
> character that the cursor is over.  In my svg I have a text element that
> contains a tspan element.  I tried the following on mousemove for the text,
> but always get -1 for the character index:

    This I believe is because you should use getClientX/Y not screenX/Y.
Rereading the spec it is unclear which coordinate system getScreenCTM should
transform to (clientX/Y has 0,0 at the upper left of the canvas, screenX/Y
has 0,0 at the upper left of the physical device).

    I will send a question to the SVG Working Group on this to get a clarification
of what is the correct answer.

>         SVGRect extent = parent.getExtentOfChar(0);
>         System.out.println(extent.getX() + " " + extent.getY());
> 
> So I tried the following, which also gives -1:
> 
>         point.setX(extent.getX() + 1);
>         point.setY(extent.getY() + 1);
>         index = parent.getCharNumAtPosition(point);
>         System.out.println(index);
> 
> Any idea what I might be doing wrong?

    There was a bug in getExtentOfChar which I just fixed in CVS.  You can
check the commit message to get the patches, or just use CVS to update.



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