]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccfg.c
Fix "contains" op for strings and langsets.
[fontconfig.git] / src / fccfg.c
index 87c38bc9f0e0b3f78ff67ed0ea30419e729d5a24..cbb6ecbc8281a22d77df19e77615ce7eddb10f0c 100644 (file)
@@ -55,10 +55,18 @@ FcConfigCreate (void)
     if (!config->fontDirs)
        goto bail3;
     
+    config->acceptGlobs = FcStrSetCreate ();
+    if (!config->acceptGlobs)
+       goto bail4;
+
+    config->rejectGlobs = FcStrSetCreate ();
+    if (!config->rejectGlobs)
+       goto bail5;
+
     config->cache = 0;
     if (FcConfigHome())
        if (!FcConfigSetCache (config, (FcChar8 *) ("~/" FC_USER_CACHE_FILE)))
-           goto bail4;
+           goto bail6;
 
     config->blanks = 0;
 
@@ -73,6 +81,10 @@ FcConfigCreate (void)
     
     return config;
 
+bail6:
+    FcStrSetDestroy (config->rejectGlobs);
+bail5:
+    FcStrSetDestroy (config->acceptGlobs);
 bail4:
     FcStrSetDestroy (config->fontDirs);
 bail3:
@@ -159,6 +171,8 @@ FcConfigDestroy (FcConfig *config)
     FcStrSetDestroy (config->configDirs);
     FcStrSetDestroy (config->fontDirs);
     FcStrSetDestroy (config->configFiles);
+    FcStrSetDestroy (config->acceptGlobs);
+    FcStrSetDestroy (config->rejectGlobs);
 
     FcStrFree (config->cache);
 
@@ -203,7 +217,8 @@ FcConfigBuildFonts (FcConfig *config)
     {
        if (FcDebug () & FC_DBG_FONTSET)
            printf ("scan dir %s\n", dir);
-       FcDirScan (fonts, config->fontDirs, cache, config->blanks, dir, FcFalse);
+       FcDirScanConfig (fonts, config->fontDirs, cache, 
+                        config->blanks, dir, FcFalse, config);
     }
     
     FcStrListDone (list);
@@ -550,13 +565,17 @@ FcConfigCompareValue (const FcValue       m_o,
        case FcTypeString:
            switch (op) {
            case FcOpEqual:    
-           case FcOpContains:
                ret = FcStrCmpIgnoreCase (m.u.s, v.u.s) == 0;
                break;
+           case FcOpContains:
+               ret = FcStrStrIgnoreCase (m.u.s, v.u.s) != 0;
+               break;
            case FcOpNotEqual:
-           case FcOpNotContains:
                ret = FcStrCmpIgnoreCase (m.u.s, v.u.s) != 0;
                break;
+           case FcOpNotContains:
+               ret = FcStrStrIgnoreCase (m.u.s, v.u.s) == 0;
+               break;
            default:
                break;
            }
@@ -578,12 +597,12 @@ FcConfigCompareValue (const FcValue       m_o,
        case FcTypeCharSet:
            switch (op) {
            case FcOpContains:
-               /* m contains v if v is a subset of m */
-               ret = FcCharSetIsSubset (v.u.c, m.u.c);
+               /* v contains m if m is a subset of v */
+               ret = FcCharSetIsSubset (m.u.c, v.u.c);
                break;
            case FcOpNotContains:
-               /* m contains v if v is a subset of m */
-               ret = !FcCharSetIsSubset (v.u.c, m.u.c);
+               /* v contains m if m is a subset of v */
+               ret = !FcCharSetIsSubset (m.u.c, v.u.c);
                break;
            case FcOpEqual:
                ret = FcCharSetEqual (m.u.c, v.u.c);
@@ -598,16 +617,16 @@ FcConfigCompareValue (const FcValue       m_o,
        case FcTypeLangSet:
            switch (op) {
            case FcOpContains:
-               ret = FcLangSetContains (v.u.l, m.u.l);
+               ret = FcLangSetContains (m.u.l, v.u.l);
                break;
            case FcOpNotContains:
-               ret = FcLangSetContains (v.u.l, m.u.l);
+               ret = FcLangSetContains (m.u.l, v.u.l);
                break;
            case FcOpEqual:
-               ret = FcLangSetEqual (v.u.l, m.u.l);
+               ret = FcLangSetEqual (m.u.l, v.u.l);
                break;
            case FcOpNotEqual:
-               ret = !FcLangSetEqual (v.u.l, m.u.l);
+               ret = !FcLangSetEqual (m.u.l, v.u.l);
                break;
            default:
                break;
@@ -1232,6 +1251,14 @@ FcConfigSubstituteWithPat (FcConfig    *config,
                    !FcStrCmpIgnoreCase ((FcChar8 *) t->field, 
                                         (FcChar8 *) e->field))
                {
+                   /* 
+                    * KLUDGE - the pattern may have been reallocated or
+                    * things may have been inserted or deleted above
+                    * this element by other edits.  Go back and find
+                    * the element again
+                    */
+                   if (e != s->edit && st[i].elt)
+                       st[i].elt = FcPatternFindElt (p, t->field);
                    if (!st[i].elt)
                        t = 0;
                    break;
@@ -1612,7 +1639,7 @@ FcConfigAppFontAddFile (FcConfig    *config,
        FcConfigSetFonts (config, set, FcSetApplication);
     }
        
-    if (!FcFileScan (set, subdirs, 0, config->blanks, file, FcFalse))
+    if (!FcFileScanConfig (set, subdirs, 0, config->blanks, file, FcFalse, config))
     {
        FcStrSetDestroy (subdirs);
        return FcFalse;
@@ -1659,7 +1686,7 @@ FcConfigAppFontAddDir (FcConfig       *config,
        FcConfigSetFonts (config, set, FcSetApplication);
     }
     
-    if (!FcDirScan (set, subdirs, 0, config->blanks, dir, FcFalse))
+    if (!FcDirScanConfig (set, subdirs, 0, config->blanks, dir, FcFalse, config))
     {
        FcStrSetDestroy (subdirs);
        return FcFalse;
@@ -1680,3 +1707,76 @@ FcConfigAppFontClear (FcConfig       *config)
 {
     FcConfigSetFonts (config, 0, FcSetApplication);
 }
+
+/*
+ * Manage filename-based font source selectors
+ */
+
+FcBool
+FcConfigGlobAdd (FcConfig      *config,
+                const FcChar8  *glob,
+                FcBool         accept)
+{
+    FcStrSet   *set = accept ? config->acceptGlobs : config->rejectGlobs;
+
+    return FcStrSetAdd (set, glob);
+}
+
+static FcBool
+FcConfigGlobMatch (const FcChar8    *glob,
+                  const FcChar8    *string)
+{
+    FcChar8    c;
+
+    while ((c = *glob++)) 
+    {
+       switch (c) {
+       case '*':
+           /* short circuit common case */
+           if (!*glob)
+               return FcTrue;
+           /* short circuit another common case */
+           if (strchr ((char *) glob, '*') == 0)
+               string += strlen ((char *) string) - strlen ((char *) glob);
+           while (*string)
+           {
+               if (FcConfigGlobMatch (glob, string))
+                   return FcTrue;
+               string++;
+           }
+           return FcFalse;
+       case '?':
+           if (*string++ == '\0')
+               return FcFalse;
+           break;
+       default:
+           if (*string++ != c)
+               return FcFalse;
+           break;
+       }
+    }
+    return *string == '\0';
+}
+
+static FcBool
+FcConfigGlobsMatch (const FcStrSet     *globs,
+                   const FcChar8       *string)
+{
+    int        i;
+
+    for (i = 0; i < globs->num; i++)
+       if (FcConfigGlobMatch (globs->strs[i], string))
+           return FcTrue;
+    return FcFalse;
+}
+
+FcBool
+FcConfigAcceptFilename (FcConfig       *config,
+                       const FcChar8   *filename)
+{
+    if (FcConfigGlobsMatch (config->acceptGlobs, filename))
+       return FcTrue;
+    if (FcConfigGlobsMatch (config->rejectGlobs, filename))
+       return FcFalse;
+    return FcTrue;
+}