Skip to content

Commit 719717a

Browse files
committed
fix: reintroduce fallbacks and assertion checks to avoid regressions
They got lost in refactoring and are causing test failures on CI, bring them back.
1 parent 72d2868 commit 719717a

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

src/qt/guiutil_font.h

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,47 @@ class FontRegistry {
6363

6464
void SetFont(const QString& font);
6565
void SetFontScale(int font_scale) { m_font_scale = font_scale; }
66-
void SetWeightBold(const QFont::Weight& bold) { m_weights.at(m_font).m_bold = bold; }
67-
void SetWeightNormal(const QFont::Weight& normal) { m_weights.at(m_font).m_normal = normal; }
66+
void SetWeightBold(const QFont::Weight& bold)
67+
{
68+
assert(m_weights.count(m_font));
69+
m_weights.at(m_font).m_bold = bold;
70+
}
71+
void SetWeightNormal(const QFont::Weight& normal)
72+
{
73+
assert(m_weights.count(m_font));
74+
m_weights.at(m_font).m_normal = normal;
75+
}
6876

6977
double GetScaleSteps() const { return m_scale_steps; }
7078
double GetScaledFontSize(int size) const { return std::round(size * (1 + (m_font_scale * m_scale_steps)) * 4) / 4.0; }
7179
QString GetFont() const { return m_font; }
7280
int GetFontScale() const { return m_font_scale; }
7381
int GetFontSize() const { return m_font_size; }
74-
QFont::Weight GetWeightBold() const { return m_weights.at(m_font).m_bold; }
75-
QFont::Weight GetWeightNormal() const { return m_weights.at(m_font).m_normal; }
76-
QFont::Weight GetWeightBoldDefault() const { return m_weights.at(m_font).m_bold_default; }
77-
QFont::Weight GetWeightNormalDefault() const { return m_weights.at(m_font).m_normal_default; }
78-
std::vector<QFont::Weight> GetSupportedWeights() const { return m_weights.at(m_font).m_supported_weights; }
82+
QFont::Weight GetWeightBold() const
83+
{
84+
if (auto it = m_weights.find(m_font); it != m_weights.end()) { return it->second.m_bold; }
85+
return TARGET_WEIGHT_BOLD;
86+
}
87+
QFont::Weight GetWeightNormal() const
88+
{
89+
if (auto it = m_weights.find(m_font); it != m_weights.end()) { return it->second.m_normal; }
90+
return TARGET_WEIGHT_NORMAL;
91+
}
92+
QFont::Weight GetWeightBoldDefault() const
93+
{
94+
if (auto it = m_weights.find(m_font); it != m_weights.end()) { return it->second.m_bold_default; }
95+
return TARGET_WEIGHT_BOLD;
96+
}
97+
QFont::Weight GetWeightNormalDefault() const
98+
{
99+
if (auto it = m_weights.find(m_font); it != m_weights.end()) { return it->second.m_normal_default; }
100+
return TARGET_WEIGHT_NORMAL;
101+
}
102+
std::vector<QFont::Weight> GetSupportedWeights() const
103+
{
104+
if (auto it = m_weights.find(m_font); it != m_weights.end()) { return it->second.m_supported_weights; }
105+
return {TARGET_WEIGHT_NORMAL, TARGET_WEIGHT_BOLD};
106+
}
79107

80108
private:
81109
double m_scale_steps{0.01};

0 commit comments

Comments
 (0)