From: Laurent D. <lau...@ne...> - 2000-08-22 22:24:29
|
On 22 Aug, Scott Stanton wrote: > > This is a great idea! It's taking advantage of some features in Unicode > to finesse the whole underline issue. The concept is quite elegant, > really. I do have a few comments about the implementation though: > Thanks to Jan for the idea. I didn't even know such a character existed. > - If you are adding \_ to the Tcl backslash parser, you need to do the > same thing for the regexp backslash parser. > Ok, I'll look at it as soon as I have the time. Maybe even tonight. > - Rather than putting a constant like 0x332 directly in the code, it might > be better to add a #define for TCL_COMBINING_LOW_LINE (the official > Unicode character name). > Ok. Does this go in tcl.h? I guess, if it's needed by Tk. > - Don't assume that the \_ character actually takes 2 bytes. This is only > true if the string is in canonical UTF form. It's actually possible to > represent a \_ with 3 or more bytes in a non-canonical form. Always use > the Tcl UTF functions to compute character offsets. > Ok. I'll revise that. > - Your algorithm ends up scanning the string twice. It would be faster to > skip the call to Tcl_UtfFindFirst() and just do character by character > comparisons. > Hmmm... Ok. I have to go thru the string anyway. > - If you remove the \_ from the original text string, then a cget -text > won't return the correct value. You need to make a separate copy of the > string for rendering purposes. > Well, the whole idea of removing the string was so I wouldn't have to keep a separate copy around. I didn't want to modify the structure of tkButton and gobble up even more memory. As I said in the Enhancement request on clt, I didn't really like it. ... So maybe I'll add another attribute to tkButton which will be non-null only if the string contains a \_ in it. That way, you only use up 4 bytes to store the pointer but nothing else if you're not using the facility. This will change the way ConfigureButton() works. > - If you were going to update the string in place, you should call > Tcl_SetObjLength to set the new length. > Ok, didn't know thatg. > > For illustrative purposes, here is a revised ButtonComputeUnderline > function. It hasn't been tested (and so is probably wrong in some > places), and it assumes the addition of a butPtr->textDisplayPtr field to > hold the display string. It does demonstrate the correct way to process > the UTF data, though. Note the use of Tcl_GetStringFromObj to get the > length in bytes in addition to the string pointer. > Thanks, I'll study it and I'll try to send a revised patch by week's end but I make no promises. L -- MY EMAIL ADDRESS HAS CHANGED --> UPDATE YOUR ADDRESSBOOK Laurent Duperval "Montreal winters are an intelligence test, Netergy Networks - Java Center and we who are here have failed it." Phone: (514) 282-8484 ext. 228 -Doug Camilli mailto:lau...@ne... Penguin Power! -- The TclCore mailing list is sponsored by Ajuba Solutions To unsubscribe: email tcl...@aj... with the word UNSUBSCRIBE as the subject. |