Commit 6afcd71a authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

winex11: Move Unicode conversion out of string_from_unicode_text.

parent 56f1ed6a
...@@ -729,9 +729,11 @@ static void *import_utf8_string( Atom type, const void *data, size_t size, size_ ...@@ -729,9 +729,11 @@ static void *import_utf8_string( Atom type, const void *data, size_t size, size_
DWORD str_size; DWORD str_size;
WCHAR *ret; WCHAR *ret;
if (!(ret = malloc( (size * 2 + 1) * sizeof(WCHAR) ))) return NULL; RtlUTF8ToUnicodeN( NULL, 0, &str_size, data, size );
RtlUTF8ToUnicodeN( ret + size, size * sizeof(WCHAR), &str_size, data, size ); if (!(ret = malloc( str_size * 2 + sizeof(WCHAR) ))) return NULL;
return unicode_text_from_string( ret, ret + size, str_size / sizeof(WCHAR), ret_size ); RtlUTF8ToUnicodeN( ret + str_size / sizeof(WCHAR), str_size, &str_size, data, size );
return unicode_text_from_string( ret, ret + str_size / sizeof(WCHAR),
str_size / sizeof(WCHAR), ret_size );
} }
...@@ -1198,19 +1200,9 @@ static BOOL export_data( Display *display, Window win, Atom prop, Atom target, v ...@@ -1198,19 +1200,9 @@ static BOOL export_data( Display *display, Window win, Atom prop, Atom target, v
* *
* Convert CF_UNICODETEXT data to a string in the specified codepage. * Convert CF_UNICODETEXT data to a string in the specified codepage.
*/ */
static char *string_from_unicode_text( UINT codepage, const WCHAR *string, size_t string_size, size_t *size ) static void string_from_unicode_text( char *str, size_t len, DWORD *size )
{ {
UINT i, j; DWORD i, j;
char *str;
UINT lenW = string_size / sizeof(WCHAR);
DWORD len;
if (!string_size) return NULL;
len = WideCharToMultiByte( codepage, 0, string, lenW, NULL, 0, NULL, NULL );
if ((str = malloc( len )))
{
WideCharToMultiByte( codepage, 0, string, lenW, str, len, NULL, NULL);
/* remove carriage returns */ /* remove carriage returns */
for (i = j = 0; i < len; i++) for (i = j = 0; i < len; i++)
...@@ -1219,10 +1211,8 @@ static char *string_from_unicode_text( UINT codepage, const WCHAR *string, size_ ...@@ -1219,10 +1211,8 @@ static char *string_from_unicode_text( UINT codepage, const WCHAR *string, size_
str[j++] = str[i]; str[j++] = str[i];
} }
while (j && !str[j - 1]) j--; /* remove trailing nulls */ while (j && !str[j - 1]) j--; /* remove trailing nulls */
*size = j;
TRACE( "returning %s\n", debugstr_an( str, j )); TRACE( "returning %s\n", debugstr_an( str, j ));
} *size = j;
return str;
} }
...@@ -1233,10 +1223,14 @@ static char *string_from_unicode_text( UINT codepage, const WCHAR *string, size_ ...@@ -1233,10 +1223,14 @@ static char *string_from_unicode_text( UINT codepage, const WCHAR *string, size_
*/ */
static BOOL export_string( Display *display, Window win, Atom prop, Atom target, void *data, size_t size ) static BOOL export_string( Display *display, Window win, Atom prop, Atom target, void *data, size_t size )
{ {
char *text = string_from_unicode_text( 28591, data, size, &size ); DWORD len;
char *text;
if (!text) return FALSE; if (!(text = malloc( size ))) return FALSE;
put_property( display, win, prop, target, 8, text, size ); len = WideCharToMultiByte( 28591, 0, data, size / sizeof(WCHAR), text, size, NULL, NULL );
string_from_unicode_text( text, len, &len );
put_property( display, win, prop, target, 8, text, len );
free( text ); free( text );
return TRUE; return TRUE;
} }
...@@ -1250,10 +1244,14 @@ static BOOL export_string( Display *display, Window win, Atom prop, Atom target, ...@@ -1250,10 +1244,14 @@ static BOOL export_string( Display *display, Window win, Atom prop, Atom target,
static BOOL export_utf8_string( Display *display, Window win, Atom prop, Atom target, static BOOL export_utf8_string( Display *display, Window win, Atom prop, Atom target,
void *data, size_t size ) void *data, size_t size )
{ {
char *text = string_from_unicode_text( CP_UTF8, data, size, &size ); DWORD len;
char *text;
if (!text) return FALSE; if (!(text = malloc( size / sizeof(WCHAR) * 3 ))) return FALSE;
put_property( display, win, prop, target, 8, text, size ); RtlUnicodeToUTF8N( text, size / sizeof(WCHAR) * 3, &len, data, size );
string_from_unicode_text( text, len, &len );
put_property( display, win, prop, target, 8, text, len );
free( text ); free( text );
return TRUE; return TRUE;
} }
...@@ -1280,9 +1278,15 @@ static BOOL export_compound_text( Display *display, Window win, Atom prop, Atom ...@@ -1280,9 +1278,15 @@ static BOOL export_compound_text( Display *display, Window win, Atom prop, Atom
{ {
XTextProperty textprop; XTextProperty textprop;
XICCEncodingStyle style; XICCEncodingStyle style;
char *text = string_from_unicode_text( CP_UNIXCP, data, size, &size ); DWORD len;
char *text;
if (!(text = malloc( size / sizeof(WCHAR) * 3 ))) return FALSE;
len = WideCharToMultiByte( CP_UNIXCP, 0, data, size / sizeof(WCHAR),
text, size / sizeof(WCHAR) * 3, NULL, NULL );
string_from_unicode_text( text, len, &len );
if (!text) return FALSE;
if (target == x11drv_atom(COMPOUND_TEXT)) if (target == x11drv_atom(COMPOUND_TEXT))
style = XCompoundTextStyle; style = XCompoundTextStyle;
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment