From 9cae95faa3311a12f0c8e1e85227d225a58c0c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 29 Jun 2020 21:16:59 +0200 Subject: [PATCH] Cocoa: Fix non-BMP Unicode codepoint input Supplimentary Plane codepoints were reported as UTF-16 surrogate pairs. Fixes #1635. (cherry picked from commit ad9eb768c9518dbe94232e5201d318d512ad9beb) --- README.md | 3 +++ src/cocoa_window.m | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d0dd79b5..e0569a4c 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,8 @@ information on what to include when reporting a bug. - Bugfix: Some extension loader headers did not prevent default OpenGL header inclusion (#1695) - [Cocoa] Changed `EGLNativeWindowType` from `NSView` to `CALayer` (#1169) + - [Cocoa] Bugfix: Non-BMP Unicode codepoint input was reported as UTF-16 + (#1635) - [X11] Bugfix: IME input of CJK was broken for "C" locale (#1587,#1636) - [X11] Bugfix: Xlib errors caused by other parts of the application could be reported as GLFW errors @@ -341,6 +343,7 @@ skills. - Ryogo Yoshimura - Lukas Zanner - Andrey Zholos + - Aihui Zhu - Santi Zupancic - Jonas Ådahl - Lasse Öörni diff --git a/src/cocoa_window.m b/src/cocoa_window.m index ddd6e909..9431b2e2 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -731,14 +731,24 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; else characters = (NSString*) string; - const NSUInteger length = [characters length]; - for (NSUInteger i = 0; i < length; i++) + NSRange range = NSMakeRange(0, [characters length]); + while (range.length) { - const unichar codepoint = [characters characterAtIndex:i]; - if ((codepoint & 0xff00) == 0xf700) - continue; + uint32_t codepoint = 0; - _glfwInputChar(window, codepoint, mods, plain); + if ([characters getBytes:&codepoint + maxLength:sizeof(codepoint) + usedLength:NULL + encoding:NSUTF32StringEncoding + options:0 + range:range + remainingRange:&range]) + { + if ((codepoint & 0xff00) == 0xf700) + continue; + + _glfwInputChar(window, codepoint, mods, plain); + } } }