diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-20 10:10:40 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-20 10:10:40 (GMT) |
commit | 75d83ece93c7c0f3a2a3c8e3a925b35353ccddeb (patch) | |
tree | 3837fda35cda470c9a59d59f26068c9fa9394441 /macosx/tkMacOSXFont.c | |
parent | 5e2cf435c8008214b25114de4509a7facd345dbd (diff) | |
download | tk-75d83ece93c7c0f3a2a3c8e3a925b35353ccddeb.zip tk-75d83ece93c7c0f3a2a3c8e3a925b35353ccddeb.tar.gz tk-75d83ece93c7c0f3a2a3c8e3a925b35353ccddeb.tar.bz2 |
Fix TkUtfAtIndex(), still was not 100% correct.
Simplify TKNSString::DString, since Tcl_UniCharToUtf() is already capable of surrogate handling with a proper Tcl version.
Diffstat (limited to 'macosx/tkMacOSXFont.c')
-rw-r--r-- | macosx/tkMacOSXFont.c | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index 6f1ae77..44e25d2 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -133,7 +133,6 @@ static void DrawCharsInContext(Display *display, Drawable drawable, _string = [[NSString alloc] initWithString:aString]; self.UTF8String = _string.UTF8String; } - printf("Initialized with string %s\n", self.UTF8String); return self; } @@ -166,32 +165,16 @@ static void DrawCharsInContext(Display *display, Drawable drawable, * The DString has not been initialized. Construct it from * our string's unicode characters. */ - - char buffer[2*TCL_UTF_MAX]; - unsigned int index, length, ch; + char *p; + int index; Tcl_DStringInit(&_ds); -#if TCL_UTF_MAX == 3 - for (index = 0; index < [_string length]; index++) { - UniChar uni = [_string characterAtIndex: index]; - - if (CFStringIsSurrogateHighCharacter(uni)) { - UniChar low = [_string characterAtIndex: ++index]; - ch = CFStringGetLongCharacterForSurrogatePair(uni, low); - } else { - ch = uni; - } - length = TkUniCharToUtf(ch, buffer); - Tcl_DStringAppend(&_ds, buffer, length); - } -#else + Tcl_DStringSetLength(&_ds, 3 * [_string length]); + p = Tcl_DStringValue(&_ds); for (index = 0; index < [_string length]; index++) { - ch = (int) [_string characterAtIndex: index]; - length = Tcl_UniCharToUtf(ch, buffer); - Tcl_DStringAppend(&_ds, buffer, length); + p += Tcl_UniCharToUtf([_string characterAtIndex: index], p); } - -#endif + Tcl_DStringSetLength(&_ds, p - Tcl_DStringValue(&_ds)); } return _ds; } |