From 10fec15751ee00ab1b1482b889c0e261fdd40e2f Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 25 Aug 2019 15:27:28 +0200 Subject: [PATCH] Calculate correct font pointSize for GetNonClientMetrics wxNativeFontInfo constructor calculates the pointSize using the main screen DPI. But lfHeight returned by GetNonClientMetrics is based on the window DPI. --- src/msw/menuitem.cpp | 10 +++++++++- src/msw/msgdlg.cpp | 13 +++++++++++-- src/msw/settings.cpp | 11 ++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index 83733eb4aa..cbf114bb9a 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -392,7 +392,15 @@ void MenuDrawData::Init() Offset = -12; - Font = wxFont(wxNativeFontInfo(metrics.lfMenuFont)); + wxNativeFontInfo info(metrics.lfMenuFont); + // wxNativeFontInfo constructor calculates the pointSize using the + // main screen DPI. But lfHeight is based on the window DPI. + if ( window ) + { + info.pointSize = wxNativeFontInfo::GetPointSizeAtPPI( + info.lf.lfHeight, window->GetDPI().y); + } + Font = wxFont(info); Theme = false; } diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index 8e2a101a55..21fbfc4e4b 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -397,8 +397,17 @@ void wxMessageDialog::AdjustButtonLabels() wxFont wxMessageDialog::GetMessageFont() { const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL; - const NONCLIENTMETRICS& ncm = wxMSWImpl::GetNonClientMetrics(win); - return wxNativeFontInfo(ncm.lfMessageFont); + wxNativeFontInfo info(wxMSWImpl::GetNonClientMetrics(win).lfMessageFont); + + // wxNativeFontInfo constructor calculates the pointSize using the + // main screen DPI. But lfHeight is based on the window DPI. + if ( win ) + { + info.pointSize = wxNativeFontInfo::GetPointSizeAtPPI( + info.lf.lfHeight, win->GetDPI().y); + } + + return info; } int wxMessageDialog::ShowMessageBox() diff --git a/src/msw/settings.cpp b/src/msw/settings.cpp index fc1783c1ac..c2029cc67f 100644 --- a/src/msw/settings.cpp +++ b/src/msw/settings.cpp @@ -183,8 +183,17 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) // controls may prefer to use lfStatusFont or lfCaptionFont if it // is more appropriate for them const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL; - const wxNativeFontInfo + wxNativeFontInfo info(wxMSWImpl::GetNonClientMetrics(win).lfMessageFont); + + // wxNativeFontInfo constructor calculates the pointSize using the + // main screen DPI. But lfHeight is based on the window DPI. + if ( win ) + { + info.pointSize = wxNativeFontInfo::GetPointSizeAtPPI( + info.lf.lfHeight, win->GetDPI().y); + } + gs_fontDefault = new wxFont(info); }