فهرست منبع

Cocoa: Fix non-BMP Unicode codepoint input

Supplimentary Plane codepoints were reported as UTF-16 surrogate pairs.

Fixes #1635.
Camilla Löwy 5 سال پیش
والد
کامیت
ad9eb768c9
2فایلهای تغییر یافته به همراه19 افزوده شده و 6 حذف شده
  1. 3 0
      README.md
  2. 16 6
      src/cocoa_window.m

+ 3 - 0
README.md

@@ -164,6 +164,8 @@ information on what to include when reporting a bug.
  - [Cocoa] Bugfix: Undecorated windows could not be iconified on recent macOS
  - [Cocoa] Bugfix: Undecorated windows could not be iconified on recent macOS
  - [Cocoa] Bugfix: Touching event queue from secondary thread before main thread
  - [Cocoa] Bugfix: Touching event queue from secondary thread before main thread
    would abort (#1649)
    would abort (#1649)
+ - [Cocoa] Bugfix: Non-BMP Unicode codepoint input was reported as UTF-16
+   (#1635)
  - [X11] Bugfix: The CMake files did not check for the XInput headers (#1480)
  - [X11] Bugfix: The CMake files did not check for the XInput headers (#1480)
  - [X11] Bugfix: Key names were not updated when the keyboard layout changed
  - [X11] Bugfix: Key names were not updated when the keyboard layout changed
    (#1462,#1528)
    (#1462,#1528)
@@ -411,6 +413,7 @@ skills.
  - Ryogo Yoshimura
  - Ryogo Yoshimura
  - Lukas Zanner
  - Lukas Zanner
  - Andrey Zholos
  - Andrey Zholos
+ - Aihui Zhu
  - Santi Zupancic
  - Santi Zupancic
  - Jonas Ådahl
  - Jonas Ådahl
  - Lasse Öörni
  - Lasse Öörni

+ 16 - 6
src/cocoa_window.m

@@ -731,14 +731,24 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
     else
     else
         characters = (NSString*) string;
         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;
+
+        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);
+            _glfwInputChar(window, codepoint, mods, plain);
+        }
     }
     }
 }
 }