From f73d7d07c8a4b7653848f66910e05dc8a9687511 Mon Sep 17 00:00:00 2001 From: Felix Nawothnig Date: Fri, 30 Mar 2007 14:58:32 +0200 Subject: [PATCH] gdi32: Properly handle negative font widths. --- dlls/gdi32/freetype.c | 2 +- dlls/gdi32/tests/font.c | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index f7b1220a2b1..c37247725ac 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 2f7a6a994a5..532037c46b3 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) {