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.
From: Akihiro Sagawa sagawa.aki@gmail.com
--- dlls/user32/tests/dialog.c | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c index 7ea0d13c0f3..bf74736b325 100644 --- a/dlls/user32/tests/dialog.c +++ b/dlls/user32/tests/dialog.c @@ -2434,6 +2434,56 @@ static void test_create_controls(void) DestroyWindow(control); }
+static void test_unknown_font_name(void) +{ + HWND hDlg; + RECT rcDefault, rcUnknown; + struct { + DLGTEMPLATE tmplate; + WORD menu,class,title,pointSize; + WCHAR faceName[LF_FACESIZE]; + } temp; + HFONT hFont; + const short width = 120, height = 80; + + /* Create a dialog box with the default font */ + memset(&temp, 0, sizeof(temp)); + temp.tmplate.style = DS_CENTER; + temp.tmplate.cx = width; + temp.tmplate.cy = height; + + hDlg = CreateDialogIndirectParamW(g_hinst, (LPCDLGTEMPLATEW)&temp, NULL, NULL, 0); + ok(hDlg != 0, "Failed to create test dialog.\n"); + + GetClientRect(hDlg, &rcDefault); + + hFont = (HFONT) SendMessageW(hDlg, WM_GETFONT, 0, 0); + ok(!hFont, "got %p\n", hFont); + + DestroyWindow(hDlg); + + /* Create a dialog box with an unknown font name */ + memset(&temp, 0, sizeof(temp)); + temp.tmplate.style = DS_SETFONT | DS_CENTER; + temp.tmplate.cx = width; + temp.tmplate.cy = height; + temp.pointSize = 1234; /* will be ignored */ + wcscpy(temp.faceName, L"Nonexistent font"); + + hDlg = CreateDialogIndirectParamW(g_hinst, (LPCDLGTEMPLATEW)&temp, NULL, NULL, 0); + ok(hDlg != 0, "Failed to create test dialog.\n"); + + GetClientRect(hDlg, &rcUnknown); + + hFont = (HFONT) SendMessageW(hDlg, WM_GETFONT, 0, 0); + todo_wine 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)); +} + START_TEST(dialog) { g_hinst = GetModuleHandleA (0); @@ -2455,4 +2505,5 @@ START_TEST(dialog) test_timer_message(); test_MessageBox(); test_capture_release(); + test_unknown_font_name(); }
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)
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=151203
Your paranoid android.
=== debian11 (32 bit report) ===
user32: input.c:4306: Test succeeded inside todo block: button_down_hwnd_todo 1: got MSG_TEST_WIN hwnd 001E0086, msg WM_LBUTTONDOWN, wparam 0x1, lparam 0x320032
=== debian11b (64 bit WoW report) ===
user32: input.c:4306: Test succeeded inside todo block: button_down_hwnd_todo 1: got MSG_TEST_WIN hwnd 0000000000B200F0, msg WM_LBUTTONDOWN, wparam 0x1, lparam 0x320032