From da1e3f35e61597fbf58c9c550ceba6d44abb1563 Mon Sep 17 00:00:00 2001 From: Ondrej Balaz Date: Wed, 25 Jan 2023 05:00:57 +0900 Subject: Expand ~ in glob Allow ~ home directory expansion in acceptfont and rejectfont globs. Fixes: #347 --- doc/fontconfig-user.sgml | 3 ++- src/fccfg.c | 7 ++++++- src/fcxml.c | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/fontconfig-user.sgml b/doc/fontconfig-user.sgml index 16e98aa..0f18fce 100644 --- a/doc/fontconfig-user.sgml +++ b/doc/fontconfig-user.sgml @@ -396,7 +396,8 @@ pattern elements which are used to match fonts. <literal><glob></literal> Glob elements hold shell-style filename matching patterns (including ? and -*) which match fonts based on their complete pathnames. This can be used to +*) which match fonts based on their complete pathnames. If it starts with '~', +it refers to a directory in the users home directory. This can be used to exclude a set of directories (/usr/share/fonts/uglyfont*), or particular font file types (*.pcf.gz), but the latter mechanism relies rather heavily on filenaming conventions which can't be relied upon. Note that globs diff --git a/src/fccfg.c b/src/fccfg.c index 29124f5..f62e228 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -2923,8 +2923,13 @@ FcConfigGlobAdd (FcConfig *config, FcBool accept) { FcStrSet *set = accept ? config->acceptGlobs : config->rejectGlobs; + FcChar8 *realglob = FcStrCopyFilename(glob); + if (!realglob) + return FcFalse; - return FcStrSetAdd (set, glob); + FcBool ret = FcStrSetAdd (set, realglob); + FcStrFree(realglob); + return ret; } static FcBool diff --git a/src/fcxml.c b/src/fcxml.c index 74c892d..c700f64 100644 --- a/src/fcxml.c +++ b/src/fcxml.c @@ -2960,7 +2960,10 @@ FcParseAcceptRejectFont (FcConfigParse *parse, FcElement element) vstack->u.string, element == FcElementAcceptfont)) { - FcConfigMessage (parse, FcSevereError, "out of memory"); + if (FcStrUsesHome(vstack->u.string) && FcConfigHome() == NULL) + FcConfigMessage (parse, FcSevereWarning, "Home is disabled"); + else + FcConfigMessage (parse, FcSevereError, "out of memory"); } else { -- cgit v1.2.1