summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-20 16:51:57 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-20 16:51:57 (GMT)
commit38d1c0b4e30e546ebe17c179e46e99884dcab433 (patch)
tree626a91a7efdd0b61978a1ff2c0ccf262ada91491 /macosx
parent51d384bfda7a3eb5a915b19d343c8bb657268d75 (diff)
parent75d83ece93c7c0f3a2a3c8e3a925b35353ccddeb (diff)
downloadtk-38d1c0b4e30e546ebe17c179e46e99884dcab433.zip
tk-38d1c0b4e30e546ebe17c179e46e99884dcab433.tar.gz
tk-38d1c0b4e30e546ebe17c179e46e99884dcab433.tar.bz2
Add (and use) new internal function TkUtfAtIndex(), which does the same as Tcl_UtfAtIndex() only it protects against ending in the middle of a 4-byte UTF-8 sequence. This should fix another part of [a179564826] when handling copy-pasted Emoji in Text/Entry (and other) widgets.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/tkMacOSXBitmap.c1
-rw-r--r--macosx/tkMacOSXFont.c33
-rw-r--r--macosx/tkMacOSXPrivate.h2
3 files changed, 9 insertions, 27 deletions
diff --git a/macosx/tkMacOSXBitmap.c b/macosx/tkMacOSXBitmap.c
index 615192b..2b08235 100644
--- a/macosx/tkMacOSXBitmap.c
+++ b/macosx/tkMacOSXBitmap.c
@@ -317,7 +317,6 @@ TkpGetNativeAppBitmap(
OSType iconType;
if (OSTypeFromString(name, &iconType) == TCL_OK) {
NSString *iconUTI = OSTYPE_TO_UTI(iconType);
- printf("Found image for UTI %s\n", iconUTI.UTF8String);
NSImage *iconImage = [[NSWorkspace sharedWorkspace]
iconForFileType: iconUTI];
pixmap = PixmapFromImage(display, iconImage, NSSizeToCGSize(size));
diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c
index 7fc0113..d704184 100644
--- a/macosx/tkMacOSXFont.c
+++ b/macosx/tkMacOSXFont.c
@@ -105,7 +105,7 @@ static void DrawCharsInContext(Display *display, Drawable drawable,
* To avoid an extra copy, a TKNSString object wraps a Tcl_DString with an
* NSString that uses the DString's buffer as its character buffer. It can be
* constructed from a Tcl_DString and it has a DString property that handles
- * converting from an NSString to a Tcl_DString
+ * converting from an NSString to a Tcl_DString.
*/
@implementation TKNSString
@@ -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;
}
@@ -1056,7 +1039,7 @@ TkpMeasureCharsInContext(
[attributedString release];
[string release];
length = ceil(width - offset);
- fit = (Tcl_UtfAtIndex(source, index) - source) - rangeStart;
+ fit = (TkUtfAtIndex(source, index) - source) - rangeStart;
done:
#ifdef TK_MAC_DEBUG_FONTS
TkMacOSXDbgMsg("measure: source=\"%s\" range=\"%.*s\" maxLength=%d "
diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h
index a0645f7..be69fcd 100644
--- a/macosx/tkMacOSXPrivate.h
+++ b/macosx/tkMacOSXPrivate.h
@@ -527,7 +527,7 @@ VISIBILITY_HIDDEN
* byte sequence as initial data. So we add a new class which does provide
* such a constructor. It also has a DString property which is a DString whose
* string pointer is a byte sequence encoding the NSString with the current Tk
- * encoding, namely UTF-8 if TCL_MAX >= 4 or CESU-8 if TCL_MAX = 3.
+ * encoding, namely UTF-8 if TCL_UTF_MAX >= 4 or CESU-8 if TCL_UTF_MAX = 3.
*
*---------------------------------------------------------------------------
*/