From 0e7d5620c23bd9220bd20da8c908053efddba2b1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 9 Oct 2025 10:22:23 -0700 Subject: [PATCH] testclipboard: added support for UCS-2 and UCS-4 text Chrome uses UCS-2 text for text/x-moz-url content --- test/testclipboard.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/test/testclipboard.c b/test/testclipboard.c index 85e887b6b8..ac884f9014 100644 --- a/test/testclipboard.c +++ b/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; }