Fixed font DPI scaling

This commit is contained in:
Ales Pergl 2017-10-06 22:25:44 +02:00
parent c85b159d46
commit 1d25d58c26
2 changed files with 8 additions and 6 deletions

View file

@ -21,8 +21,8 @@ struct NotificationData {
}; };
template<typename T> template<typename T>
inline T ScaleForDpi(T value, unsigned dpi) { constexpr T ScaleForDpi(T value, unsigned dpi, unsigned source_dpi = 96) {
return value * dpi / 96; return value * dpi / source_dpi;
} }
struct ScreenMetrics { struct ScreenMetrics {

View file

@ -137,19 +137,21 @@ void DesktopNotificationController::InitializeFonts() {
if (!body_font_) { if (!body_font_) {
NONCLIENTMETRICS metrics = { sizeof(metrics) }; NONCLIENTMETRICS metrics = { sizeof(metrics) };
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) { if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) {
auto baseHeight = metrics.lfMessageFont.lfHeight; auto base_height = metrics.lfMessageFont.lfHeight;
HDC hdc = GetDC(NULL); HDC hdc = GetDC(NULL);
auto dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); auto base_dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(NULL, hdc); ReleaseDC(NULL, hdc);
ScreenMetrics scr;
metrics.lfMessageFont.lfHeight = metrics.lfMessageFont.lfHeight =
(LONG)ScaleForDpi(baseHeight * 1.1f, dpi_y); (LONG)ScaleForDpi(base_height * 1.1f, scr.dpi_y, base_dpi_y);
body_font_ = CreateFontIndirect(&metrics.lfMessageFont); body_font_ = CreateFontIndirect(&metrics.lfMessageFont);
if (caption_font_) DeleteFont(caption_font_); if (caption_font_) DeleteFont(caption_font_);
metrics.lfMessageFont.lfHeight = metrics.lfMessageFont.lfHeight =
(LONG)ScaleForDpi(baseHeight * 1.4f, dpi_y); (LONG)ScaleForDpi(base_height * 1.4f, scr.dpi_y, base_dpi_y);
caption_font_ = CreateFontIndirect(&metrics.lfMessageFont); caption_font_ = CreateFontIndirect(&metrics.lfMessageFont);
} }
} }