]> git.wh0rd.org - fontconfig.git/commitdiff
Proper config path for static libraries in win32
authorDennis Schridde <lindevel@gmx.net>
Sun, 4 May 2008 02:45:31 +0000 (19:45 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 4 May 2008 02:45:31 +0000 (19:45 -0700)
Since fontconfig didn't have special handling for paths in static Windows
libraries, I've created a patch which should fix this.

Basically it does this:
fccfg.c:
If fontconfig_path was uninitialised it tries to get the directory the exe is
in and uses a fonts/ dir inside that.
fcxml.c:
In case the fonts.conf lists a <dir>CUSTOMFONTDIR</dir>, it searches for a
fonts/ directory where the exe is located.

src/fccfg.c
src/fcxml.c

index ed620a09d8b154aae3bba5efa14523a33dbed7a5..853eb7f37a738f7e312b378253194dc1270d2732 100644 (file)
@@ -1520,10 +1520,16 @@ FcConfigSubstitute (FcConfig    *config,
     return FcConfigSubstituteWithPat (config, p, 0, kind);
 }
 
-#if defined (_WIN32) && (defined (PIC) || defined (DLL_EXPORT))
+#if defined (_WIN32)
+
+#  define WIN32_LEAN_AND_MEAN
+#  define WIN32_EXTRA_LEAN
+#  include <windows.h>
 
 static FcChar8 fontconfig_path[1000] = "";
 
+#  if (defined (PIC) || defined (DLL_EXPORT))
+
 BOOL WINAPI
 DllMain (HINSTANCE hinstDLL,
         DWORD     fdwReason,
@@ -1561,12 +1567,12 @@ DllMain (HINSTANCE hinstDLL,
   return TRUE;
 }
 
+#  endif /* !PIC */
+
 #undef FONTCONFIG_PATH
 #define FONTCONFIG_PATH fontconfig_path
 
-#else /* !(_WIN32 && PIC) */
-
-#endif /* !(_WIN32 && PIC) */
+#endif /* !_WIN32 */
 
 #ifndef FONTCONFIG_FILE
 #define FONTCONFIG_FILE        "fonts.conf"
@@ -1651,6 +1657,16 @@ FcConfigGetPath (void)
        }
     }
     
+#ifdef _WIN32
+       if (fontconfig_path[0] == '\0')
+       {
+               if(!GetModuleFileName(NULL, fontconfig_path, sizeof(fontconfig_path)))
+                       goto bail1;
+               char *p = strrchr (fontconfig_path, '\\');
+               if (p) *p = '\0';
+               strcat (fontconfig_path, "\\fonts");
+       }
+#endif
     dir = (FcChar8 *) FONTCONFIG_PATH;
     path[i] = malloc (strlen ((char *) dir) + 1);
     if (!path[i])
@@ -1707,7 +1723,7 @@ FcChar8 *
 FcConfigFilename (const FcChar8 *url)
 {
     FcChar8    *file, *dir, **path, **p;
-    
+
     if (!url || !*url)
     {
        url = (FcChar8 *) getenv ("FONTCONFIG_FILE");
index 19103062e45a3522f3f81f198653e3ba018eb7b6..a2cc02eae263fda248693bb18c932439123df290 100644 (file)
@@ -2058,7 +2058,27 @@ FcEndElement(void *userData, const XML_Char *name)
            break;
        }
 #ifdef _WIN32
-       if (strcmp (data, "WINDOWSFONTDIR") == 0)
+       if (strcmp (data, "CUSTOMFONTDIR") == 0)
+       {
+               FcStrFree (data);
+               data = malloc (1000);
+               if (!data)
+               {
+                       FcConfigMessage (parse, FcSevereError, "out of memory");
+                       break;
+               }
+               FcMemAlloc (FC_MEM_STRING, 1000);
+               if(!GetModuleFileName(NULL, data, 1000))
+               {
+                       FcConfigMessage (parse, FcSevereError, "GetModuleFileName failed");
+                       FcStrFree (data);
+                       break;
+               }
+               char *p = strrchr (data, '\\');
+               if (p) *p = '\0';
+               strcat (data, "\\fonts");
+       }
+       else if (strcmp (data, "WINDOWSFONTDIR") == 0)
        {
            int rc;
            FcStrFree (data);