From 30f0774da2cecd4a02f773758fcf81c45cf3fdab Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 21 Nov 2019 10:26:09 +0000 Subject: Now that TkUniCharToUtf() produces maximum of 4 bytes, reduce storage. More code simplifications. Disallow Emoji on X11 without xft, just use replacement character then. --- generic/tkEntry.c | 2 +- generic/tkUtil.c | 19 +++++++++++-------- generic/ttk/ttkEntry.c | 2 +- win/tkWinFont.c | 4 ++-- win/tkWinKey.c | 2 +- win/tkWinX.c | 3 +-- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/generic/tkEntry.c b/generic/tkEntry.c index 0dfacd7..161e581 100644 --- a/generic/tkEntry.c +++ b/generic/tkEntry.c @@ -1923,7 +1923,7 @@ EntryComputeGeometry( if (entryPtr->showChar != NULL) { int ch; - char buf[6]; + char buf[4]; int size; /* diff --git a/generic/tkUtil.c b/generic/tkUtil.c index 8e3e2ee..73bc112 100644 --- a/generic/tkUtil.c +++ b/generic/tkUtil.c @@ -1222,13 +1222,17 @@ TkUtfToUniChar( Tcl_UniChar uniChar = 0; int len = Tcl_UtfToUniChar(src, &uniChar); - if ((uniChar & 0xfc00) == 0xd800) { + if ((uniChar & 0xFC00) == 0xD800) { Tcl_UniChar high = uniChar; /* This can only happen if Tcl is compiled with TCL_UTF_MAX=4, * or when a high surrogate character is detected in UTF-8 form */ int len2 = Tcl_UtfToUniChar(src+len, &uniChar); - if ((uniChar & 0xfc00) == 0xdc00) { - *chPtr = (((high & 0x3ff) << 10) | (uniChar & 0x3ff)) + 0x10000; + if ((uniChar & 0xFC00) == 0xDC00) { +#if defined(__WIN32) || defined(MAC_OSX_TK) || defined(HAVE_XFT) + *chPtr = (((high & 0x3FF) << 10) | (uniChar & 0x3FF)) + 0x10000; +#else + *chPtr = 0xFFFD +#endif len += len2; } else { *chPtr = high; @@ -1259,17 +1263,16 @@ TkUtfToUniChar( int TkUniCharToUtf(int ch, char *buf) { - int size = Tcl_UniCharToUtf(ch, buf); if ((((unsigned)(ch - 0x10000) <= 0xFFFFF)) && (size < 4)) { - /* Hey, this is wrong, we must be running TCL_UTF_MAX==3 - * The best thing we can do is spit out a 4-byte UTF-8 character */ + /* Spit out a 4-byte UTF-8 character */ buf[3] = (char) ((ch | 0x80) & 0xBF); buf[2] = (char) (((ch >> 6) | 0x80) & 0xBF); buf[1] = (char) (((ch >> 12) | 0x80) & 0xBF); buf[0] = (char) ((ch >> 18) | 0xF0); - size = 4; + return 4; + } else { + return Tcl_UniCharToUtf(ch, buf); } - return size; } diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index 1579a32..4862e99 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -279,7 +279,7 @@ static char *EntryDisplayString(const char *showChar, int numChars) char *displayString, *p; int size; int ch; - char buf[6]; + char buf[4]; TkUtfToUniChar(showChar, &ch); size = TkUniCharToUtf(ch, buf); diff --git a/win/tkWinFont.c b/win/tkWinFont.c index 604a667..7b70a08 100644 --- a/win/tkWinFont.c +++ b/win/tkWinFont.c @@ -2172,9 +2172,9 @@ FontMapLoadPage( { FontFamily *familyPtr; Tcl_Encoding encoding; - char src[XMaxTransChars], buf[16]; - USHORT *startCount, *endCount; int i, j, bitOffset, end, segCount; + USHORT *startCount, *endCount; + char buf[16], src[4]; subFontPtr->fontMap[row] = ckalloc(FONTMAP_BITSPERPAGE / 8); memset(subFontPtr->fontMap[row], 0, FONTMAP_BITSPERPAGE / 8); diff --git a/win/tkWinKey.c b/win/tkWinKey.c index 8a83874..29f2ff0 100644 --- a/win/tkWinKey.c +++ b/win/tkWinKey.c @@ -97,8 +97,8 @@ TkpGetString( * result. */ { XKeyEvent *keyEv = &eventPtr->xkey; - char buf[6]; int len; + char buf[4]; Tcl_DStringInit(dsPtr); if (keyEv->send_event == -1) { diff --git a/win/tkWinX.c b/win/tkWinX.c index c01096e..d2af130 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -1478,8 +1478,7 @@ GetTranslatedKey( if ((msg.message == WM_CHAR) && (msg.lParam & 0x20000000)) { xkey->state = 0; } - xkey->trans_chars[xkey->nbytes] = (char) msg.wParam; - xkey->nbytes++; + xkey->trans_chars[xkey->nbytes++] = (char) msg.wParam; if (((unsigned short) msg.wParam) > ((unsigned short) 0xff)) { /* -- cgit v0.12