summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:36:40 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:36:40 +0000
commitfdc436b531a36264d6f2ad8d4ae10170a8c281a8 (patch)
tree05812fe435175c36edfc49a540ccab297e1eb7be /src
parent019984a14f01e4463ae479765d2340ff26055367 (diff)
downloadopenttd-fdc436b531a36264d6f2ad8d4ae10170a8c281a8.tar.xz
(svn r25672) -Fix: [Win32] Handle Unicode characters from outside the BMP correctly.
Diffstat (limited to 'src')
-rw-r--r--src/video/win32_v.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index 7a6e8a866..fb50367fc 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -439,12 +439,31 @@ static void PaintWindowThread(void *)
}
/** Forward key presses to the window system. */
-static LRESULT HandleCharMsg(uint keycode, uint charcode)
+static LRESULT HandleCharMsg(uint keycode, WChar charcode)
{
#if !defined(UNICODE)
wchar_t w;
int len = MultiByteToWideChar(_codepage, 0, (char*)&charcode, 1, &w, 1);
charcode = len == 1 ? w : 0;
+#else
+ static WChar prev_char = 0;
+
+ /* Did we get a lead surrogate? If yes, store and exit. */
+ if (Utf16IsLeadSurrogate(charcode)) {
+ if (prev_char != 0) DEBUG(driver, 1, "Got two UTF-16 lead surrogates, dropping the first one");
+ prev_char = charcode;
+ return 0;
+ }
+
+ /* Stored lead surrogate and incoming trail surrogate? Combine and forward to input handling. */
+ if (prev_char != 0) {
+ if (Utf16IsTrailSurrogate(charcode)) {
+ charcode = Utf16DecodeSurrogate(prev_char, charcode);
+ } else {
+ DEBUG(driver, 1, "Got an UTF-16 lead surrogate without a trail surrogate, dropping the lead surrogate");
+ }
+ }
+ prev_char = 0;
#endif /* UNICODE */
HandleKeypress(keycode, charcode);