Commit 65ff9cac authored by Alexandre Julliard's avatar Alexandre Julliard

win32u: Use the ntdll functions for codepage conversions.

parent 6eae7a24
...@@ -3221,7 +3221,6 @@ static UINT get_glyph_index_symbol( struct gdi_font *font, UINT glyph ) ...@@ -3221,7 +3221,6 @@ static UINT get_glyph_index_symbol( struct gdi_font *font, UINT glyph )
CPTABLEINFO *get_cptable( WORD cp ) CPTABLEINFO *get_cptable( WORD cp )
{ {
static CPTABLEINFO tables[100]; static CPTABLEINFO tables[100];
CPTABLEINFO *info;
unsigned int i; unsigned int i;
USHORT *ptr; USHORT *ptr;
SIZE_T size; SIZE_T size;
...@@ -3234,112 +3233,28 @@ CPTABLEINFO *get_cptable( WORD cp ) ...@@ -3234,112 +3233,28 @@ CPTABLEINFO *get_cptable( WORD cp )
ERR( "too many code pages\n" ); ERR( "too many code pages\n" );
return NULL; return NULL;
} }
RtlInitCodePageTable( ptr, &tables[i] );
info = &tables[i]; return &tables[i];
info->CodePage = ptr[1];
info->MaximumCharacterSize = ptr[2];
info->DefaultChar = ptr[3];
info->UniDefaultChar = ptr[4];
info->TransDefaultChar = ptr[5];
info->TransUniDefaultChar = ptr[6];
memcpy( info->LeadByte, ptr + 7, sizeof(info->LeadByte) );
ptr += ptr[0];
info->WideCharTable = ptr + ptr[0] + 1;
info->MultiByteTable = ++ptr;
ptr += 256;
if (*ptr++) ptr += 256; /* glyph table */
info->DBCSRanges = ptr;
if (*ptr) /* dbcs ranges */
{
info->DBCSCodePage = 1;
info->DBCSOffsets = ptr + 1;
}
else
{
info->DBCSCodePage = 0;
info->DBCSOffsets = NULL;
}
return info;
} }
DWORD win32u_wctomb( CPTABLEINFO *info, char *dst, DWORD dstlen, const WCHAR *src, DWORD srclen ) DWORD win32u_wctomb( CPTABLEINFO *info, char *dst, DWORD dstlen, const WCHAR *src, DWORD srclen )
{ {
DWORD i, ret; DWORD ret;
if (!info && !(info = get_cptable( get_acp() ))) return 0; if (!info && !(info = get_cptable( get_acp() ))) return 0;
srclen /= sizeof(WCHAR); RtlUnicodeToCustomCPN( info, dst, dstlen, &ret, src, srclen );
if (info->DBCSCodePage)
{
WCHAR *uni2cp = info->WideCharTable;
for (i = dstlen; srclen && i; i--, srclen--, src++)
{
if (uni2cp[*src] & 0xff00)
{
if (i == 1) break; /* do not output a partial char */
i--;
*dst++ = uni2cp[*src] >> 8;
}
*dst++ = (char)uni2cp[*src];
}
ret = dstlen - i;
}
else
{
char *uni2cp = info->WideCharTable;
ret = min( srclen, dstlen );
for (i = 0; i < ret; i++) dst[i] = uni2cp[src[i]];
}
return ret; return ret;
} }
DWORD win32u_mbtowc( CPTABLEINFO *info, WCHAR *dst, DWORD dstlen, const char *src, DWORD srclen ) DWORD win32u_mbtowc( CPTABLEINFO *info, WCHAR *dst, DWORD dstlen, const char *src, DWORD srclen )
{ {
DWORD i, ret; DWORD ret;
if (!info && !(info = get_cptable( get_acp() ))) return 0; if (!info && !(info = get_cptable( get_acp() ))) return 0;
if (!dst) RtlCustomCPToUnicodeN( info, dst, dstlen, &ret, src, srclen );
{ return ret;
/* only compute length */
if (info->DBCSOffsets)
{
for (ret = 0; srclen--; src++, ret++)
{
if (!info->DBCSOffsets[(unsigned char)*src]) continue;
if (!srclen--) break;
src++;
}
}
else ret = srclen;
return ret * sizeof(WCHAR);
}
dstlen /= sizeof(WCHAR);
if (info->DBCSOffsets)
{
for (i = dstlen; srclen && i; i--, srclen--, src++, dst++)
{
USHORT off = info->DBCSOffsets[(unsigned char)*src];
if (off && srclen > 1)
{
src++;
srclen--;
*dst = info->DBCSOffsets[off + (unsigned char)*src];
}
else *dst = info->MultiByteTable[(unsigned char)*src];
}
ret = dstlen - i;
}
else
{
ret = min( srclen, dstlen );
for (i = 0; i < ret; i++) dst[i] = info->MultiByteTable[(unsigned char)src[i]];
}
return ret * sizeof(WCHAR);
} }
static BOOL wc_to_index( UINT cp, WCHAR wc, unsigned char *dst, BOOL allow_default ) static BOOL wc_to_index( UINT cp, WCHAR wc, unsigned char *dst, BOOL allow_default )
......
...@@ -592,9 +592,8 @@ static inline WCHAR *win32u_wcsdup( const WCHAR *str ) ...@@ -592,9 +592,8 @@ static inline WCHAR *win32u_wcsdup( const WCHAR *str )
static inline WCHAR *towstr( const char *str ) static inline WCHAR *towstr( const char *str )
{ {
DWORD len = strlen( str ) + 1; DWORD len = strlen( str ) + 1;
DWORD size = win32u_mbtowc( NULL, NULL, 0, str, len ); WCHAR *ret = malloc( len * sizeof(WCHAR) );
WCHAR *ret = malloc( size ); if (ret) win32u_mbtowc( NULL, ret, len * sizeof(WCHAR), str, len );
if (ret) win32u_mbtowc( NULL, ret, size, str, len );
return ret; return ret;
} }
......
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