diff options
author | nijtmans@users.sourceforge.net <jan.nijtmans> | 2016-08-30 10:24:09 (GMT) |
---|---|---|
committer | nijtmans@users.sourceforge.net <jan.nijtmans> | 2016-08-30 10:24:09 (GMT) |
commit | 95b2756be7d3c937cbc5e19ff1456ae374f5a75e (patch) | |
tree | 47d25c98edc0c1c42f9831657c9fc60fa698055c /win | |
parent | 6b6110a379f349fe5417c60fce1e89d75a498072 (diff) | |
download | tk-95b2756be7d3c937cbc5e19ff1456ae374f5a75e.zip tk-95b2756be7d3c937cbc5e19ff1456ae374f5a75e.tar.gz tk-95b2756be7d3c937cbc5e19ff1456ae374f5a75e.tar.bz2 |
Enhance TkpGetString() to handle Unicode characters, even when TCL_UTF_MAX==3.
Diffstat (limited to 'win')
-rw-r--r-- | win/tkWinFont.c | 2 | ||||
-rw-r--r-- | win/tkWinKey.c | 16 | ||||
-rw-r--r-- | win/tkWinX.c | 10 |
3 files changed, 21 insertions, 7 deletions
diff --git a/win/tkWinFont.c b/win/tkWinFont.c index 9172b00..940bc10 100644 --- a/win/tkWinFont.c +++ b/win/tkWinFont.c @@ -2188,7 +2188,7 @@ FontMapLoadPage( { FontFamily *familyPtr; Tcl_Encoding encoding; - char src[TCL_UTF_MAX], buf[16]; + char src[XMaxTransChars], buf[16]; USHORT *startCount, *endCount; int i, j, bitOffset, end, segCount; diff --git a/win/tkWinKey.c b/win/tkWinKey.c index ed546f7..a49898f 100644 --- a/win/tkWinKey.c +++ b/win/tkWinKey.c @@ -102,7 +102,7 @@ TkpGetString( */ int unichar; - char buf[TCL_UTF_MAX]; + char buf[XMaxTransChars]; int len; unichar = keyEv->trans_chars[1] & 0xff; @@ -115,10 +115,18 @@ TkpGetString( } else if (keyEv->send_event == -3) { /* * Special case for WM_UNICHAR. xkey.trans_chars[] already contains a - * UTF-8 char. + * UTF-8 char, except when nbytes == 0 (then it didn't fit there). */ - Tcl_DStringAppend(dsPtr, keyEv->trans_chars, keyEv->nbytes); + if (keyEv->nbytes) { + Tcl_DStringAppend(dsPtr, keyEv->trans_chars, keyEv->nbytes); + } else if (keyEv->keycode > 0xffff) { + char buf[XMaxTransChars]; + Tcl_UniCharToUtf(((keyEv->keycode - 0x10000) >> 10) | 0xd800, buf); + Tcl_DStringAppend(dsPtr, buf, 3); + Tcl_UniCharToUtf(((keyEv->keycode - 0x10000) & 0x3ff) | 0xdc00, buf); + Tcl_DStringAppend(dsPtr, buf, 3); + } } else { /* * This is an event generated from generic code. It has no nchars or @@ -129,7 +137,7 @@ TkpGetString( if (((keysym != NoSymbol) && (keysym > 0) && (keysym < 256)) || (keysym == XK_Return) || (keysym == XK_Tab)) { - char buf[TCL_UTF_MAX]; + char buf[XMaxTransChars]; int len; len = Tcl_UniCharToUtf((Tcl_UniChar) (keysym & 255), buf); diff --git a/win/tkWinX.c b/win/tkWinX.c index 2180f52..6b8bdff 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -1252,8 +1252,14 @@ GenerateXEvent( event.xany.send_event = -3; event.xkey.keycode = wParam; event.xkey.nbytes = Tcl_UniCharToUtf((int)wParam, buffer); - for (i=0; i<event.xkey.nbytes && i<XMaxTransChars; ++i) { - event.xkey.trans_chars[i] = buffer[i]; + if(((int)wParam > 0xffff) && (event.xkey.nbytes < 4)) { + /* trans_chars buffer is not big enough to hold 2 surrogate + characters, so don't store anything */ + event.xkey.nbytes = 0; + } else { + for (i=0; i<event.xkey.nbytes && i<XMaxTransChars; ++i) { + event.xkey.trans_chars[i] = buffer[i]; + } } Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); event.type = KeyRelease; |