config: font_parse(): handle font family names with \-:,

These characters have special meaning, and when they appear in the
font *family name*, they need to be escaped in the font pattern.

Before this patch, even if the user did escape them properly, _we_
un-escaped them in FcNameUnparse(), causing the wrong font to be
loaded later.
This commit is contained in:
Daniel Eklöf 2026-06-24 10:26:54 +02:00
parent ebaa878dce
commit 22ea71117c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -4123,7 +4123,25 @@ config_font_parse(const char *pattern, struct config_font *font)
FcPatternRemove(pat, FC_SIZE, 0);
FcPatternRemove(pat, FC_PIXEL_SIZE, 0);
char *stripped_pattern = (char *)FcNameUnparse(pat);
/* Only the family part, with '\', '-', ':' and ',' \-escaped */
FcChar8 *escaped_family = FcPatternFormat(
pat, (const FcChar8 *)"%{+family{%{family|escape(\\\\-:,)}}}");
/* Everything but the family, size and pixelsize */
FcChar8 *rest = FcPatternFormat(
pat, (const FcChar8 *)"%{-family,size,pixelsize{%{=unparse}}}");
char *stripped_pattern = NULL;
if (escaped_family == NULL || rest == NULL) {
free(escaped_family);
free(rest);
stripped_pattern = (char *)FcNameUnparse(pat);
} else {
stripped_pattern = xasprintf("%s%s", escaped_family, rest);
free(escaped_family);
free(rest);
}
FcPatternDestroy(pat);
LOG_DBG("%s: pt-size=%.2f, px-size=%d", stripped_pattern, pt_size, px_size);