Felix Nawothnig : gdi32: Properly handle negative font widths.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Apr 2 06:22:55 CDT 2007


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

Author: Felix Nawothnig <flexo at holycrap.org>
Date:   Fri Mar 30 14:58:32 2007 +0200

gdi32: Properly handle negative font widths.

---

 dlls/gdi32/freetype.c   |    2 +-
 dlls/gdi32/tests/font.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index f7b1220..c372477 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -2953,7 +2953,7 @@ found:
 
     TRACE("caching: gdiFont=%p  hfont=%p\n", ret, hfont);
 
-    ret->aveWidth = FT_IS_SCALABLE(ret->ft_face) ? lf.lfWidth : 0;
+    ret->aveWidth = FT_IS_SCALABLE(ret->ft_face) ? abs(lf.lfWidth) : 0;
     list_add_head(&gdi_font_list, &ret->entry);
     return ret;
 }
diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index 2f7a6a9..532037c 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -30,6 +30,8 @@
 
 #include "wine/test.h"
 
+#define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
+
 LONG  (WINAPI *pGdiGetCharDimensions)(HDC hdc, LPTEXTMETRICW lptm, LONG *height);
 BOOL  (WINAPI *pGetCharABCWidthsW)(HDC hdc, UINT first, UINT last, LPABC abc);
 DWORD (WINAPI *pGetFontUnicodeRanges)(HDC hdc, LPGLYPHSET lpgs);
@@ -1481,6 +1483,46 @@ static void test_text_metrics(const LOGFONTA *lf)
 
     hfont_old = SelectObject(hdc, hfont);
 
+    if(lf->lfWidth > 0) {
+        HFONT hfont2;
+        GLYPHMETRICS gm1, gm2;
+        LOGFONTA lf2 = *lf;
+        MAT2 mat2 = { {0,1}, {0,0}, {0,0}, {0,1} };
+
+        /* negative widths are handled just as positive ones */
+        lf2.lfWidth *= -1;
+
+        SetLastError(0xdeadbeef);
+        hfont2 = CreateFontIndirectA(&lf2);
+        ok(hfont != 0, "CreateFontIndirect error %u\n", GetLastError());
+        SelectObject(hdc, hfont2);
+
+        memset(&gm1, 0xaa, sizeof(gm1));
+        SetLastError(0xdeadbeef);
+        ret = GetGlyphOutlineA(hdc, 'x', GGO_METRICS, &gm1, 0, NULL, &mat2);
+        ok(ret != GDI_ERROR, "GetGlyphOutline error 0x%x\n", GetLastError());
+
+        SelectObject(hdc, hfont);
+        DeleteObject(hfont2);
+
+        memset(&gm2, 0xbb, sizeof(gm2));
+        SetLastError(0xdeadbeef);
+        ret = GetGlyphOutlineA(hdc, 'x', GGO_METRICS, &gm2, 0, NULL, &mat2);
+        ok(ret != GDI_ERROR, "GetGlyphOutline error 0x%x\n", GetLastError());
+
+        ok(gm1.gmBlackBoxX == gm2.gmBlackBoxX &&
+           gm1.gmBlackBoxY == gm2.gmBlackBoxY &&
+           gm1.gmptGlyphOrigin.x == gm2.gmptGlyphOrigin.x &&
+           gm1.gmptGlyphOrigin.y == gm2.gmptGlyphOrigin.y &&
+           gm1.gmCellIncX == gm2.gmCellIncX &&
+           gm1.gmCellIncY == gm2.gmCellIncY,
+           "gm1=%d,%d,%d,%d,%d,%d gm2=%d,%d,%d,%d,%d,%d\n",
+           gm1.gmBlackBoxX, gm1.gmBlackBoxY, gm1.gmptGlyphOrigin.x,
+           gm1.gmptGlyphOrigin.y, gm1.gmCellIncX, gm1.gmCellIncY,
+           gm2.gmBlackBoxX, gm2.gmBlackBoxY, gm2.gmptGlyphOrigin.x,
+           gm2.gmptGlyphOrigin.y, gm2.gmCellIncX, gm2.gmCellIncY);
+    }
+
     size = GetFontData(hdc, MS_OS2_TAG, 0, NULL, 0);
     if (size == GDI_ERROR)
     {




More information about the wine-cvs mailing list