diff options
author | George Hazan <ghazan@miranda.im> | 2022-06-16 22:32:40 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-06-16 22:32:40 +0300 |
commit | b306ebad307bc450d0639ee0169976fa50a84b40 (patch) | |
tree | cef022b550448034401fdb35e00347cd3902133d /src | |
parent | aa37139121fccf4d304cc07d546b2b96ebe6dbcb (diff) |
Utils_CorrectFontSize - a function for dynamic font size adjustment
Diffstat (limited to 'src')
-rw-r--r-- | src/core/stdmsg/src/msgoptions.cpp | 4 | ||||
-rw-r--r-- | src/mir_app/src/chat_opts.cpp | 6 | ||||
-rw-r--r-- | src/mir_core/src/Windows/miranda.cpp | 11 | ||||
-rw-r--r-- | src/mir_core/src/Windows/winutil.cpp | 15 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 1 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 1 |
6 files changed, 28 insertions, 10 deletions
diff --git a/src/core/stdmsg/src/msgoptions.cpp b/src/core/stdmsg/src/msgoptions.cpp index 60a798bd72..5e52bbceed 100644 --- a/src/core/stdmsg/src/msgoptions.cpp +++ b/src/core/stdmsg/src/msgoptions.cpp @@ -60,7 +60,7 @@ bool LoadMsgDlgFont(int i, LOGFONT* lf, COLORREF * colour) }
if (lf) {
mir_snprintf(str, "SRMFont%dSize", i);
- lf->lfHeight = (char)g_plugin.getByte(str, fontOptionsList[i].defSize);
+ lf->lfHeight = Utils_CorrectFontSize(g_plugin.getByte(str, fontOptionsList[i].defSize));
lf->lfWidth = 0;
lf->lfEscapement = 0;
lf->lfOrientation = 0;
@@ -106,7 +106,7 @@ void RegisterSRMMFonts(void) fontid.flags |= (fontOptionsList[i].defStyle == DBFONTF_BOLD) ? FIDF_CLASSHEADER : FIDF_CLASSGENERAL;
fontid.deffontsettings.colour = fontOptionsList[i].defColour;
- fontid.deffontsettings.size = fontOptionsList[i].defSize;
+ fontid.deffontsettings.size = Utils_CorrectFontSize(fontOptionsList[i].defSize);
fontid.deffontsettings.style = fontOptionsList[i].defStyle;
wcsncpy_s(fontid.deffontsettings.szFace, fontOptionsList[i].szDefFace, _TRUNCATE);
fontid.deffontsettings.charset = DEFAULT_CHARSET;
diff --git a/src/mir_app/src/chat_opts.cpp b/src/mir_app/src/chat_opts.cpp index 50a7587f6c..756caea53b 100644 --- a/src/mir_app/src/chat_opts.cpp +++ b/src/mir_app/src/chat_opts.cpp @@ -68,7 +68,7 @@ static FontOptionsList fontOptionsList[] = { LPGENW("User disables status for ..."), RGB(150, 70, 70), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
{ LPGENW("Action message"), RGB(160, 90, 160), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
{ LPGENW("Highlighted message"), RGB(180, 150, 80), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
- { L"", 0, lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
+ { L"", 0, lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
{ LPGENW("Nick list members (online)"), RGB(0, 0, 0), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 },
{ LPGENW("Nick list members (away)"), RGB(170, 170, 170), lfDefault.lfFaceName, DEFAULT_CHARSET, 0, -12 }
};
@@ -106,7 +106,7 @@ void LoadMsgDlgFont(int i, LOGFONT *lf, COLORREF *colour) }
if (lf) {
mir_snprintf(str, "Font%dSize", i);
- lf->lfHeight = (char)db_get_b(0, CHATFONT_MODULE, str, FO.defSize);
+ lf->lfHeight = db_get_b(0, CHATFONT_MODULE, str, Utils_CorrectFontSize(FO.defSize));
lf->lfWidth = 0;
lf->lfEscapement = 0;
lf->lfOrientation = 0;
@@ -175,7 +175,7 @@ void RegisterFonts(void) wcsncpy_s(fontid.deffontsettings.szFace, FO.szDefFace, _TRUNCATE);
fontid.deffontsettings.charset = FO.defCharset;
fontid.deffontsettings.colour = FO.defColour;
- fontid.deffontsettings.size = FO.defSize;
+ fontid.deffontsettings.size = Utils_CorrectFontSize(FO.defSize);
fontid.deffontsettings.style = FO.defStyle;
Font_RegisterW(&fontid, g_pChatPlugin);
}
diff --git a/src/mir_core/src/Windows/miranda.cpp b/src/mir_core/src/Windows/miranda.cpp index a00eb3d448..7446eb1ba0 100644 --- a/src/mir_core/src/Windows/miranda.cpp +++ b/src/mir_core/src/Windows/miranda.cpp @@ -183,6 +183,11 @@ static void LoadCoreModule(void) InitTimeZones(); InitialiseModularEngine(); + wchar_t wszIniPath[MAX_PATH]; + PathToAbsoluteW(L"mirandaboot.ini", wszIniPath); + if (GetPrivateProfileIntW(L"Interface", L"DpiAware", 0, wszIniPath) == 1) + g_bEnableDpiAware = true; + CreateServiceFunction(MS_SYSTEM_RESTART, RestartMiranda); hShutdownEvent = CreateHookableEvent(ME_SYSTEM_SHUTDOWN); @@ -255,15 +260,11 @@ MIR_CORE_DLL(void) BeginMessageLoop() bufferedPaintUninit = (pfnBufferedPaintUninit)GetProcAddress(hThemeAPI, "BufferedPaintUninit"); } - wchar_t wszIniPath[MAX_PATH]; - PathToAbsoluteW(L"mirandaboot.ini", wszIniPath); - if (GetPrivateProfileIntW(L"Interface", L"DpiAware", 0, wszIniPath) == 1) { + if (g_bEnableDpiAware) { typedef BOOL (WINAPI *pfnSetProcessDPIAware_t)(void); auto *pFunc = (pfnSetProcessDPIAware_t)GetProcAddress(GetModuleHandleW(L"user32"), "SetProcessDPIAware"); if (pFunc != nullptr) pFunc(); - - g_bEnableDpiAware = true; } if (bufferedPaintInit) diff --git a/src/mir_core/src/Windows/winutil.cpp b/src/mir_core/src/Windows/winutil.cpp index f22b5e3fd9..4e4846a467 100644 --- a/src/mir_core/src/Windows/winutil.cpp +++ b/src/mir_core/src/Windows/winutil.cpp @@ -116,3 +116,18 @@ MIR_CORE_DLL(int) Utils_AssertInsideScreen(RECT *rc) return 1; } + +///////////////////////////////////////////////////////////////////////////////////////// + +static LOGFONTW g_lfDefault; + +MIR_CORE_DLL(int) Utils_CorrectFontSize(int size) +{ + if (!g_bEnableDpiAware) + return size; + + if (!g_lfDefault.lfWeight) + SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(g_lfDefault), &g_lfDefault, FALSE); + + return size * g_lfDefault.lfWeight / -12; +} diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 694d3ed211..558e90dc3e 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1539,3 +1539,4 @@ Miranda_IsTerminated @1758 Miranda_SetTerminated @1759
Miranda_WaitOnHandle @1760
Miranda_WaitOnHandleEx @1761
+_Utils_CorrectFontSize@4 @1762 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 9b283b025d..a3f03dab57 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1539,3 +1539,4 @@ Miranda_IsTerminated @1758 Miranda_SetTerminated @1759
Miranda_WaitOnHandle @1760
Miranda_WaitOnHandleEx @1761
+Utils_CorrectFontSize @1762 NONAME
|