diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-09-19 12:05:28 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-09-19 12:05:28 (GMT) |
commit | 06f3173fc0a3402010291caa151baa8fef3e5a9d (patch) | |
tree | cdabe9c60a5c8e415cbb4f7f05dd9b2b59372edf /win | |
parent | b5deacd1f7c7553a45b73fffe25053df18895a8c (diff) | |
parent | bdb580aa2563588e6e1f5090bb9b89369e2f2d4f (diff) | |
download | tk-06f3173fc0a3402010291caa151baa8fef3e5a9d.zip tk-06f3173fc0a3402010291caa151baa8fef3e5a9d.tar.gz tk-06f3173fc0a3402010291caa151baa8fef3e5a9d.tar.bz2 |
Enhanced proposed fix [6c0d7aec67]: unicode text input Windows 8. More places where Unicode surrogate handling could be improved.
Diffstat (limited to 'win')
-rw-r--r-- | win/tkWinFont.c | 21 | ||||
-rw-r--r-- | win/tkWinKey.c | 38 | ||||
-rw-r--r-- | win/tkWinX.c | 13 |
3 files changed, 21 insertions, 51 deletions
diff --git a/win/tkWinFont.c b/win/tkWinFont.c index 940bc10..a281a4f 100644 --- a/win/tkWinFont.c +++ b/win/tkWinFont.c @@ -26,9 +26,8 @@ * Under Windows, a "font family" is uniquely identified by its face name. */ -#define FONTMAP_SHIFT 10 - -#define FONTMAP_PAGES (1 << (sizeof(Tcl_UniChar)*8 - FONTMAP_SHIFT)) +#define FONTMAP_SHIFT 12 +#define FONTMAP_PAGES (1 << (21 - FONTMAP_SHIFT)) #define FONTMAP_BITSPERPAGE (1 << FONTMAP_SHIFT) typedef struct FontFamily { @@ -743,7 +742,7 @@ void TkpGetFontAttrsForChar( Tk_Window tkwin, /* Window on the font's display */ Tk_Font tkfont, /* Font to query */ - Tcl_UniChar c, /* Character of interest */ + int c, /* Character of interest */ TkFontAttributes *faPtr) /* Output: Font attributes */ { WinFont *fontPtr = (WinFont *) tkfont; @@ -828,7 +827,7 @@ Tk_MeasureChars( HFONT oldFont; WinFont *fontPtr; int curX, moretomeasure; - Tcl_UniChar ch; + int ch; SIZE size; FontFamily *familyPtr; Tcl_DString runString; @@ -859,7 +858,7 @@ Tk_MeasureChars( start = source; end = start + numBytes; for (p = start; p < end; ) { - next = p + Tcl_UtfToUniChar(p, &ch); + next = p + TkUtfToUniChar(p, &ch); thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr); if (thisSubFontPtr != lastSubFontPtr) { familyPtr = lastSubFontPtr->familyPtr; @@ -921,7 +920,7 @@ Tk_MeasureChars( familyPtr = lastSubFontPtr->familyPtr; Tcl_DStringInit(&runString); for (p = start; p < end; ) { - next = p + Tcl_UtfToUniChar(p, &ch); + next = p + TkUtfToUniChar(p, &ch); Tcl_UtfToExternal(NULL, familyPtr->encoding, p, (int) (next - p), 0, NULL, buf, sizeof(buf), NULL, &dstWrote, NULL); @@ -970,13 +969,13 @@ Tk_MeasureChars( */ const char *lastWordBreak = NULL; - Tcl_UniChar ch2; + int ch2; end = p; p = source; ch = ' '; while (p < end) { - next = p + Tcl_UtfToUniChar(p, &ch2); + next = p + TkUtfToUniChar(p, &ch2); if ((ch != ' ') && (ch2 == ' ')) { lastWordBreak = p; } @@ -1443,7 +1442,7 @@ MultiFontTextOut( * string when drawing. */ double angle) { - Tcl_UniChar ch; + int ch; SIZE size; HFONT oldFont; FontFamily *familyPtr; @@ -1458,7 +1457,7 @@ MultiFontTextOut( end = source + numBytes; for (p = source; p < end; ) { - next = p + Tcl_UtfToUniChar(p, &ch); + next = p + TkUtfToUniChar(p, &ch); thisSubFontPtr = FindSubFontForChar(fontPtr, ch, &lastSubFontPtr); if (thisSubFontPtr != lastSubFontPtr) { if (p > source) { diff --git a/win/tkWinKey.c b/win/tkWinKey.c index 2698c4d..7fee101 100644 --- a/win/tkWinKey.c +++ b/win/tkWinKey.c @@ -88,6 +88,8 @@ TkpGetString( * result. */ { XKeyEvent *keyEv = &eventPtr->xkey; + int len; + char buf[6]; Tcl_DStringInit(dsPtr); if (keyEv->send_event == -1) { @@ -95,41 +97,14 @@ TkpGetString( Tcl_ExternalToUtfDString(TkWinGetKeyInputEncoding(), keyEv->trans_chars, keyEv->nbytes, dsPtr); } - } else if (keyEv->send_event == -2) { - /* - * Special case for win2000 multi-lingal IME input. xkey.trans_chars[] - * already contains a UNICODE char. - */ - - int unichar; - char buf[XMaxTransChars]; - int len; - - unichar = keyEv->trans_chars[1] & 0xff; - unichar <<= 8; - unichar |= keyEv->trans_chars[0] & 0xff; - - len = Tcl_UniCharToUtf((Tcl_UniChar) unichar, buf); - - Tcl_DStringAppend(dsPtr, buf, len); } else if (keyEv->send_event == -3) { - char buf[XMaxTransChars]; - int len; - /* - * Special case for WM_UNICHAR. + * Special case for WM_UNICHAR and win2000 multi-lingal IME input */ - len = Tcl_UniCharToUtf(keyEv->keycode, buf); - if ((keyEv->keycode <= 0xffff) || (len == XMaxTransChars)) { - Tcl_DStringAppend(dsPtr, buf, len); - } else { - 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); - } + len = TkUniCharToUtf(keyEv->keycode, buf); + Tcl_DStringAppend(dsPtr, buf, len); } else { /* * This is an event generated from generic code. It has no nchars or @@ -140,9 +115,6 @@ TkpGetString( if (((keysym != NoSymbol) && (keysym > 0) && (keysym < 256)) || (keysym == XK_Return) || (keysym == XK_Tab)) { - char buf[XMaxTransChars]; - int len; - len = Tcl_UniCharToUtf((Tcl_UniChar) (keysym & 255), buf); Tcl_DStringAppend(dsPtr, buf, len); } diff --git a/win/tkWinX.c b/win/tkWinX.c index bb60a2d..987fbb5 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -1580,8 +1580,8 @@ HandleIMEComposition( /* * Set up the fields pertinent to key event. * - * We set send_event to the special value of -2, so that TkpGetString - * in tkWinKey.c knows that trans_chars[] already contains a UNICODE + * We set send_event to the special value of -3, so that TkpGetString + * in tkWinKey.c knows that keycode already contains a UNICODE * char and there's no need to do encoding conversion. * * Note that the event *must* be zeroed out first; Tk plays cunning @@ -1592,7 +1592,7 @@ HandleIMEComposition( memset(&event, 0, sizeof(XEvent)); event.xkey.serial = winPtr->display->request++; - event.xkey.send_event = -2; + event.xkey.send_event = -3; event.xkey.display = winPtr->display; event.xkey.window = winPtr->window; event.xkey.root = RootWindow(winPtr->display, winPtr->screenNum); @@ -1600,8 +1600,7 @@ HandleIMEComposition( event.xkey.state = TkWinGetModifierState(); event.xkey.time = TkpGetMS(); event.xkey.same_screen = True; - event.xkey.keycode = 0; - event.xkey.nbytes = 2; + event.xkey.nbytes = 0; for (i=0; i<n; ) { /* @@ -1609,8 +1608,8 @@ HandleIMEComposition( * UNICODE character in the composition. */ - event.xkey.trans_chars[0] = (char) buff[i++]; - event.xkey.trans_chars[1] = (char) buff[i++]; + event.xkey.keycode = ((unsigned char) buff[i++]) << 8; + event.xkey.keycode += (unsigned char) buff[i++]; event.type = KeyPress; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); |