Fix: Wayland crash on startup due to Pango also using FontConfig (#10916)

Basically, we haven't been a good neighbour. Turns out you shouldn't
actually call FcFini when you are done, as some library might still
want to use FontConfig. And they use a shared instance for their
administration.

The idea is that you call FcInit once, and use FcConfigReference
after that to get an instance, you can release. This entry is
ref-counted, and things happen automatically based on that.

At least, I think.
This commit is contained in:
Patric Stout 2023-06-03 21:09:02 +02:00 committed by Loïc Guilloux
parent 53709f0bdc
commit 57a6233754
1 changed files with 59 additions and 52 deletions

View File

@ -30,8 +30,13 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
FT_Error err = FT_Err_Cannot_Open_Resource;
if (!FcInit()) {
ShowInfoF("Unable to load font configuration");
} else {
ShowInfo("Unable to load font configuration");
return err;
}
auto fc_instance = FcConfigReference(nullptr);
assert(fc_instance != nullptr);
FcPattern *match;
FcPattern *pat;
FcFontSet *fs;
@ -87,8 +92,7 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
free(font_family);
FcPatternDestroy(pat);
FcFontSetDestroy(fs);
FcFini();
}
FcConfigDestroy(fc_instance);
return err;
}
@ -98,10 +102,13 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback)
{
if (!FcInit()) return false;
bool ret = false;
if (!FcInit()) return ret;
auto fc_instance = FcConfigReference(nullptr);
assert(fc_instance != nullptr);
/* Fontconfig doesn't handle full language isocodes, only the part
* before the _ of e.g. en_GB is used, so "remove" everything after
* the _. */
@ -168,6 +175,6 @@ bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode,
FcFontSetDestroy(fs);
}
FcFini();
FcConfigDestroy(fc_instance);
return ret;
}