From 1aa8b700c3f09a31c78e7834e0db373f80b5e226 Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Tue, 2 Oct 2018 09:32:03 +0000 Subject: [PATCH] Add more prefix support in 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 --- src/fcxml.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) 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 @@ FcParseDir (FcConfigParse *parse) #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 element. please add prefix=\"cwd\" if current behavior is desired."); + } +#endif if (!data) { FcConfigMessage (parse, FcSevereError, "out of memory"); @@ -2153,6 +2173,11 @@ FcParseDir (FcConfigParse *parse) strcat ((char *) data, "\\"); strcat ((char *) data, "fonts"); } + else if (!attr) + { + if (!FcStrIsAbsoluteFilename (data) && data[0] != '~') + FcConfigMessage (parse, FcSevereWarning, "Use of ambiguous element. please add prefix=\"cwd\" if current behavior is desired."); + } #endif if (strlen ((char *) data) == 0) FcConfigMessage (parse, FcSevereWarning, "empty font directory name ignored");