[PATCH 8/8] winex11: Directly use ntdll for utf8 conversion.

Jacek Caban wine at gitlab.winehq.org
Thu Apr 28 07:12:20 CDT 2022


From: Jacek Caban <jacek at codeweavers.com>

---
 dlls/winex11.drv/clipboard.c | 11 +++++------
 dlls/winex11.drv/window.c    |  7 ++++---
 dlls/winex11.drv/xrandr.c    |  8 ++++++--
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/dlls/winex11.drv/clipboard.c b/dlls/winex11.drv/clipboard.c
index 1dcd5362c8c..f9e6764fc0a 100644
--- a/dlls/winex11.drv/clipboard.c
+++ b/dlls/winex11.drv/clipboard.c
@@ -914,12 +914,11 @@ static void *import_text_html( Atom type, const void *data, size_t size, size_t
     /* Firefox uses UTF-16LE with byte order mark. Convert to UTF-8 without the BOM. */
     if (size >= sizeof(WCHAR) && ((const WCHAR *)data)[0] == 0xfeff)
     {
-        len = WideCharToMultiByte( CP_UTF8, 0, (const WCHAR *)data + 1, size / sizeof(WCHAR) - 1,
-                                   NULL, 0, NULL, NULL );
-        if (!(text = malloc( len ))) return 0;
-        WideCharToMultiByte( CP_UTF8, 0, (const WCHAR *)data + 1, size / sizeof(WCHAR) - 1,
-                             text, len, NULL, NULL );
-        size = len;
+        DWORD str_len;
+        RtlUnicodeToUTF8N( NULL, 0, &str_len, (const WCHAR *)data + 1, size - sizeof(WCHAR) );
+        if (!(text = malloc( str_len ))) return NULL;
+        RtlUnicodeToUTF8N( text, str_len, &str_len, (const WCHAR *)data + 1, size - sizeof(WCHAR) );
+        size = str_len;
         data = text;
     }
 
diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c
index d7027032465..3b0ccd8d22a 100644
--- a/dlls/winex11.drv/window.c
+++ b/dlls/winex11.drv/window.c
@@ -437,22 +437,23 @@ static void sync_window_opacity( Display *display, Window win,
  */
 static void sync_window_text( Display *display, Window win, const WCHAR *text )
 {
-    UINT count;
+    DWORD count, len;
     char *buffer, *utf8_buffer;
     XTextProperty prop;
 
     /* allocate new buffer for window text */
+    len = lstrlenW( text );
     count = WideCharToMultiByte(CP_UNIXCP, 0, text, -1, NULL, 0, NULL, NULL);
     if (!(buffer = malloc( count ))) return;
     WideCharToMultiByte(CP_UNIXCP, 0, text, -1, buffer, count, NULL, NULL);
 
-    count = WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), NULL, 0, NULL, NULL);
+    RtlUnicodeToUTF8N( NULL, 0, &count, text, len * sizeof(WCHAR) );
     if (!(utf8_buffer = malloc( count )))
     {
         free( buffer );
         return;
     }
-    WideCharToMultiByte(CP_UTF8, 0, text, strlenW(text), utf8_buffer, count, NULL, NULL);
+    RtlUnicodeToUTF8N( utf8_buffer, count, &count, text, len * sizeof(WCHAR) );
 
     if (XmbTextListToTextProperty( display, &buffer, 1, XStdICCTextStyle, &prop ) == Success)
     {
diff --git a/dlls/winex11.drv/xrandr.c b/dlls/winex11.drv/xrandr.c
index b0619c0abcd..6ede776d76b 100644
--- a/dlls/winex11.drv/xrandr.c
+++ b/dlls/winex11.drv/xrandr.c
@@ -652,6 +652,7 @@ static BOOL get_gpu_properties_from_vulkan( struct gdi_gpu *gpu, const XRRProvid
     VkPhysicalDeviceIDProperties id;
     VkInstance vk_instance = NULL;
     VkDisplayKHR vk_display;
+    DWORD len;
     BOOL ret = FALSE;
     VkResult vr;
 
@@ -723,7 +724,8 @@ static BOOL get_gpu_properties_from_vulkan( struct gdi_gpu *gpu, const XRRProvid
                 gpu->vendor_id = properties2.properties.vendorID;
                 gpu->device_id = properties2.properties.deviceID;
             }
-            MultiByteToWideChar( CP_UTF8, 0, properties2.properties.deviceName, -1, gpu->name, ARRAY_SIZE(gpu->name) );
+            RtlUTF8ToUnicodeN( gpu->name, sizeof(gpu->name), &len, properties2.properties.deviceName,
+                               strlen( properties2.properties.deviceName ) + 1 );
             ret = TRUE;
             goto done;
         }
@@ -749,6 +751,7 @@ static BOOL xrandr14_get_gpus2( struct gdi_gpu **new_gpus, int *count, BOOL get_
     INT primary_provider = -1;
     RECT primary_rect;
     BOOL ret = FALSE;
+    DWORD len;
     INT i, j;
 
     screen_resources = xrandr_get_screen_resources();
@@ -803,7 +806,8 @@ static BOOL xrandr14_get_gpus2( struct gdi_gpu **new_gpus, int *count, BOOL get_
         if (get_properties)
         {
             if (!get_gpu_properties_from_vulkan( &gpus[i], provider_info ))
-                MultiByteToWideChar( CP_UTF8, 0, provider_info->name, -1, gpus[i].name, ARRAY_SIZE(gpus[i].name) );
+                RtlUTF8ToUnicodeN( gpus[i].name, sizeof(gpus[i].name), &len, provider_info->name,
+                                   strlen( provider_info->name ) + 1 );
             /* FIXME: Add an alternate method of getting PCI IDs, for systems that don't support Vulkan */
         }
         pXRRFreeProviderInfo( provider_info );
-- 
GitLab

https://gitlab.winehq.org/wine/wine/-/merge_requests/11



More information about the wine-devel mailing list