Fixes for i18n.

This commit is contained in:
Hidenori Takeshima 2000-03-26 14:43:22 +00:00 committed by Alexandre Julliard
parent 9505c1c8da
commit e2905ea478
5 changed files with 86 additions and 33 deletions

View file

@ -913,22 +913,47 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
INT WINAPI LoadStringA( HINSTANCE instance, UINT resource_id, INT WINAPI LoadStringA( HINSTANCE instance, UINT resource_id,
LPSTR buffer, INT buflen ) LPSTR buffer, INT buflen )
{ {
INT retval; INT retval;
LPWSTR buffer2 = NULL; INT wbuflen;
if (buffer && buflen) INT abuflen;
buffer2 = HeapAlloc( GetProcessHeap(), 0, buflen * 2 ); LPWSTR wbuf = NULL;
retval = LoadStringW(instance,resource_id,buffer2,buflen); LPSTR abuf = NULL;
if (buffer2) 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) { abuflen = WideCharToMultiByte(CP_ACP,0,wbuf,wbuflen,NULL,0,NULL,NULL);
lstrcpynWtoA( buffer, buffer2, buflen ); if ( abuflen > 0 )
retval = lstrlenA( buffer ); {
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; return retval;
} }

View file

@ -193,7 +193,7 @@ UINT WINAPI GetEnhMetaFileDescriptionA(
) )
{ {
LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf); LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
INT first; INT first, first_A;
if(!emh) return FALSE; if(!emh) return FALSE;
if(emh->nDescription == 0 || emh->offDescription == 0) { if(emh->nDescription == 0 || emh->offDescription == 0) {
@ -208,12 +208,14 @@ UINT WINAPI GetEnhMetaFileDescriptionA(
first = lstrlenW( (WCHAR *) ((char *) emh + emh->offDescription)); first = lstrlenW( (WCHAR *) ((char *) emh + emh->offDescription));
lstrcpynWtoA(buf, (WCHAR *) ((char *) emh + emh->offDescription), size); 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)), 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); EMF_ReleaseEnhMetaHeader(hmf);
return min(size, emh->nDescription); return min(size, first_A);
} }
/***************************************************************************** /*****************************************************************************

View file

@ -15,6 +15,7 @@
#include "debugtools.h" #include "debugtools.h"
#include "winerror.h" #include "winerror.h"
#include "dc.h" #include "dc.h"
#include "winnls.h"
DEFAULT_DEBUG_CHANNEL(font) DEFAULT_DEBUG_CHANNEL(font)
DECLARE_DEBUG_CHANNEL(gdi) DECLARE_DEBUG_CHANNEL(gdi)
@ -869,15 +870,19 @@ BOOL WINAPI GetTextExtentPoint32A( HDC hdc, LPCSTR str, INT count,
{ {
LPWSTR p; LPWSTR p;
BOOL ret; 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. /* 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 * We allocate one more than we need so that lstrcpynWtoA can write a
* trailing 0 if it wants. * trailing 0 if it wants.
*/ */
p = HeapAlloc( GetProcessHeap(), 0, (count+1) * sizeof(WCHAR) ); wlen = MultiByteToWideChar(codepage,0,str,count,NULL,0);
lstrcpynAtoW(p, str, count+1); p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) );
ret = GetTextExtentPoint32W( hdc, p, count, size ); wlen = MultiByteToWideChar(codepage,0,str,count,p,wlen);
ret = GetTextExtentPoint32W( hdc, p, wlen, size );
HeapFree( GetProcessHeap(), 0, p ); HeapFree( GetProcessHeap(), 0, p );
return ret; return ret;
} }

View file

@ -18,6 +18,7 @@
#include "heap.h" #include "heap.h"
#include "debugtools.h" #include "debugtools.h"
#include "cache.h" #include "cache.h"
#include "winnls.h"
DEFAULT_DEBUG_CHANNEL(text); 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 RECT *lprect, LPCSTR str, UINT count,
const INT *lpDx ) const INT *lpDx )
{ {
/* str need not be \0 terminated but lstrcpynAtoW adds \0 so we allocate one LPWSTR p;
more byte */
LPWSTR p = HeapAlloc( GetProcessHeap(), 0, (count+1) * sizeof(WCHAR) );
INT ret; INT ret;
lstrcpynAtoW( p, str, count+1 ); UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
ret = ExtTextOutW( hdc, x, y, flags, lprect, p, count, lpDx ); 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 ); HeapFree( GetProcessHeap(), 0, p );
return ret; return ret;
} }
@ -679,9 +684,14 @@ LONG WINAPI TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR str,
const INT *lpTabPos, INT nTabOrg ) const INT *lpTabPos, INT nTabOrg )
{ {
LONG ret; LONG ret;
LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 ); LPSTR p;
lstrcpynWtoA( p, str, count + 1 ); INT acount;
ret = TabbedTextOutA( hdc, x, y, p, count, cTabStops, 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 ); lpTabPos, nTabOrg );
HeapFree( GetProcessHeap(), 0, p ); HeapFree( GetProcessHeap(), 0, p );
return ret; return ret;
@ -721,9 +731,14 @@ DWORD WINAPI GetTabbedTextExtentW( HDC hdc, LPCWSTR lpstr, INT count,
INT cTabStops, const INT *lpTabPos ) INT cTabStops, const INT *lpTabPos )
{ {
LONG ret; LONG ret;
LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 ); LPSTR p;
lstrcpynWtoA( p, lpstr, count + 1 ); INT acount;
ret = GetTabbedTextExtentA( hdc, p, count, cTabStops, lpTabPos ); 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 ); HeapFree( GetProcessHeap(), 0, p );
return ret; return ret;
} }

View file

@ -50,6 +50,7 @@
#include "heap.h" #include "heap.h"
#include "server.h" #include "server.h"
#include "debugtools.h" #include "debugtools.h"
#include "winnls.h"
DEFAULT_DEBUG_CHANNEL(console) DEFAULT_DEBUG_CHANNEL(console)
@ -847,13 +848,18 @@ BOOL WINAPI WriteConsoleW( HANDLE hConsoleOutput,
LPVOID lpReserved ) LPVOID lpReserved )
{ {
BOOL ret; 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? */ /* FIXME: should I check if this is a console handle? */
ret= WriteFile(hConsoleOutput, xstring, nNumberOfCharsToWrite, ret= WriteFile(hConsoleOutput, xstring, n,
lpNumberOfCharsWritten, NULL); lpNumberOfCharsWritten, NULL);
/* FIXME: lpNumberOfCharsWritten should be converted to numofchars in UNICODE */
HeapFree( GetProcessHeap(), 0, xstring ); HeapFree( GetProcessHeap(), 0, xstring );
return ret; return ret;
} }