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

FcNameParse may require some characters be escaped. Instead, pass name as FC_FAMILY.

(cherry picked from commit ca52da6c95)
This commit is contained in:
Peter Nelson 2024-05-16 00:38:23 +01:00 committed by Jonathan G Rennison
parent c5f49ba0e8
commit 06b84f7c00

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();