From e2905ea47878c285aaf70daf506bffb73e131fae Mon Sep 17 00:00:00 2001 From: Hidenori Takeshima Date: Sun, 26 Mar 2000 14:43:22 +0000 Subject: [PATCH] Fixes for i18n. --- loader/resource.c | 51 ++++++++++++++++++++++++++++++++++++++------------- objects/enhmetafile.c | 10 ++++++---- objects/font.c | 11 ++++++++--- objects/text.c | 37 ++++++++++++++++++++++++++----------- win32/console.c | 12 +++++++++--- 5 files changed, 87 insertions(+), 34 deletions(-) diff --git a/loader/resource.c b/loader/resource.c index 17090080f5f..472be198284 100644 --- a/loader/resource.c +++ b/loader/resource.c @@ -913,22 +913,47 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id, INT WINAPI LoadStringA( HINSTANCE instance, UINT resource_id, LPSTR buffer, INT buflen ) { - INT retval; - LPWSTR buffer2 = NULL; - if (buffer && buflen) - buffer2 = HeapAlloc( GetProcessHeap(), 0, buflen * 2 ); - retval = LoadStringW(instance,resource_id,buffer2,buflen); - - if (buffer2) + INT retval; + INT wbuflen; + INT abuflen; + LPWSTR wbuf = NULL; + LPSTR abuf = NULL; + + if ( buffer != NULL && buflen > 0 ) + *buffer = 0; + + wbuflen = LoadStringW(instance,resource_id,NULL,0); + if ( !wbuflen ) + return 0; + wbuflen ++; + + retval = 0; + wbuf = HeapAlloc( GetProcessHeap(), 0, wbuflen * sizeof(WCHAR) ); + wbuflen = LoadStringW(instance,resource_id,wbuf,wbuflen); + if ( wbuflen > 0 ) { - if (retval) { - lstrcpynWtoA( buffer, buffer2, buflen ); - retval = lstrlenA( buffer ); + abuflen = WideCharToMultiByte(CP_ACP,0,wbuf,wbuflen,NULL,0,NULL,NULL); + if ( abuflen > 0 ) + { + if ( buffer == NULL || buflen == 0 ) + retval = abuflen; + else + { + abuf = HeapAlloc( GetProcessHeap(), 0, abuflen * sizeof(CHAR) ); + abuflen = WideCharToMultiByte(CP_ACP,0,wbuf,wbuflen,abuf,abuflen,NULL,NULL); + if ( abuflen > 0 ) + { + abuflen = min(abuflen,buflen - 1); + memcpy( buffer, abuf, abuflen ); + buffer[abuflen] = 0; + retval = abuflen; + } + HeapFree( GetProcessHeap(), 0, abuf ); + } } - else - *buffer = 0; - HeapFree( GetProcessHeap(), 0, buffer2 ); } + HeapFree( GetProcessHeap(), 0, wbuf ); + return retval; } diff --git a/objects/enhmetafile.c b/objects/enhmetafile.c index 7cca7968c89..a2e4965884b 100644 --- a/objects/enhmetafile.c +++ b/objects/enhmetafile.c @@ -193,7 +193,7 @@ UINT WINAPI GetEnhMetaFileDescriptionA( ) { LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf); - INT first; + INT first, first_A; if(!emh) return FALSE; if(emh->nDescription == 0 || emh->offDescription == 0) { @@ -208,12 +208,14 @@ UINT WINAPI GetEnhMetaFileDescriptionA( first = lstrlenW( (WCHAR *) ((char *) emh + emh->offDescription)); lstrcpynWtoA(buf, (WCHAR *) ((char *) emh + emh->offDescription), size); - buf += first + 1; + first_A = lstrlenA( buf ); + buf += first_A + 1; lstrcpynWtoA(buf, (WCHAR *) ((char *) emh + emh->offDescription+2*(first+1)), - size - first - 1); + size - first_A - 1); /* i18n ready */ + first_A += lstrlenA(buf) + 1; EMF_ReleaseEnhMetaHeader(hmf); - return min(size, emh->nDescription); + return min(size, first_A); } /***************************************************************************** diff --git a/objects/font.c b/objects/font.c index 27df7f40483..d4bbce7dff1 100644 --- a/objects/font.c +++ b/objects/font.c @@ -15,6 +15,7 @@ #include "debugtools.h" #include "winerror.h" #include "dc.h" +#include "winnls.h" DEFAULT_DEBUG_CHANNEL(font) DECLARE_DEBUG_CHANNEL(gdi) @@ -869,15 +870,19 @@ BOOL WINAPI GetTextExtentPoint32A( HDC hdc, LPCSTR str, INT count, { LPWSTR p; BOOL ret; + UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */ + UINT wlen; /* str may not be 0 terminated so we can't use HEAP_strdupWtoA. * We allocate one more than we need so that lstrcpynWtoA can write a * trailing 0 if it wants. */ - p = HeapAlloc( GetProcessHeap(), 0, (count+1) * sizeof(WCHAR) ); - lstrcpynAtoW(p, str, count+1); - ret = GetTextExtentPoint32W( hdc, p, count, size ); + wlen = MultiByteToWideChar(codepage,0,str,count,NULL,0); + p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) ); + wlen = MultiByteToWideChar(codepage,0,str,count,p,wlen); + + ret = GetTextExtentPoint32W( hdc, p, wlen, size ); HeapFree( GetProcessHeap(), 0, p ); return ret; } diff --git a/objects/text.c b/objects/text.c index 1aa4428db96..fed275200cc 100644 --- a/objects/text.c +++ b/objects/text.c @@ -18,6 +18,7 @@ #include "heap.h" #include "debugtools.h" #include "cache.h" +#include "winnls.h" DEFAULT_DEBUG_CHANNEL(text); @@ -381,12 +382,16 @@ BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags, const RECT *lprect, LPCSTR str, UINT count, const INT *lpDx ) { - /* str need not be \0 terminated but lstrcpynAtoW adds \0 so we allocate one - more byte */ - LPWSTR p = HeapAlloc( GetProcessHeap(), 0, (count+1) * sizeof(WCHAR) ); + LPWSTR p; INT ret; - lstrcpynAtoW( p, str, count+1 ); - ret = ExtTextOutW( hdc, x, y, flags, lprect, p, count, lpDx ); + UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */ + UINT wlen; + + wlen = MultiByteToWideChar(codepage,0,str,count,NULL,0); + p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) ); + wlen = MultiByteToWideChar(codepage,0,str,count,p,wlen); + + ret = ExtTextOutW( hdc, x, y, flags, lprect, p, wlen, lpDx ); HeapFree( GetProcessHeap(), 0, p ); return ret; } @@ -679,9 +684,14 @@ LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str, const INT *lpTabPos, INT nTabOrg ) { LONG ret; - LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 ); - lstrcpynWtoA( p, str, count + 1 ); - ret = TabbedTextOutA( hdc, x, y, p, count, cTabStops, + LPSTR p; + INT acount; + UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */ + + acount = WideCharToMultiByte(codepage,0,str,count,NULL,0,NULL,NULL); + p = HEAP_xalloc( GetProcessHeap(), 0, acount ); + acount = WideCharToMultiByte(codepage,0,str,count,p,acount,NULL,NULL); + ret = TabbedTextOutA( hdc, x, y, p, acount, cTabStops, lpTabPos, nTabOrg ); HeapFree( GetProcessHeap(), 0, p ); return ret; @@ -721,9 +731,14 @@ DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count, INT cTabStops, const INT *lpTabPos ) { LONG ret; - LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 ); - lstrcpynWtoA( p, lpstr, count + 1 ); - ret = GetTabbedTextExtentA( hdc, p, count, cTabStops, lpTabPos ); + LPSTR p; + INT acount; + UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */ + + acount = WideCharToMultiByte(codepage,0,lpstr,count,NULL,0,NULL,NULL); + p = HEAP_xalloc( GetProcessHeap(), 0, acount ); + acount = WideCharToMultiByte(codepage,0,lpstr,count,p,acount,NULL,NULL); + ret = GetTabbedTextExtentA( hdc, p, acount, cTabStops, lpTabPos ); HeapFree( GetProcessHeap(), 0, p ); return ret; } diff --git a/win32/console.c b/win32/console.c index baef517bf5c..ac0d66fffe8 100644 --- a/win32/console.c +++ b/win32/console.c @@ -50,6 +50,7 @@ #include "heap.h" #include "server.h" #include "debugtools.h" +#include "winnls.h" DEFAULT_DEBUG_CHANNEL(console) @@ -847,13 +848,18 @@ BOOL WINAPI WriteConsoleW( HANDLE hConsoleOutput, LPVOID lpReserved ) { BOOL ret; - LPSTR xstring=HeapAlloc( GetProcessHeap(), 0, nNumberOfCharsToWrite ); + LPSTR xstring; + DWORD n; - lstrcpynWtoA( xstring, lpBuffer,nNumberOfCharsToWrite); + n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,NULL,0,NULL,NULL); + xstring=HeapAlloc( GetProcessHeap(), 0, n ); + + n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,xstring,n,NULL,NULL); /* FIXME: should I check if this is a console handle? */ - ret= WriteFile(hConsoleOutput, xstring, nNumberOfCharsToWrite, + ret= WriteFile(hConsoleOutput, xstring, n, lpNumberOfCharsWritten, NULL); + /* FIXME: lpNumberOfCharsWritten should be converted to numofchars in UNICODE */ HeapFree( GetProcessHeap(), 0, xstring ); return ret; } -- 2.11.4.GIT