aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2026-06-24 08:26:54 +0000
committerDaniel Eklöf <daniel@ekloef.se>2026-06-24 08:26:54 +0000
commit22ea71117c75602e7bb4046c2e67d1be8a775af0 (patch)
tree8120ffa55ea9774f6cfccecf449ddf9b03b4c627 /config.c
parentnotify: fix crash in notify_done() when terminal has been closed before notification (diff)
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.
Diffstat (limited to 'config.c')
-rw-r--r--config.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/config.c b/config.c
index 481d4c4f..824a4ded 100644
--- a/config.c
+++ b/config.c
@@ -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);