Merge pull request #10715 from electron/fix_toast_dpi_scaling
Fixed font DPI scaling
This commit is contained in:
commit
19ac2179fb
2 changed files with 8 additions and 6 deletions
|
@ -21,8 +21,8 @@ struct NotificationData {
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
inline T ScaleForDpi(T value, unsigned dpi) {
|
||||
return value * dpi / 96;
|
||||
constexpr T ScaleForDpi(T value, unsigned dpi, unsigned source_dpi = 96) {
|
||||
return value * dpi / source_dpi;
|
||||
}
|
||||
|
||||
struct ScreenMetrics {
|
||||
|
|
|
@ -137,19 +137,21 @@ void DesktopNotificationController::InitializeFonts() {
|
|||
if (!body_font_) {
|
||||
NONCLIENTMETRICS metrics = { sizeof(metrics) };
|
||||
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) {
|
||||
auto baseHeight = metrics.lfMessageFont.lfHeight;
|
||||
auto base_height = metrics.lfMessageFont.lfHeight;
|
||||
|
||||
HDC hdc = GetDC(NULL);
|
||||
auto dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
|
||||
auto base_dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
|
||||
ReleaseDC(NULL, hdc);
|
||||
|
||||
ScreenMetrics scr;
|
||||
|
||||
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);
|
||||
|
||||
if (caption_font_) DeleteFont(caption_font_);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue