Skip to content

Properly scale default skin font according to DPI (#1110) #1294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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