Expand ~ in glob

Allow ~ home directory expansion in acceptfont and rejectfont globs.

Fixes: #347
This commit is contained in:
Ondrej Balaz 2023-01-25 05:00:57 +09:00
parent f7091cd17b
commit da1e3f35e6
3 changed files with 12 additions and 3 deletions

View File

@ -396,7 +396,8 @@ pattern elements which are used to match fonts.
</para></refsect2> </para></refsect2>
<refsect2><title><literal>&lt;glob&gt;</literal></title><para> <refsect2><title><literal>&lt;glob&gt;</literal></title><para>
Glob elements hold shell-style filename matching patterns (including ? and 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 exclude a set of directories (/usr/share/fonts/uglyfont*), or particular
font file types (*.pcf.gz), but the latter mechanism relies rather heavily font file types (*.pcf.gz), but the latter mechanism relies rather heavily
on filenaming conventions which can't be relied upon. Note that globs on filenaming conventions which can't be relied upon. Note that globs

View File

@ -2923,8 +2923,13 @@ FcConfigGlobAdd (FcConfig *config,
FcBool accept) FcBool accept)
{ {
FcStrSet *set = accept ? config->acceptGlobs : config->rejectGlobs; 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 static FcBool

View File

@ -2960,7 +2960,10 @@ FcParseAcceptRejectFont (FcConfigParse *parse, FcElement element)
vstack->u.string, vstack->u.string,
element == FcElementAcceptfont)) 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 else
{ {