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,
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);
INT retval;
INT wbuflen;
INT abuflen;
LPWSTR wbuf = NULL;
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) {
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;
}

View File

@ -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);
}
/*****************************************************************************

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}