Fix: Unable to choose a font containing hyphen. (#12684)

FcNameParse may require some characters be escaped. Instead, pass name as FC_FAMILY.
This commit is contained in:
Peter Nelson 2024-05-16 00:38:23 +01:00 committed by GitHub
parent d1b7619822
commit ca52da6c95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 2 deletions

View File

@ -55,8 +55,9 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
auto [font_family, font_style] = SplitFontFamilyAndStyle(font_name);
/* Resolve the name and populate the information structure */
FcPattern *pat = FcNameParse((FcChar8 *)font_family.data());
if (!font_style.empty()) FcPatternAddString(pat, FC_STYLE, (FcChar8 *)font_style.data());
FcPattern *pat = FcPatternCreate();
if (!font_family.empty()) FcPatternAddString(pat, FC_FAMILY, reinterpret_cast<const FcChar8 *>(font_family.c_str()));
if (!font_style.empty()) FcPatternAddString(pat, FC_STYLE, reinterpret_cast<const FcChar8 *>(font_style.c_str()));
FcConfigSubstitute(nullptr, pat, FcMatchPattern);
FcDefaultSubstitute(pat);
FcFontSet *fs = FcFontSetCreate();