[3/3] gdi32: Return the correct value from GetTextFace.

Dan Hipschman dsh at linux.ucla.edu
Thu Jun 19 18:00:53 CDT 2008


---
 dlls/gdi32/font.c       |   24 +++++++++++++-----------
 dlls/gdi32/freetype.c   |    5 +++--
 dlls/gdi32/tests/font.c |    5 -----
 3 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 1bfd97a..08d06b3 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -794,20 +794,21 @@ BOOL WINAPI SetTextJustification( HDC hdc, INT extra, INT breaks )
  */
 INT WINAPI GetTextFaceA( HDC hdc, INT count, LPSTR name )
 {
-    INT res = GetTextFaceW(hdc, 0, NULL);
-    LPWSTR nameW = HeapAlloc( GetProcessHeap(), 0, res * 2 );
-    GetTextFaceW( hdc, res, nameW );
-
     if (name)
     {
-        if (count && !WideCharToMultiByte( CP_ACP, 0, nameW, -1, name, count, NULL, NULL))
+        LPWSTR nameW = HeapAlloc( GetProcessHeap(), 0, count * sizeof nameW[0] );
+        INT res = GetTextFaceW( hdc, count, nameW );
+        if (count && res)
+        {
+            WideCharToMultiByte( CP_ACP, 0, nameW, -1, name, count, NULL, NULL);
             name[count-1] = 0;
-        res = strlen(name);
+        }
+        HeapFree( GetProcessHeap(), 0, nameW );
+        /* GetTextFaceA does NOT include the nul byte in the return count.  */
+        return res ? res - 1 : 0;
     }
     else
-        res = WideCharToMultiByte( CP_ACP, 0, nameW, -1, NULL, 0, NULL, NULL);
-    HeapFree( GetProcessHeap(), 0, nameW );
-    return res;
+        return GetTextFaceW(hdc, 0, NULL);
 }
 
 /***********************************************************************
@@ -825,12 +826,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 );
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 8bcb487..ec64503 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -5365,11 +5365,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)
diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index 968be53..b67fabb 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -1960,7 +1960,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]);
 
@@ -1988,26 +1987,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");
 



More information about the wine-patches mailing list