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
diff --git a/src/fcxml.c b/src/fcxml.c
index 7797502..9d75249 100644
--- a/src/fcxml.c
+++ b/src/fcxml.c
@@ -2073,16 +2073,36 @@
#endif
attr = FcConfigGetAttribute (parse, "prefix");
- if (attr && FcStrCmp (attr, (const FcChar8 *)"xdg") == 0)
- {
- prefix = FcConfigXdgDataHome ();
- /* home directory might be disabled.
- * simply ignore this element.
- */
- if (!prefix)
- goto bail;
- }
data = FcStrBufDoneStatic (&parse->pstack->str);
+ if (attr)
+ {
+ if (FcStrCmp (attr, (const FcChar8 *)"xdg") == 0)
+ {
+ prefix = FcConfigXdgDataHome ();
+ /* home directory might be disabled.
+ * simply ignore this element.
+ */
+ if (!prefix)
+ goto bail;
+ }
+ 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)
{
FcConfigMessage (parse, FcSevereError, "out of memory");
@@ -2153,6 +2173,11 @@
strcat ((char *) data, "\\");
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
if (strlen ((char *) data) == 0)
FcConfigMessage (parse, FcSevereWarning, "empty font directory name ignored");