From: Akihiro Sagawa sagawa.aki@gmail.com
We also check the pixel size to avoid the problem of using the bitmap font when the specified system font, such as MS UI Gothic, is not available.
Wine-Bugs: https://bugs.winehq.org/show_bug.cgi?id=37297 --- dlls/user32/defdlg.c | 3 ++- dlls/user32/dialog.c | 30 +++++++++++++++++++++++++----- dlls/user32/tests/dialog.c | 4 ++-- 3 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/dlls/user32/defdlg.c b/dlls/user32/defdlg.c index 1b50893c041..1ff77912416 100644 --- a/dlls/user32/defdlg.c +++ b/dlls/user32/defdlg.c @@ -208,7 +208,8 @@ static LRESULT DEFDLG_Proc( HWND hwnd, UINT msg, WPARAM wParam, case WM_NCDESTROY: if (dlgInfo) { - if (dlgInfo->hUserFont) DeleteObject( dlgInfo->hUserFont ); + if (dlgInfo->hUserFont && dlgInfo->hUserFont != GetStockObject( SYSTEM_FONT )) + DeleteObject( dlgInfo->hUserFont ); if (dlgInfo->hMenu) NtUserDestroyMenu( dlgInfo->hMenu ); HeapFree( GetProcessHeap(), 0, dlgInfo );
diff --git a/dlls/user32/dialog.c b/dlls/user32/dialog.c index 219a4326441..3f8987bf4aa 100644 --- a/dlls/user32/dialog.c +++ b/dlls/user32/dialog.c @@ -432,6 +432,12 @@ static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result ) return (LPCSTR)(((UINT_PTR)p + 3) & ~3); }
+static int CALLBACK is_font_installed_proc( const LOGFONTW *lf, const TEXTMETRICW *tm, + DWORD type, LPARAM lParam) +{ + return 0; /* found */ +} +
/*********************************************************************** * DIALOG_CreateIndirect @@ -491,10 +497,23 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, /* We convert the size to pixels and then make it -ve. This works * for both +ve and -ve template.pointSize */ int pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72); - hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight, - template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0, - PROOF_QUALITY, FF_DONTCARE, - template.faceName ); + + /* Use SYSTEM_FONT instead if the given font is not installed. + * We also check the pixel size to avoid the problem of using + * the bitmap font when the specified system font, such as MS + * UI Gothic, is not available */ + if (abs(pixels) < GetSystemMetrics(SM_CYCAPTION) * 2 /* wine specific */ || + !EnumFontFamiliesW(dc, template.faceName, is_font_installed_proc, 0)) + { + hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight, + template.italic, FALSE, FALSE, DEFAULT_CHARSET, + 0, 0, PROOF_QUALITY, FF_DONTCARE, + template.faceName ); + } + else + { + hUserFont = GetStockObject( SYSTEM_FONT ); + } }
if (hUserFont) @@ -639,7 +658,8 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
if (!hwnd) { - if (hUserFont) DeleteObject( hUserFont ); + if (hUserFont && hUserFont != GetStockObject( SYSTEM_FONT )) + DeleteObject( hUserFont ); if (hMenu) NtUserDestroyMenu( hMenu ); if (disabled_owner) EnableWindow( disabled_owner, TRUE ); return 0; diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c index bf74736b325..bb11dc61a71 100644 --- a/dlls/user32/tests/dialog.c +++ b/dlls/user32/tests/dialog.c @@ -2476,12 +2476,12 @@ static void test_unknown_font_name(void) GetClientRect(hDlg, &rcUnknown);
hFont = (HFONT) SendMessageW(hDlg, WM_GETFONT, 0, 0); - todo_wine ok(hFont == GetStockObject(SYSTEM_FONT), "got %p\n", hFont); + ok(hFont == GetStockObject(SYSTEM_FONT), "got %p\n", hFont);
DestroyWindow(hDlg);
/* Are they the same window size? */ - todo_wine ok(!memcmp(&rcDefault, &rcUnknown, sizeof(RECT)), "got %s, expected %s\n", wine_dbgstr_rect(&rcUnknown), wine_dbgstr_rect(&rcDefault)); + ok(!memcmp(&rcDefault, &rcUnknown, sizeof(RECT)), "got %s, expected %s\n", wine_dbgstr_rect(&rcUnknown), wine_dbgstr_rect(&rcDefault)); }
START_TEST(dialog)