]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccfg.c
Change files from ISO-Latin-1 to UTF-8
[fontconfig.git] / src / fccfg.c
index f393c79bf73fd6bdbabf51b11ed278e2195ae990..079e18c25514604c9b66784169606dd70289ef81 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $RCSId: xc/lib/fontconfig/src/fccfg.c,v 1.23 2002/08/31 22:17:32 keithp Exp $
  *
- * Copyright © 2000 Keith Packard
+ * 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
@@ -67,10 +67,43 @@ FcConfigCreate (void)
     if (!config->rejectGlobs)
        goto bail5;
 
+    config->acceptPatterns = FcFontSetCreate ();
+    if (!config->acceptPatterns)
+       goto bail6;
+    
+    config->rejectPatterns = FcFontSetCreate ();
+    if (!config->rejectPatterns)
+       goto bail7;
+
     config->cache = 0;
     if (FcConfigHome())
        if (!FcConfigSetCache (config, (FcChar8 *) ("~/" FC_USER_CACHE_FILE)))
-           goto bail6;
+           goto bail8;
+
+#ifdef _WIN32
+    if (config->cache == 0)
+    {
+       /* If no home, use the temp folder. */
+       FcChar8     dummy[1];
+       int         templen = GetTempPath (1, dummy);
+       FcChar8     *temp = malloc (templen + 1);
+
+       if (temp)
+       {
+           FcChar8 *cache_dir;
+
+           GetTempPath (templen + 1, temp);
+           cache_dir = FcStrPlus (temp, FC_USER_CACHE_FILE);
+           free (temp);
+           if (!FcConfigSetCache (config, cache_dir))
+           {
+               FcStrFree (cache_dir);
+               goto bail6;
+           }
+           FcStrFree (cache_dir);
+       }
+    }
+#endif
 
     config->blanks = 0;
 
@@ -85,6 +118,10 @@ FcConfigCreate (void)
     
     return config;
 
+bail8:
+    FcFontSetDestroy (config->rejectPatterns);
+bail7:
+    FcFontSetDestroy (config->acceptPatterns);
 bail6:
     FcStrSetDestroy (config->rejectGlobs);
 bail5:
@@ -120,7 +157,10 @@ FcConfigNewestFile (FcStrSet *files)
        while ((file = FcStrListNext (list)))
            if (stat ((char *) file, &statb) == 0)
                if (!newest.set || statb.st_mtime - newest.time > 0)
+               {
+                   newest.set = FcTrue;
                    newest.time = statb.st_mtime;
+               }
        FcStrListDone (list);
     }
     return newest;
@@ -138,9 +178,9 @@ FcConfigUptoDate (FcConfig *config)
            return FcFalse;
     }
     config_time = FcConfigNewestFile (config->configFiles);
-    font_time = FcConfigNewestFile (config->configDirs);
+    font_time = FcConfigNewestFile (config->fontDirs);
     if ((config_time.set && config_time.time - config->rescanTime > 0) ||
-       (font_time.set && font_time.time - config->rescanTime) > 0)
+       (font_time.set && (font_time.time - config->rescanTime) > 0))
     {
        return FcFalse;
     }
@@ -179,6 +219,8 @@ FcConfigDestroy (FcConfig *config)
     FcStrSetDestroy (config->configFiles);
     FcStrSetDestroy (config->acceptGlobs);
     FcStrSetDestroy (config->rejectGlobs);
+    FcFontSetDestroy (config->acceptPatterns);
+    FcFontSetDestroy (config->rejectPatterns);
 
     if (config->blanks)
        FcBlanksDestroy (config->blanks);
@@ -637,7 +679,7 @@ FcConfigCompareValue (const FcValue left_o,
                ret = FcLangSetContains (left.u.l, right.u.l);
                break;
            case FcOpNotContains:
-               ret = FcLangSetContains (left.u.l, right.u.l);
+               ret = !FcLangSetContains (left.u.l, right.u.l);
                break;
            case FcOpEqual:
                ret = FcLangSetEqual (left.u.l, right.u.l);
@@ -1809,3 +1851,40 @@ FcConfigAcceptFilename (FcConfig *config,
        return FcFalse;
     return FcTrue;
 }
+
+/*
+ * Manage font-pattern based font source selectors
+ */
+
+FcBool
+FcConfigPatternsAdd (FcConfig  *config,
+                    FcPattern  *pattern,
+                    FcBool     accept)
+{
+    FcFontSet  *set = accept ? config->acceptPatterns : config->rejectPatterns;
+
+    return FcFontSetAdd (set, pattern);
+}
+
+static FcBool
+FcConfigPatternsMatch (const FcFontSet *patterns,
+                      const FcPattern  *font)
+{
+    int i;
+    
+    for (i = 0; i < patterns->nfont; i++)
+       if (FcListPatternMatchAny (patterns->fonts[i], font))
+           return FcTrue;
+    return FcFalse;
+}
+
+FcBool
+FcConfigAcceptFont (FcConfig       *config,
+                   const FcPattern *font)
+{
+    if (FcConfigPatternsMatch (config->acceptPatterns, font))
+       return FcTrue;
+    if (FcConfigPatternsMatch (config->rejectPatterns, font))
+       return FcFalse;
+    return FcTrue;
+}