@@ -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
80108private:
81109 double m_scale_steps{0.01 };
0 commit comments