Skip to content

Commit

Permalink
Properly scale default skin font according to DPI (#1110)
Browse files Browse the repository at this point in the history
Original fix introduced in 528d15 was not correct.
The problem is that `SystemParametersInfo` uses DPI that current session
started with.

We should use `SystemParametersInfoForDpi` (available since Win10 1607)
that returns properly scaled font size.

Fixes #1110
  • Loading branch information
ge0rdi committed Jan 19, 2023
1 parent 2d6fb1f commit 21eea53
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Src/StartMenu/StartMenuDLL/SkinManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,17 @@ SIZE MenuSkin::ScaleSkinElement( const SIZE &size ) const
return res;
}

_Success_(return != FALSE)
BOOL WINAPI SystemParametersInfoForDpi(_In_ UINT uiAction, _In_ UINT uiParam, _Pre_maybenull_ _Post_valid_ PVOID pvParam, _In_ UINT fWinIni, _In_ UINT dpi)
{
static auto p = static_cast<decltype(&SystemParametersInfoForDpi)>((void*)GetProcAddress(GetModuleHandle(L"user32.dll"), "SystemParametersInfoForDpi"));
if (p)
return p(uiAction, uiParam, pvParam, fWinIni, dpi);

// fall-back for older systems
return SystemParametersInfo(uiAction, uiParam, pvParam, fWinIni);
}

HFONT MenuSkin::LoadSkinFont( const wchar_t *str, const wchar_t *name, int weight, float size, bool bScale ) const
{
DWORD quality=DEFAULT_QUALITY;
Expand Down Expand Up @@ -545,9 +556,8 @@ HFONT MenuSkin::LoadSkinFont( const wchar_t *str, const wchar_t *name, int weigh
{
// get the default menu font
NONCLIENTMETRICS metrics={sizeof(metrics)};
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,NULL,&metrics,0);
SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS,sizeof(metrics),&metrics,0,Dpi);
metrics.lfMenuFont.lfQuality=(BYTE)quality;
metrics.lfMenuFont.lfHeight=ScaleSkinElement(metrics.lfMenuFont.lfHeight,scale);
return CreateFontIndirect(&metrics.lfMenuFont);
}
size=ScaleSkinElement((int)(size*96),scale)/72.f;
Expand Down

0 comments on commit 21eea53

Please sign in to comment.