From 990c4472c4f40caa89fad0747b1311a4d0bd0265 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Thu, 15 Sep 2022 23:17:03 +0300 Subject: [PATCH] [Option][GUI] Font options --- ui/style/style_core_font.cpp | 27 +++++++++++++++++++++------ ui/style/style_core_font.h | 7 +++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ui/style/style_core_font.cpp b/ui/style/style_core_font.cpp index 626ba05..db336ea 100644 --- a/ui/style/style_core_font.cpp +++ b/ui/style/style_core_font.cpp @@ -11,6 +11,7 @@ #include "base/variant.h" #include "base/base_file_utilities.h" #include "ui/integration.h" +#include "ui/style/style_core_scale.h" #include #include @@ -38,6 +39,7 @@ namespace style { namespace { QString Custom; +CustomFontSettings CustomSettings; } // namespace @@ -50,6 +52,10 @@ void SetCustomFont(const QString &font) { Custom = font; } +void SetCustomFontSettings(const CustomFontSettings &settings) { + CustomSettings = settings; +} + namespace internal { struct ResolvedFont { @@ -125,6 +131,11 @@ bool LoadCustomFont(const QString &filePath) { } #endif // !LIB_UI_USE_PACKAGED_FONTS +bool TryFont(const QString &attempt) { + const auto resolved = QFontInfo(QFont(attempt)).family(); + return !resolved.trimmed().compare(attempt, Qt::CaseInsensitive); +} + [[nodiscard]] QString SystemMonospaceFont() { const auto type = QFontDatabase::FixedFont; return QFontDatabase::systemFont(type).family(); @@ -139,8 +150,7 @@ bool LoadCustomFont(const QString &filePath) { u"Courier"_q, }; for (const auto &family : kTryFirst) { - const auto resolved = QFontInfo(QFont(family)).family(); - if (resolved.trimmed().startsWith(family, Qt::CaseInsensitive)) { + if (TryFont(family)) { return family; } } @@ -149,6 +159,10 @@ bool LoadCustomFont(const QString &filePath) { [[nodiscard]] QString MonospaceFont() { static const auto family = [&]() -> QString { + if (TryFont(CustomSettings.monospaceFont)) { + return CustomSettings.monospaceFont; + } + const auto manual = ManualMonospaceFont(); const auto system = SystemMonospaceFont(); @@ -330,7 +344,7 @@ struct Metrics { font.setFeature("ss03", true); #endif // Qt >= 6.7.0 } - font.setPixelSize(size); + font.setPixelSize(size + ConvertScale(CustomSettings.fontSize)); const auto adjust = (overriden || system); const auto metrics = ComputeMetrics(font, adjust); @@ -341,9 +355,10 @@ struct Metrics { : QFont::Normal); if (font.bold()) { const auto style = QFontInfo(font).styleName(); - if (!style.isEmpty() && !style.startsWith( - "Semibold", - Qt::CaseInsensitive)) { + if (CustomSettings.semiboldIsBold + || (!style.isEmpty() && !style.startsWith( + "Semibold", + Qt::CaseInsensitive))) { font.setBold(true); } } diff --git a/ui/style/style_core_font.h b/ui/style/style_core_font.h index 63ea664..ad43c02 100644 --- a/ui/style/style_core_font.h +++ b/ui/style/style_core_font.h @@ -16,8 +16,15 @@ namespace style { +struct CustomFontSettings { + QString monospaceFont; + int fontSize = 0; + bool semiboldIsBold = false; +}; + [[nodiscard]] const QString &SystemFontTag(); void SetCustomFont(const QString &font); +void SetCustomFontSettings(const CustomFontSettings &settings); enum class FontFlag : uchar { Bold = 0x01,