浏览代码

testclipboard: added support for UCS-2 and UCS-4 text

Chrome uses UCS-2 text for text/x-moz-url content
Sam Lantinga 2 天之前
父节点
当前提交
0e7d5620c2
共有 1 个文件被更改,包括 16 次插入2 次删除
  1. 16 2
      test/testclipboard.c

+ 16 - 2
test/testclipboard.c

@@ -92,9 +92,23 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
 
 static float PrintClipboardText(float x, float y, const char *mime_type)
 {
-    void *data = SDL_GetClipboardData(mime_type, NULL);
+    size_t size;
+    void *data = SDL_GetClipboardData(mime_type, &size);
     if (data) {
-        SDL_RenderDebugText(renderer, x, y, (const char *)data);
+        char *text = (char *)data;
+        if (size > 2 && text[2] == '\0') {
+            /* UCS-4 data */
+            text = (char *)SDL_iconv_string("UTF-8", "UCS-4", data, size+4);
+        } else if (size > 1 && text[1] == '\0') {
+            /* UCS-2 data */
+            text = (char *)SDL_iconv_string("UTF-8", "UCS-2", data, size+2);
+        }
+        if (text) {
+            SDL_RenderDebugText(renderer, x, y, text);
+        }
+        if (text != data) {
+            SDL_free(text);
+        }
         SDL_free(data);
         return SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE + 2.0f;
     }