@@ -155,9 +155,7 @@ void FontEngine::readSettings()
155155 m_default_bold = g_settings->getBool (" font_bold" );
156156 m_default_italic = g_settings->getBool (" font_italic" );
157157
158- clearCache ();
159- updateCache ();
160- updateSkin ();
158+ refresh ();
161159}
162160
163161void FontEngine::updateSkin ()
@@ -175,25 +173,25 @@ void FontEngine::updateCache()
175173 getFont (FONT_SIZE_UNSPECIFIED, FM_Unspecified);
176174}
177175
176+ void FontEngine::refresh () {
177+ clearCache ();
178+ updateCache ();
179+ updateSkin ();
180+ }
181+
178182void FontEngine::setMediaFont (const std::string &name, const std::string &data)
179183{
180184 std::string copy = data;
181185 irr_ptr<gui::SGUITTFace> face (gui::SGUITTFace::createFace (std::move (copy)));
182186 m_media_faces.emplace (name, face);
183- // HACK dedup this
184- clearCache ();
185- updateCache ();
186- updateSkin ();
187+ refresh ();
187188}
188189
189190void FontEngine::clearMediaFonts ()
190191{
191192 RecursiveMutexAutoLock l (m_font_mutex);
192193 m_media_faces.clear ();
193- // HACK dedup this
194- clearCache ();
195- updateCache ();
196- updateSkin ();
194+ refresh ();
197195}
198196
199197gui::IGUIFont *FontEngine::initFont (const FontSpec &spec)
@@ -246,26 +244,29 @@ gui::IGUIFont *FontEngine::initFont(const FontSpec &spec)
246244 : (setting_suffix.empty () ? " " : setting_suffix.substr (1 ));
247245 if (media_name == " " ) media_name = " regular" ;
248246
249- auto it = m_media_faces.find (media_name);
250- if (it != m_media_faces.end ()) {
251- auto *face = it->second .get ();
252- face->grab ();
247+ auto createFont = [&](gui::SGUITTFace *face) -> gui::CGUITTFont* {
253248 auto *font = gui::CGUITTFont::createTTFont (m_env,
254249 face, size, true , true , font_shadow,
255250 font_shadow_alpha);
256-
257- if (!font) {
258- errorstream << " FontEngine: Cannot load media font '" << media_name <<
259- " '. Falling back to client settings." << std::endl;
260- }
261251
262- // HACK this tidbit is duplicated
252+ if (!font) return nullptr ;
253+
263254 if (spec.mode != _FM_Fallback) {
264255 FontSpec spec2 (spec);
265256 spec2.mode = _FM_Fallback;
266257 font->setFallback (getFont (spec2, true ));
267258 }
259+
268260 return font;
261+ };
262+
263+ auto it = m_media_faces.find (media_name);
264+ if (it != m_media_faces.end ()) {
265+ auto *face = it->second .get ();
266+ if (auto *font = createFont (face))
267+ return font;
268+ errorstream << " FontEngine: Cannot load media font '" << media_name <<
269+ " '. Falling back to client settings." << std::endl;
269270 }
270271
271272 for (const std::string &font_path : fallback_settings) {
@@ -274,25 +275,11 @@ gui::IGUIFont *FontEngine::initFont(const FontSpec &spec)
274275
275276 // Grab the face.
276277 auto *face = irr::gui::SGUITTFace::loadFace (font_path);
277- gui::CGUITTFont *font = nullptr ;
278- if (face) {
279- font = gui::CGUITTFont::createTTFont (m_env,
280- face, size, true , true , font_shadow,
281- font_shadow_alpha);
282- }
278+ if (auto *font = face ? createFont (face) : nullptr )
279+ return font;
283280
284- if (!font) {
285- errorstream << " FontEngine: Cannot load '" << font_path <<
286- " '. Trying to fall back to another path." << std::endl;
287- continue ;
288- }
289-
290- if (spec.mode != _FM_Fallback) {
291- FontSpec spec2 (spec);
292- spec2.mode = _FM_Fallback;
293- font->setFallback (getFont (spec2, true ));
294- }
295- return font;
281+ errorstream << " FontEngine: Cannot load '" << font_path <<
282+ " '. Trying to fall back to another path." << std::endl;
296283 }
297284 return nullptr ;
298285}
0 commit comments