Dan Hipschman : gdi32: Return the correct value from GetTextFace.

Alexandre Julliard julliard at winehq.org
Wed Jun 25 04:47:46 CDT 2008


Module: wine
Branch: master
Commit: 92c8cac214715633459227b2d47df61a18dc8d82
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=92c8cac214715633459227b2d47df61a18dc8d82

Author: Dan Hipschman <dsh at linux.ucla.edu>
Date:   Mon Jun 23 12:04:48 2008 -0700

gdi32: Return the correct value from GetTextFace.

---

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

diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index b43873a..20a009a 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -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 );
diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 95b260a..731b1c5 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -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)
diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index 4610536..868661c 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -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");
 




More information about the wine-cvs mailing list