summarylogtreecommitdiffstats
path: root/Parse-Semibold-Fontnames.patch
blob: 6ff255035c118643c2fc02b463145d730073fb92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Submodule Telegram/lib_ui contains modified content
diff --git a/Telegram/lib_ui/ui/style/style_core_font.cpp b/Telegram/lib_ui/ui/style/style_core_font.cpp
index ad3a9e3..3cdf07a 100644
--- a/Telegram/lib_ui/ui/style/style_core_font.cpp
+++ b/Telegram/lib_ui/ui/style/style_core_font.cpp
@@ -37,15 +37,55 @@ uint32 fontKey(int size, uint32 flags, int family) {
 	return (((uint32(family) << 10) | uint32(size)) << 4) | flags;
 }
 
+QString RemoveSemiboldFromName(const QString &familyName) {
+	auto removedSemibold = familyName;
+	removedSemibold.remove("Semibold", Qt::CaseInsensitive);
+	return removedSemibold.trimmed();
+}
+
+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;
+	}
+}
+
 bool ValidateFont(const QString &familyName, int flags = 0) {
-	QFont checkFont(familyName);
+	const auto parsedFamily = ParseFamilyName(familyName);
+
+	QFont checkFont(parsedFamily);
 	checkFont.setPixelSize(13);
 	checkFont.setBold(flags & style::internal::FontBold);
 	checkFont.setItalic(flags & style::internal::FontItalic);
 	checkFont.setUnderline(flags & style::internal::FontUnderline);
 	checkFont.setStyleStrategy(QFont::PreferQuality);
+
+	if (IsRealSemibold(familyName)) {
+		checkFont.setStyleName("Semibold");
+	}
+
 	auto realFamily = QFontInfo(checkFont).family();
-	if (realFamily.trimmed().compare(familyName, Qt::CaseInsensitive)) {
+	if (realFamily.trimmed().compare(parsedFamily, Qt::CaseInsensitive)) {
 		UI_LOG(("Font Error: could not resolve '%1' font, got '%2'.").arg(familyName).arg(realFamily));
 		return false;
 	}
@@ -238,7 +278,7 @@ int registerFontFamily(const QString &family) {
 }
 
 FontData::FontData(int size, uint32 flags, int family, Font *other)
-: f(GetFontOverride(fontFamilies[family], flags))
+: f(ParseFamilyName(GetFontOverride(fontFamilies[family], flags)))
 , m(f)
 , _size(size)
 , _flags(flags)
@@ -261,6 +301,10 @@ FontData::FontData(int size, uint32 flags, int family, Font *other)
 	f.setStrikeOut(_flags & FontStrikeOut);
 	f.setStyleStrategy(QFont::PreferQuality);
 
+	if (IsRealSemibold(GetFontOverride(fontFamilies[family], flags))) {
+		f.setStyleName("Semibold");
+	}
+
 	m = QFontMetrics(f);
 	height = m.height();
 	ascent = m.ascent();