Merge branch 'msw-font-dpi'

Various wxFont-related fixes and refactorings in preparation for adding
per-monitor DPI support.

Closes https://github.com/wxWidgets/wxWidgets/pull/1408
This commit is contained in:
Vadim Zeitlin
2019-07-12 18:53:24 +02:00
12 changed files with 83 additions and 78 deletions

View File

@@ -118,7 +118,20 @@ public:
// set the XFLD
void SetXFontName(const wxString& xFontName);
#elif defined(__WXMSW__)
wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_), pointSize(0.0f) { }
wxNativeFontInfo(const LOGFONT& lf_);
// MSW-specific: get the height value in pixels using LOGFONT convention
// (i.e. negative) corresponding to the given size in points and DPI.
static int GetLogFontHeightAtPPI(float size, int ppi)
{
return -wxRound(size * ppi / 72.0);
}
// And the same thing for the size of this font.
int GetLogFontHeightAtPPI(int ppi) const
{
return GetLogFontHeightAtPPI(pointSize, ppi);
}
LOGFONT lf;

View File

@@ -961,10 +961,14 @@ extern const wxCursor *wxGetGlobalCursor(); // from msw/cursor.cpp
WXDLLIMPEXP_CORE void wxGetCursorPosMSW(POINT* pt);
WXDLLIMPEXP_CORE void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font);
WXDLLIMPEXP_CORE void wxFillLogFont(LOGFONT *logFont, const wxFont *font);
WXDLLIMPEXP_CORE wxFont wxCreateFontFromLogFont(const LOGFONT *logFont);
WXDLLIMPEXP_CORE wxFontEncoding wxGetFontEncFromCharSet(int charset);
inline void wxSetWindowFont(HWND hwnd, const wxFont& font)
{
::SendMessage(hwnd, WM_SETFONT,
(WPARAM)GetHfontOf(font), MAKELPARAM(TRUE, 0));
}
WXDLLIMPEXP_CORE void wxSliderEvent(WXHWND control, WXWORD wParam, WXWORD pos);
WXDLLIMPEXP_CORE void wxScrollBarEvent(WXHWND hbar, WXWORD wParam, WXWORD pos);

View File

@@ -113,14 +113,11 @@ public:
// set font for all windows
void SetFont(const wxFont& font)
{
HFONT hfont = GetHfontOf(font);
wxCHECK_RET( hfont, wxT("invalid font") );
for ( size_t n = 0; n < m_count; n++ )
{
if ( m_hwnds[n] )
{
::SendMessage(m_hwnds[n], WM_SETFONT, (WPARAM)hfont, 0);
wxSetWindowFont(m_hwnds[n], font);
// otherwise the window might not be redrawn correctly
::InvalidateRect(m_hwnds[n], NULL, FALSE /* don't erase bg */);