gdi32: Add more font substitution tests, make them pass under Wine

Dmitry Timoshkov dmitry at codeweavers.com
Tue May 13 08:10:05 CDT 2008


Hello,

this patch should fix the problem reported in the bug 9812.

It appears that leaving lf.lfWeight == 0 (FW_DONTCARE) signals that
the caller doesn't care about font characteristics, and Windows font
mapper goes ahead and fixes up font charset too in that case.

The tests pass under Win98, XP SP3, Vista SP1.

Changelog:
    gdi32: Add more font substitution tests, make them pass under Wine.
---
 dlls/gdi32/freetype.c   |    5 ++-
 dlls/gdi32/tests/font.c |   87 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 87 insertions(+), 5 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 414a85e..643191b 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 c627521..93d384e 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);
 }
 
-- 
1.5.5.1






More information about the wine-patches mailing list