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 Bibek Sahu <sc...@dodds.net> on 2004/02/03 23:03:53 UTC
text index
Howdy all,
Question for anyone: how do I find the index of a character in a
SVGTextContentElement just-prior to a sub-element?
I'm working on an SVG-Editor, and when the user clicks on a text element,
it becomes the active text element and is where characters get inserted /
removed. I'm stuck on what to do at border-conditions when the user moves
the caret by hitting the left arrow-key or right arrow-key.
For example: suppose I have
<text xml:space="default" id="main-elt">This <tspan id="sub-elt-1"
style="color:blue"> is </tspan> --- <tspan id="sub-elt-2"
style="color:red"> My </tspan> --- example.</text>
... and the user clicks on the 'M' in "My". I set the active element to
be "sub-elt-2", and the current index to be '0'. If a user types, it goes
inside "sub-elt-2".
But suppose the user hits the Left-Arrow, to back up a step and type after
"is". Moving up to the parent element is easy; but what should the cursor
index be? (Note that I've left extra spaces in there, and set the
xml:space to "default" -- the SVG spec says that character indices should
be calculated after text is compressed, which is the wrench in this
equasion).
If I didn't have to worry about character-compression, I'd just walk the
parent's tree until I found "sub-elt-2", keeping track of lengths along
the way. But this falls apart when doing character-compression; are there
easy ways to calculate the character-index just prior to element
"sub-elt-2"? Or even just get the text prior to it, compressed if
necessary?
Thanks!
- Bibek
PS: sorry 'bout the confusing item on DOM Click events in 1.5.1. I'm not
exactly sure what the problem is, but I know it's in my code somewhere.
It looks like nodes are being added wrong when pulled from another
document... but I know how to work around it for now, so 'tis fine ATM.
:-)
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org