From fc694055aca2f469aa906c0c8c6e9bc70cf46c1e Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 26 Dec 2020 03:25:28 +0400 Subject: [PATCH 1/2] Fix applying bold style with system font --- ui/style/style_core_custom_font.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/style/style_core_custom_font.cpp b/ui/style/style_core_custom_font.cpp index 83aa83c..ccb4a3a 100644 --- a/ui/style/style_core_custom_font.cpp +++ b/ui/style/style_core_custom_font.cpp @@ -46,8 +46,10 @@ QFont ResolveFont(uint32 flags, int size) { : sizes; const auto point = good.isEmpty() ? size : good.front(); result = Database.font(custom.family, custom.style, point); - } else if (!UseSystemFont || !overrideIsEmpty) { - result.setFamily(fontOverride); + } else { + if (!UseSystemFont || !overrideIsEmpty) { + result.setFamily(fontOverride); + } if (bold) { if (CustomSemiboldIsBold) { result.setBold(true); From c4417452095d91dc97f0c3ae852d59c469ab54c5 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 26 Dec 2020 03:32:11 +0400 Subject: [PATCH 2/2] No need to parse Semibold in name since tdesktop code always uses Semibold style --- ui/style/style_core_custom_font.cpp | 11 +------- ui/style/style_core_font.cpp | 44 ++--------------------------- ui/style/style_core_font.h | 2 -- 3 files changed, 3 insertions(+), 54 deletions(-) diff --git a/ui/style/style_core_custom_font.cpp b/ui/style/style_core_custom_font.cpp index ccb4a3a..da9a8b4 100644 --- a/ui/style/style_core_custom_font.cpp +++ b/ui/style/style_core_custom_font.cpp @@ -28,7 +28,6 @@ void SetCustomFonts(const CustomFont ®ular, const CustomFont &bold) { QFont ResolveFont(uint32 flags, int size) { static auto Database = QFontDatabase(); - const auto fontOverride = ParseFamilyName(GetFontOverride(flags)); const auto overrideIsEmpty = GetPossibleEmptyOverride(flags).isEmpty(); const auto bold = ((flags & FontBold) || (flags & FontSemibold)); @@ -48,7 +47,7 @@ QFont ResolveFont(uint32 flags, int size) { result = Database.font(custom.family, custom.style, point); } else { if (!UseSystemFont || !overrideIsEmpty) { - result.setFamily(fontOverride); + result.setFamily(GetFontOverride(flags)); } if (bold) { if (CustomSemiboldIsBold) { @@ -72,14 +71,6 @@ QFont ResolveFont(uint32 flags, int size) { } } } - - if (IsRealSemibold(fontOverride)) { - if (flags & FontItalic) { - result.setStyleName("Semibold Italic"); - } else { - result.setStyleName("Semibold"); - } - } } if (italic) { result.setItalic(true); diff --git a/ui/style/style_core_font.cpp b/ui/style/style_core_font.cpp index 4c47130..25b2fda 100644 --- a/ui/style/style_core_font.cpp +++ b/ui/style/style_core_font.cpp @@ -42,26 +42,13 @@ uint32 fontKey(int size, uint32 flags, int family) { return (((uint32(family) << 12) | uint32(size)) << 6) | flags; } -QString RemoveSemiboldFromName(const QString &familyName) { - auto removedSemibold = familyName; - removedSemibold.remove("Semibold", Qt::CaseInsensitive); - return removedSemibold.trimmed(); -} - bool ValidateFont(const QString &familyName, int flags = 0) { - const auto parsedFamily = ParseFamilyName(familyName); - - QFont checkFont(parsedFamily); + QFont checkFont(familyName); checkFont.setBold(flags & style::internal::FontBold); checkFont.setItalic(flags & style::internal::FontItalic); checkFont.setUnderline(flags & style::internal::FontUnderline); - - if (IsRealSemibold(familyName)) { - checkFont.setStyleName("Semibold"); - } - auto realFamily = QFontInfo(checkFont).family(); - if (realFamily.trimmed().compare(parsedFamily, Qt::CaseInsensitive)) { + if (realFamily.trimmed().compare(familyName, Qt::CaseInsensitive)) { UI_LOG(("Font Error: could not resolve '%1' font, got '%2'.").arg(familyName).arg(realFamily)); return false; } @@ -305,33 +292,6 @@ QString GetFontOverride(int32 flags) { return result.isEmpty() ? "Open Sans" : result; } -bool IsRealSemibold(const QString &familyName) { - const auto removedSemibold = RemoveSemiboldFromName(familyName); - - QFont originalFont(familyName); - QFont withoutSemiboldFont(removedSemibold); - withoutSemiboldFont.setStyleName("Semibold"); - - QFontInfo originalFontInfo(originalFont); - QFontInfo withoutSemiboldInfo(withoutSemiboldFont); - - if (originalFontInfo.family().trimmed().compare(familyName, Qt::CaseInsensitive) && - !withoutSemiboldInfo.family().trimmed().compare(removedSemibold, Qt::CaseInsensitive) && - !withoutSemiboldInfo.styleName().trimmed().compare("Semibold", Qt::CaseInsensitive)) { - return true; - } else { - return false; - } -} - -QString ParseFamilyName(const QString &familyName) { - if (IsRealSemibold(familyName)) { - return RemoveSemiboldFromName(familyName); - } else { - return familyName; - } -} - QString MonospaceFont() { static const auto family = [&]() -> QString { if (TryFont(CustomMonospaceFont)) { diff --git a/ui/style/style_core_font.h b/ui/style/style_core_font.h index 43708f6..11e6eba 100644 --- a/ui/style/style_core_font.h +++ b/ui/style/style_core_font.h @@ -24,8 +24,6 @@ extern bool UseOriginalMetrics; void StartFonts(); [[nodiscard]] QString GetPossibleEmptyOverride(int32 flags = 0); [[nodiscard]] QString GetFontOverride(int32 flags = 0); -[[nodiscard]] bool IsRealSemibold(const QString &familyName); -[[nodiscard]] QString ParseFamilyName(const QString &familyName); [[nodiscard]] QString MonospaceFont(); void destroyFonts();