W32: Support cache paths relative to the root directory

Paths starting with '/' don't make sense on W32 as-is,
prepend the installation root directory to them.

This allows the cache to be contained within a particular
fontconfig installation (as long as the default
--with-cache-dir= is overriden at configure time).
This commit is contained in:
Руслан Ижбулатов 2015-04-08 08:41:25 +00:00 committed by Akira TAGOH
parent 7bc07cf6c2
commit f6e6a8a22b
2 changed files with 22 additions and 1 deletions

View File

@ -1843,6 +1843,7 @@ FcConfigSubstitute (FcConfig *config,
#if defined (_WIN32) #if defined (_WIN32)
static FcChar8 fontconfig_path[1000] = ""; /* MT-dontcare */ static FcChar8 fontconfig_path[1000] = ""; /* MT-dontcare */
FcChar8 fontconfig_instprefix[1000] = ""; /* MT-dontcare */
# if (defined (PIC) || defined (DLL_EXPORT)) # if (defined (PIC) || defined (DLL_EXPORT))
@ -1877,6 +1878,7 @@ DllMain (HINSTANCE hinstDLL,
if (p && (FcStrCmpIgnoreCase (p + 1, (const FcChar8 *) "bin") == 0 || if (p && (FcStrCmpIgnoreCase (p + 1, (const FcChar8 *) "bin") == 0 ||
FcStrCmpIgnoreCase (p + 1, (const FcChar8 *) "lib") == 0)) FcStrCmpIgnoreCase (p + 1, (const FcChar8 *) "lib") == 0))
*p = '\0'; *p = '\0';
strcat ((char *) fontconfig_instprefix, (char *) fontconfig_path);
strcat ((char *) fontconfig_path, "\\etc\\fonts"); strcat ((char *) fontconfig_path, "\\etc\\fonts");
} }
else else

View File

@ -54,6 +54,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <mbstring.h> #include <mbstring.h>
extern FcChar8 fontconfig_instprefix[];
#endif #endif
static void static void
@ -2187,7 +2188,25 @@ FcParseCacheDir (FcConfigParse *parse)
data = prefix; data = prefix;
} }
#ifdef _WIN32 #ifdef _WIN32
if (strcmp ((const char *) data, "WINDOWSTEMPDIR_FONTCONFIG_CACHE") == 0) else if (data[0] == '/' && fontconfig_instprefix[0] != '\0')
{
size_t plen = strlen ((const char *)fontconfig_instprefix);
size_t dlen = strlen ((const char *)data);
prefix = malloc (plen + 1 + dlen + 1);
if (!prefix)
{
FcConfigMessage (parse, FcSevereError, "out of memory");
goto bail;
}
strcpy ((char *) prefix, (char *) fontconfig_instprefix);
prefix[plen] = FC_DIR_SEPARATOR;
memcpy (&prefix[plen + 1], data, dlen);
prefix[plen + 1 + dlen] = 0;
FcStrFree (data);
data = prefix;
}
else if (strcmp ((const char *) data, "WINDOWSTEMPDIR_FONTCONFIG_CACHE") == 0)
{ {
int rc; int rc;
FcStrFree (data); FcStrFree (data);