gdi32: Return the correct value from GetTextFace.

This commit is contained in:
Dan Hipschman 2008-06-23 12:04:48 -07:00 committed by Alexandre Julliard
parent 88a9ca7c41
commit 92c8cac214
3 changed files with 16 additions and 11 deletions

View file

@ -800,9 +800,17 @@ INT WINAPI GetTextFaceA( HDC hdc, INT count, LPSTR name )
if (name)
{
if (count && !WideCharToMultiByte( CP_ACP, 0, nameW, -1, name, count, NULL, NULL))
if (count)
{
res = WideCharToMultiByte(CP_ACP, 0, nameW, -1, name, count, NULL, NULL);
if (res == 0)
res = count;
name[count-1] = 0;
res = strlen(name);
/* GetTextFaceA does NOT include the nul byte in the return count. */
res--;
}
else
res = 0;
}
else
res = WideCharToMultiByte( CP_ACP, 0, nameW, -1, NULL, 0, NULL, NULL);
@ -825,12 +833,13 @@ INT WINAPI GetTextFaceW( HDC hdc, INT count, LPWSTR name )
ret = WineEngGetTextFace(dc->gdiFont, count, name);
else if ((font = (FONTOBJ *) GDI_GetObjPtr( dc->hFont, FONT_MAGIC )))
{
INT n = strlenW(font->logfont.lfFaceName) + 1;
if (name)
{
lstrcpynW( name, font->logfont.lfFaceName, count );
ret = strlenW(name);
ret = min(count, n);
}
else ret = strlenW(font->logfont.lfFaceName) + 1;
else ret = n;
GDI_ReleaseObj( dc->hFont );
}
release_dc_ptr( dc );

View file

@ -5569,11 +5569,12 @@ DWORD WineEngGetFontData(GdiFont *font, DWORD table, DWORD offset, LPVOID buf,
*/
INT WineEngGetTextFace(GdiFont *font, INT count, LPWSTR str)
{
INT n = strlenW(font->name) + 1;
if(str) {
lstrcpynW(str, font->name, count);
return strlenW(font->name);
return min(count, n);
} else
return strlenW(font->name) + 1;
return n;
}
UINT WineEngGetTextCharsetInfo(GdiFont *font, LPFONTSIGNATURE fs, DWORD flags)

View file

@ -2261,7 +2261,6 @@ static void test_GetTextFace(void)
/* Play with the count arg. */
bufA[0] = 'x';
n = GetTextFaceA(dc, 0, bufA);
todo_wine
ok(n == 0, "GetTextFaceA returned %d\n", n);
ok(bufA[0] == 'x', "GetTextFaceA buf[0] == %d\n", bufA[0]);
@ -2289,26 +2288,22 @@ static void test_GetTextFace(void)
dc = GetDC(NULL);
g = SelectObject(dc, f);
n = GetTextFaceW(dc, sizeof bufW / sizeof bufW[0], bufW);
todo_wine
ok(n == sizeof faceW / sizeof faceW[0], "GetTextFaceW returned %d\n", n);
ok(lstrcmpW(faceW, bufW) == 0, "GetTextFaceW\n");
/* Play with the count arg. */
bufW[0] = 'x';
n = GetTextFaceW(dc, 0, bufW);
todo_wine
ok(n == 0, "GetTextFaceW returned %d\n", n);
ok(bufW[0] == 'x', "GetTextFaceW buf[0] == %d\n", bufW[0]);
bufW[0] = 'x';
n = GetTextFaceW(dc, 1, bufW);
todo_wine
ok(n == 1, "GetTextFaceW returned %d\n", n);
ok(bufW[0] == '\0', "GetTextFaceW buf[0] == %d\n", bufW[0]);
bufW[0] = 'x'; bufW[1] = 'y';
n = GetTextFaceW(dc, 2, bufW);
todo_wine
ok(n == 2, "GetTextFaceW returned %d\n", n);
ok(bufW[0] == faceW[0] && bufW[1] == '\0', "GetTextFaceW didn't copy\n");