/*
- * $XFree86: xc/lib/fontconfig/src/fccfg.c,v 1.23 2002/08/31 22:17:32 keithp Exp $
+ * $RCSId: xc/lib/fontconfig/src/fccfg.c,v 1.23 2002/08/31 22:17:32 keithp Exp $
*
- * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
+ * Copyright © 2000 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
#include "fcint.h"
+#if defined (_WIN32) && defined (PIC)
+#define STRICT
+#include <windows.h>
+#undef STRICT
+#endif
+
FcConfig *_fcConfig;
FcConfig *
goto bail3;
config->cache = 0;
- if (!FcConfigSetCache (config, (FcChar8 *) ("~/" FC_USER_CACHE_FILE)))
- goto bail4;
+ if (FcConfigHome())
+ if (!FcConfigSetCache (config, (FcChar8 *) ("~/" FC_USER_CACHE_FILE)))
+ goto bail4;
config->blanks = 0;
while (s)
{
n = s->next;
- FcTestDestroy (s->test);
- FcEditDestroy (s->edit);
+ if (s->test)
+ FcTestDestroy (s->test);
+ if (s->edit)
+ FcEditDestroy (s->edit);
s = n;
}
}
case FcTypeLangSet:
switch (op) {
case FcOpContains:
- ret = FcLangSetCompare (v.u.l, m.u.l) != FcLangDifferentLang;
+ ret = FcLangSetContains (v.u.l, m.u.l);
break;
case FcOpNotContains:
- ret = FcLangSetCompare (v.u.l, m.u.l) == FcLangDifferentLang;
+ ret = FcLangSetContains (v.u.l, m.u.l);
break;
case FcOpEqual:
ret = FcLangSetEqual (v.u.l, m.u.l);
return FcConfigSubstituteWithPat (config, p, 0, kind);
}
+#if defined (_WIN32) && defined (PIC)
+
+static FcChar8 fontconfig_path[1000] = "";
+
+BOOL WINAPI
+DllMain (HINSTANCE hinstDLL,
+ DWORD fdwReason,
+ LPVOID lpvReserved)
+{
+ FcChar8 *p;
+
+ switch (fdwReason) {
+ case DLL_PROCESS_ATTACH:
+ if (!GetModuleFileName ((HMODULE) hinstDLL, fontconfig_path,
+ sizeof (fontconfig_path)))
+ break;
+
+ /* If the fontconfig DLL is in a "bin" or "lib" subfolder,
+ * assume it's a Unix-style installation tree, and use
+ * "etc/fonts" in there as FONTCONFIG_PATH. Otherwise use the
+ * folder where the DLL is as FONTCONFIG_PATH.
+ */
+ p = strrchr (fontconfig_path, '\\');
+ if (p)
+ {
+ *p = '\0';
+ p = strrchr (fontconfig_path, '\\');
+ if (p && (FcStrCmpIgnoreCase (p + 1, "bin") == 0 ||
+ FcStrCmpIgnoreCase (p + 1, "lib") == 0))
+ *p = '\0';
+ strcat (fontconfig_path, "\\etc\\fonts");
+ }
+ else
+ fontconfig_path[0] = '\0';
+
+ break;
+ }
+
+ return TRUE;
+}
+
+#undef FONTCONFIG_PATH
+#define FONTCONFIG_PATH fontconfig_path
+
+#else /* !(_WIN32 && PIC) */
+
#ifndef FONTCONFIG_PATH
#define FONTCONFIG_PATH "/etc/fonts"
#endif
+#endif /* !(_WIN32 && PIC) */
+
#ifndef FONTCONFIG_FILE
#define FONTCONFIG_FILE "fonts.conf"
#endif
return 0;
strcpy ((char *) path, (const char *) dir);
- /* make sure there's a single separating / */
+ /* make sure there's a single separator */
+#ifdef _WIN32
+ if ((!path[0] || (path[strlen((char *) path)-1] != '/' &&
+ path[strlen((char *) path)-1] != '\\')) &&
+ (file[0] != '/' && file[0] != '\\'))
+ strcat ((char *) path, "\\");
+#else
if ((!path[0] || path[strlen((char *) path)-1] != '/') && file[0] != '/')
strcat ((char *) path, "/");
+#endif
strcat ((char *) path, (char *) file);
FcMemAlloc (FC_MEM_STRING, strlen ((char *) path) + 1);
e = env;
npath++;
while (*e)
- if (*e++ == ':')
+ if (*e++ == FC_SEARCH_PATH_SEPARATOR)
npath++;
}
path = calloc (npath, sizeof (FcChar8 *));
e = env;
while (*e)
{
- colon = (FcChar8 *) strchr ((char *) e, ':');
+ colon = (FcChar8 *) strchr ((char *) e, FC_SEARCH_PATH_SEPARATOR);
if (!colon)
colon = e + strlen ((char *) e);
path[i] = malloc (colon - e + 1);
free (path);
}
+static FcBool _FcConfigHomeEnabled = FcTrue;
+
+FcChar8 *
+FcConfigHome (void)
+{
+ if (_FcConfigHomeEnabled)
+ {
+ char *home = getenv ("HOME");
+
+#ifdef _WIN32
+ if (home == NULL)
+ home = getenv ("USERPROFILE");
+#endif
+
+ return home;
+ }
+ return 0;
+}
+
+FcBool
+FcConfigEnableHome (FcBool enable)
+{
+ FcBool prev = _FcConfigHomeEnabled;
+ _FcConfigHomeEnabled = enable;
+ return prev;
+}
+
FcChar8 *
FcConfigFilename (const FcChar8 *url)
{
url = (FcChar8 *) FONTCONFIG_FILE;
}
file = 0;
+
+#ifdef _WIN32
+ if (isalpha (*url) &&
+ url[1] == ':' &&
+ (url[2] == '/' || url[2] == '\\'))
+ goto absolute_path;
+#endif
+
switch (*url) {
case '~':
- dir = (FcChar8 *) getenv ("HOME");
+ dir = FcConfigHome ();
if (dir)
file = FcConfigFileExists (dir, url + 1);
else
file = 0;
break;
+#ifdef _WIN32
+ case '\\':
+ absolute_path:
+#endif
case '/':
file = FcConfigFileExists (0, url);
break;