Alexandre Julliard : gdi32: Fix text justification to properly handle logical coordinates.

Alexandre Julliard julliard at winehq.org
Tue Dec 11 14:41:15 CST 2012


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Dec 11 16:52:43 2012 +0100

gdi32: Fix text justification to properly handle logical coordinates.

---

 dlls/gdi32/font.c       |   13 ++++++-------
 dlls/gdi32/tests/dc.c   |   13 +++++++++++++
 dlls/gdi32/tests/font.c |   40 ++++++++++++++++++++++++----------------
 3 files changed, 43 insertions(+), 23 deletions(-)

diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 3d75682..34520f5 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -1189,7 +1189,7 @@ BOOL WINAPI GetTextExtentExPointW( HDC hdc, LPCWSTR str, INT count,
     /* Perform device size to world size transformations.  */
     if (ret)
     {
-	INT extra      = dc->charExtra,
+	INT extra = abs(INTERNAL_XWSTODS(dc, dc->charExtra)),
         breakExtra = dc->breakExtra,
         breakRem   = dc->breakRem,
         i;
@@ -1198,7 +1198,6 @@ BOOL WINAPI GetTextExtentExPointW( HDC hdc, LPCWSTR str, INT count,
 	{
 	    for (i = 0; i < count; ++i)
 	    {
-		dxs[i] = abs(INTERNAL_XDSTOWS(dc, dxs[i]));
 		dxs[i] += (i+1) * extra;
                 if (count > 1 && (breakExtra || breakRem) && str[i] == tm.tmBreakChar)
                 {
@@ -1209,15 +1208,12 @@ BOOL WINAPI GetTextExtentExPointW( HDC hdc, LPCWSTR str, INT count,
                         dxs[i]++;
                     }
                 }
+		dxs[i] = abs(INTERNAL_XDSTOWS(dc, dxs[i]));
 		if (dxs[i] <= maxExt)
 		    ++nFit;
 	    }
-            breakRem = dc->breakRem;
 	}
-	size->cx = abs(INTERNAL_XDSTOWS(dc, size->cx));
-	size->cy = abs(INTERNAL_YDSTOWS(dc, size->cy));
-
-        if (!dxs && count > 1 && (breakExtra || breakRem))
+        else if (count > 1 && (breakExtra || breakRem))
         {
             for (i = 0; i < count; i++)
             {
@@ -1232,6 +1228,9 @@ BOOL WINAPI GetTextExtentExPointW( HDC hdc, LPCWSTR str, INT count,
                 }
             }
         }
+        size->cx += count * extra;
+	size->cx = abs(INTERNAL_XDSTOWS(dc, size->cx));
+	size->cy = abs(INTERNAL_YDSTOWS(dc, size->cy));
     }
 
     if (lpnFit)
diff --git a/dlls/gdi32/tests/dc.c b/dlls/gdi32/tests/dc.c
index 8baacc2..802d82a 100644
--- a/dlls/gdi32/tests/dc.c
+++ b/dlls/gdi32/tests/dc.c
@@ -58,6 +58,7 @@ static void test_dc_values(void)
 {
     HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
     COLORREF color;
+    int extra;
 
     ok( hdc != NULL, "CreateDC failed\n" );
     color = SetBkColor( hdc, 0x12345678 );
@@ -86,6 +87,18 @@ static void test_dc_values(void)
     color = GetTextColor( hdc );
     ok( color == 0, "wrong color %08x\n", color );
 
+    extra = GetTextCharacterExtra( hdc );
+    ok( extra == 0, "initial extra %d\n", extra );
+    SetTextCharacterExtra( hdc, 123 );
+    extra = GetTextCharacterExtra( hdc );
+    ok( extra == 123, "initial extra %d\n", extra );
+    SetMapMode( hdc, MM_LOMETRIC );
+    extra = GetTextCharacterExtra( hdc );
+    ok( extra == 123, "initial extra %d\n", extra );
+    SetMapMode( hdc, MM_TEXT );
+    extra = GetTextCharacterExtra( hdc );
+    ok( extra == 123, "initial extra %d\n", extra );
+
     DeleteDC( hdc );
 }
 
diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index 1064ce2..8508d70 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -1753,18 +1753,17 @@ static void testJustification(HDC hdc, PSTR str, RECT *clientArea)
 {
     INT         y,
                 breakCount,
-                justifiedWidth = 0, /* to test GetTextExtentExPointW() */
                 areaWidth = clientArea->right - clientArea->left,
                 nErrors = 0, e;
-    BOOL        lastExtent = FALSE;
     PSTR        pFirstChar, pLastChar;
     SIZE        size;
     TEXTMETRICA tm;
     struct err
     {
-        char extent[100];
+        char *start;
+        int  len;
         int  GetTextExtentExPointWWidth;
-    } error[10];
+    } error[20];
 
     GetTextMetricsA(hdc, &tm);
     y = clientArea->top;
@@ -1803,18 +1802,16 @@ static void testJustification(HDC hdc, PSTR str, RECT *clientArea)
         {
             SetTextJustification(hdc, areaWidth - size.cx, breakCount);
             GetTextExtentPoint32(hdc, pFirstChar, pLastChar - pFirstChar, &size);
-            justifiedWidth = size.cx;
+            if (size.cx != areaWidth && nErrors < sizeof(error)/sizeof(error[0]) - 1)
+            {
+                error[nErrors].start = pFirstChar;
+                error[nErrors].len = pLastChar - pFirstChar;
+                error[nErrors].GetTextExtentExPointWWidth = size.cx;
+                nErrors++;
+            }
         }
-        else lastExtent = TRUE;
 
-        /* catch errors and report them */
-        if (!lastExtent && (justifiedWidth != areaWidth))
-        {
-            memset(error[nErrors].extent, 0, 100);
-            memcpy(error[nErrors].extent, pFirstChar, pLastChar - pFirstChar);
-            error[nErrors].GetTextExtentExPointWWidth = justifiedWidth;
-            nErrors++;
-        }
+        trace( "%u %.*s\n", size.cx, (int)(pLastChar - pFirstChar), pFirstChar);
 
         y += size.cy;
         str = pLastChar;
@@ -1825,8 +1822,8 @@ static void testJustification(HDC hdc, PSTR str, RECT *clientArea)
         /* The width returned by GetTextExtentPoint32() is exactly the same
            returned by GetTextExtentExPointW() - see dlls/gdi32/font.c */
         ok(error[e].GetTextExtentExPointWWidth == areaWidth,
-            "GetTextExtentPointW() for \"%s\" should have returned a width of %d, not %d.\n",
-            error[e].extent, areaWidth, error[e].GetTextExtentExPointWWidth);
+            "GetTextExtentPointW() for \"%.*s\" should have returned a width of %d, not %d.\n",
+           error[e].len, error[e].start, areaWidth, error[e].GetTextExtentExPointWWidth);
     }
 }
 
@@ -1862,6 +1859,17 @@ static void test_SetTextJustification(void)
 
     testJustification(hdc, testText, &clientArea);
 
+    SetMapMode( hdc, MM_ANISOTROPIC );
+    SetWindowExtEx( hdc, 2, 2, NULL );
+    GetClientRect( hwnd, &clientArea );
+    DPtoLP( hdc, (POINT *)&clientArea, 2 );
+    testJustification(hdc, testText, &clientArea);
+
+    SetViewportExtEx( hdc, 3, 3, NULL );
+    GetClientRect( hwnd, &clientArea );
+    DPtoLP( hdc, (POINT *)&clientArea, 2 );
+    testJustification(hdc, testText, &clientArea);
+
     DeleteObject(hfont);
     ReleaseDC(hwnd, hdc);
     DestroyWindow(hwnd);




More information about the wine-cvs mailing list