Add more prefix support in <dir> element

Added two prefix modes:
  "relative" that makes the relative path be relative to current file
  "cwd" for relative to current working directory which implies current behavior.

Resolves: https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/15
This commit is contained in:
Akira TAGOH 2018-10-02 09:32:03 +00:00
parent f0aae4455e
commit 1aa8b700c3
1 changed files with 34 additions and 9 deletions

View File

@ -2073,7 +2073,10 @@ FcParseDir (FcConfigParse *parse)
#endif #endif
attr = FcConfigGetAttribute (parse, "prefix"); attr = FcConfigGetAttribute (parse, "prefix");
if (attr && FcStrCmp (attr, (const FcChar8 *)"xdg") == 0) data = FcStrBufDoneStatic (&parse->pstack->str);
if (attr)
{
if (FcStrCmp (attr, (const FcChar8 *)"xdg") == 0)
{ {
prefix = FcConfigXdgDataHome (); prefix = FcConfigXdgDataHome ();
/* home directory might be disabled. /* home directory might be disabled.
@ -2082,7 +2085,24 @@ FcParseDir (FcConfigParse *parse)
if (!prefix) if (!prefix)
goto bail; goto bail;
} }
data = FcStrBufDoneStatic (&parse->pstack->str); else if (FcStrCmp (attr, (const FcChar8 *)"cwd") == 0)
{
}
else if (FcStrCmp (attr, (const FcChar8 *)"relative") == 0)
{
prefix = FcStrDirname (parse->name);
if (!prefix)
goto bail;
}
}
#ifndef _WIN32
/* For Win32, check this later for dealing with special cases */
else
{
if (!FcStrIsAbsoluteFilename (data) && data[0] != '~')
FcConfigMessage (parse, FcSevereWarning, "Use of ambiguous <dir> element. please add prefix=\"cwd\" if current behavior is desired.");
}
#endif
if (!data) if (!data)
{ {
FcConfigMessage (parse, FcSevereError, "out of memory"); FcConfigMessage (parse, FcSevereError, "out of memory");
@ -2153,6 +2173,11 @@ FcParseDir (FcConfigParse *parse)
strcat ((char *) data, "\\"); strcat ((char *) data, "\\");
strcat ((char *) data, "fonts"); strcat ((char *) data, "fonts");
} }
else if (!attr)
{
if (!FcStrIsAbsoluteFilename (data) && data[0] != '~')
FcConfigMessage (parse, FcSevereWarning, "Use of ambiguous <dir> element. please add prefix=\"cwd\" if current behavior is desired.");
}
#endif #endif
if (strlen ((char *) data) == 0) if (strlen ((char *) data) == 0)
FcConfigMessage (parse, FcSevereWarning, "empty font directory name ignored"); FcConfigMessage (parse, FcSevereWarning, "empty font directory name ignored");