From a5d288f08c08dc19d217093fdf8622605c92a4e0 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Tue, 13 May 2008 22:10:05 +0900 Subject: [PATCH] gdi32: Add more font substitution tests, make them pass under Wine. --- dlls/gdi32/freetype.c | 5 ++- dlls/gdi32/tests/font.c | 86 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 5 deletions(-) diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c index 414a85ef056..643191ba885 100644 --- a/dlls/gdi32/freetype.c +++ b/dlls/gdi32/freetype.c @@ -2965,7 +2965,7 @@ static void calc_hash(FONT_DESC *pfd) return; } -static GdiFont *find_in_cache(HFONT hfont, LOGFONTW *plf, XFORM *pxf, BOOL can_use_bitmap) +static GdiFont *find_in_cache(HFONT hfont, const LOGFONTW *plf, const XFORM *pxf, BOOL can_use_bitmap) { GdiFont *ret; FONT_DESC fd; @@ -3288,7 +3288,8 @@ GdiFont *WineEngCreateFontInstance(DC *dc, HFONT hfont) /* If requested charset was DEFAULT_CHARSET then try using charset corresponding to the current ansi codepage */ - if(!csi.fs.fsCsb[0]) { + if (!csi.fs.fsCsb[0] || lf.lfWeight == FW_DONTCARE) + { INT acp = GetACP(); if(!TranslateCharsetInfo((DWORD*)(INT_PTR)acp, &csi, TCI_SRCCODEPAGE)) { FIXME("TCI failed on codepage %d\n", acp); diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c index c627521f0e8..d4abc8cbcd1 100644 --- a/dlls/gdi32/tests/font.c +++ b/dlls/gdi32/tests/font.c @@ -1778,14 +1778,26 @@ static void test_nonexistent_font(void) LOGFONTA lf; HDC hdc; HFONT hfont; + CHARSETINFO csi; + INT cs, expected_cs; char buf[LF_FACESIZE]; - if (!is_truetype_font_installed("Arial Black")) + if (!is_truetype_font_installed("Arial") || + !is_truetype_font_installed("Times New Roman")) { - skip("Arial not installed\n"); + skip("Arial or Times New Roman not installed\n"); return; } + expected_cs = GetACP(); + if (!TranslateCharsetInfo(ULongToPtr(expected_cs), &csi, TCI_SRCCODEPAGE)) + { + skip("TranslateCharsetInfo failed for code page %d\n", expected_cs); + return; + } + expected_cs = csi.ciCharset; + trace("ACP %d -> charset %d\n", GetACP(), expected_cs); + hdc = GetDC(0); memset(&lf, 0, sizeof(lf)); @@ -1794,12 +1806,80 @@ static void test_nonexistent_font(void) lf.lfCharSet = ANSI_CHARSET; lf.lfPitchAndFamily = FF_SWISS; strcpy(lf.lfFaceName, "Nonexistent font"); - hfont = CreateFontIndirectA(&lf); hfont = SelectObject(hdc, hfont); GetTextFaceA(hdc, sizeof(buf), buf); ok(!lstrcmpiA(buf, "Arial"), "Got %s\n", buf); + cs = GetTextCharset(hdc); + ok(cs == ANSI_CHARSET, "expected ANSI_CHARSET, got %d\n", cs); DeleteObject(SelectObject(hdc, hfont)); + + memset(&lf, 0, sizeof(lf)); + lf.lfHeight = -13; + lf.lfWeight = FW_DONTCARE; + strcpy(lf.lfFaceName, "Nonexistent font"); + hfont = CreateFontIndirectA(&lf); + hfont = SelectObject(hdc, hfont); + GetTextFaceA(hdc, sizeof(buf), buf); +todo_wine /* Wine uses Arial for all substitutions */ + ok(!lstrcmpiA(buf, "Nonexistent font") /* XP, Vista */ || + !lstrcmpiA(buf, "MS Serif") /* Win9x */, "Got %s\n", buf); + cs = GetTextCharset(hdc); + ok(cs == expected_cs, "expected %d, got %d\n", expected_cs, cs); + DeleteObject(SelectObject(hdc, hfont)); + + memset(&lf, 0, sizeof(lf)); + lf.lfHeight = -13; + lf.lfWeight = FW_REGULAR; + strcpy(lf.lfFaceName, "Nonexistent font"); + hfont = CreateFontIndirectA(&lf); + hfont = SelectObject(hdc, hfont); + GetTextFaceA(hdc, sizeof(buf), buf); + ok(!lstrcmpiA(buf, "Arial") /* XP, Vista */ || + !lstrcmpiA(buf, "Times New Roman") /* Win9x */, "Got %s\n", buf); + cs = GetTextCharset(hdc); + ok(cs == ANSI_CHARSET, "expected ANSI_CHARSET, got %d\n", cs); + DeleteObject(SelectObject(hdc, hfont)); + + memset(&lf, 0, sizeof(lf)); + lf.lfHeight = -13; + lf.lfWeight = FW_DONTCARE; + strcpy(lf.lfFaceName, "Times New Roman CE"); + hfont = CreateFontIndirectA(&lf); + hfont = SelectObject(hdc, hfont); + GetTextFaceA(hdc, sizeof(buf), buf); +todo_wine /* Wine uses Arial for all substitutions */ + ok(!lstrcmpiA(buf, "Times New Roman CE") /* XP, Vista */ || + !lstrcmpiA(buf, "MS Serif") /* Win9x */, "Got %s\n", buf); + cs = GetTextCharset(hdc); + ok(cs == expected_cs, "expected %d, got %d\n", expected_cs, cs); + DeleteObject(SelectObject(hdc, hfont)); + + memset(&lf, 0, sizeof(lf)); + lf.lfHeight = -13; + lf.lfWeight = FW_DONTCARE; + strcpy(lf.lfFaceName, "Times New Roman"); + hfont = CreateFontIndirectA(&lf); + hfont = SelectObject(hdc, hfont); + GetTextFaceA(hdc, sizeof(buf), buf); + ok(!lstrcmpiA(buf, "Times New Roman"), "Got %s\n", buf); + cs = GetTextCharset(hdc); + ok(cs == ANSI_CHARSET, "expected ANSI_CHARSET, got %d\n", cs); + DeleteObject(SelectObject(hdc, hfont)); + + memset(&lf, 0, sizeof(lf)); + lf.lfHeight = -13; + lf.lfWeight = FW_REGULAR; + strcpy(lf.lfFaceName, "Times New Roman CE"); + hfont = CreateFontIndirectA(&lf); + hfont = SelectObject(hdc, hfont); + GetTextFaceA(hdc, sizeof(buf), buf); + ok(!lstrcmpiA(buf, "Arial") /* XP, Vista */ || + !lstrcmpiA(buf, "Times New Roman") /* Win9x */, "Got %s\n", buf); + cs = GetTextCharset(hdc); + ok(cs == ANSI_CHARSET, "expected ANSI_CHARSET, got %d\n", cs); + DeleteObject(SelectObject(hdc, hfont)); + ReleaseDC(0, hdc); }