]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccfg.c
Revert ill-advised addition of FC_RENDER. Add strategy for handling objects
[fontconfig.git] / src / fccfg.c
index 079e18c25514604c9b66784169606dd70289ef81..5d6339f65af9102b828000ece797127dffa5bb2d 100644 (file)
@@ -247,9 +247,10 @@ FcConfigDestroy (FcConfig *config)
 FcBool
 FcConfigBuildFonts (FcConfig *config)
 {
-    FcFontSet      *fonts;
+    FcFontSet      *fonts, *cached_fonts;
     FcGlobalCache   *cache;
     FcStrList      *list;
+    FcStrSet       *oldDirs;
     FcChar8        *dir;
 
     fonts = FcFontSetCreate ();
@@ -260,22 +261,53 @@ FcConfigBuildFonts (FcConfig *config)
     if (!cache)
        goto bail1;
 
-    if (config->cache)
-       FcGlobalCacheLoad (cache, config->cache);
+    oldDirs = FcStrSetCreate ();
+    if (!oldDirs)
+        goto bail2;
 
-    list = FcConfigGetFontDirs (config);
-    if (!list)
-       goto bail1;
+    if (config->cache)
+       FcGlobalCacheLoad (cache, oldDirs, config->cache);
 
-    while ((dir = FcStrListNext (list)))
+    cached_fonts = FcCacheRead(config, cache);
+    if (!cached_fonts)
     {
-       if (FcDebug () & FC_DBG_FONTSET)
-           printf ("scan dir %s\n", dir);
-       FcDirScanConfig (fonts, config->fontDirs, cache, 
-                        config->blanks, dir, FcFalse, config);
+       list = FcConfigGetFontDirs (config);
+       if (!list)
+           goto bail2;
+       
+       while ((dir = FcStrListNext (list)))
+       {
+           if (FcDebug () & FC_DBG_FONTSET)
+               printf ("build scan dir %s\n", dir);
+           FcDirScanConfig (fonts, config->fontDirs, cache, 
+                            config->blanks, dir, FcFalse, config);
+       }
+       
+       FcStrListDone (list);
+    }
+    else
+    {
+       int i;
+
+        for (i = 0; i < oldDirs->num; i++)
+        {
+           if (FcDebug () & FC_DBG_FONTSET)
+               printf ("scan dir %s\n", oldDirs->strs[i]);
+           FcDirScanConfig (fonts, config->fontDirs, cache, 
+                            config->blanks, oldDirs->strs[i], 
+                             FcFalse, config);
+       }
+
+       for (i = 0; i < cached_fonts->nfont; i++)
+       {
+           if (FcConfigAcceptFont (config, cached_fonts->fonts[i]))
+               FcFontSetAdd (fonts, cached_fonts->fonts[i]);
+
+           cached_fonts->fonts[i] = 0; /* prevent free in FcFontSetDestroy */
+       }
+       cached_fonts->nfont = 0;
+       FcFontSetDestroy (cached_fonts);
     }
-    
-    FcStrListDone (list);
     
     if (FcDebug () & FC_DBG_FONTSET)
        FcFontSetPrint (fonts);
@@ -283,10 +315,13 @@ FcConfigBuildFonts (FcConfig *config)
     if (config->cache)
        FcGlobalCacheSave (cache, config->cache);
     FcGlobalCacheDestroy (cache);
+    FcStrSetDestroy (oldDirs);
 
     FcConfigSetFonts (config, fonts, FcSetSystem);
     
     return FcTrue;
+bail2:
+    FcStrSetDestroy (oldDirs);
 bail1:
     FcFontSetDestroy (fonts);
 bail0:
@@ -562,12 +597,12 @@ FcConfigPromote (FcValue v, FcValue u)
 }
 
 FcBool
-FcConfigCompareValue (const FcValue    left_o,
+FcConfigCompareValue (const FcValue    *left_o,
                      FcOp              op,
-                     const FcValue     right_o)
+                     const FcValue     *right_o)
 {
-    FcValue    left = left_o;
-    FcValue    right = right_o;
+    FcValue    left = FcValueCanonicalize(left_o);
+    FcValue    right = FcValueCanonicalize(right_o);
     FcBool     ret = FcFalse;
     
     left = FcConfigPromote (left, right);
@@ -629,9 +664,11 @@ FcConfigCompareValue (const FcValue        left_o,
                ret = FcStrStrIgnoreCase (left.u.s, right.u.s) != 0;
                break;
            case FcOpNotEqual:
-           case FcOpNotContains:
                ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) != 0;
                break;
+           case FcOpNotContains:
+               ret = FcStrCmpIgnoreCase (left.u.s, right.u.s) == 0;
+               break;
            default:
                break;
            }
@@ -753,7 +790,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
        break;
     case FcOpString:
        v.type = FcTypeString;
-       v.u.s = e->u.sval;
+       v.u.s = FcStrStaticName(e->u.sval);
        v = FcValueSave (v);
        break;
     case FcOpMatrix:
@@ -806,7 +843,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
        vl = FcConfigEvaluate (p, e->u.tree.left);
        vr = FcConfigEvaluate (p, e->u.tree.right);
        v.type = FcTypeBool;
-       v.u.b = FcConfigCompareValue (vl, e->op, vr);
+       v.u.b = FcConfigCompareValue (&vl, e->op, &vr);
        FcValueDestroy (vl);
        FcValueDestroy (vr);
        break;  
@@ -871,7 +908,8 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
                switch (e->op) {
                case FcOpPlus:
                    v.type = FcTypeString;
-                   v.u.s = FcStrPlus (vl.u.s, vr.u.s);
+                   v.u.s = FcStrStaticName (FcStrPlus (vl.u.s, vr.u.s));
+                        
                    if (!v.u.s)
                        v.type = FcTypeVoid;
                    break;
@@ -1019,10 +1057,10 @@ FcConfigMatchValueList (FcPattern       *p,
            e = 0;
        }
 
-       for (v = values; v; v = v->next)
+       for (v = values; v; v = FcValueListPtrU(v->next))
        {
            /* Compare the pattern value to the match expression value */
-           if (FcConfigCompareValue (v->value, t->op, value))
+           if (FcConfigCompareValue (&v->value, t->op, &value))
            {
                if (!ret)
                    ret = v;
@@ -1045,6 +1083,7 @@ static FcValueList *
 FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding)
 {
     FcValueList        *l;
+    FcValueListPtr lp;
     
     if (!e)
        return 0;
@@ -1055,56 +1094,63 @@ FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding)
     if (e->op == FcOpComma)
     {
        l->value = FcConfigEvaluate (p, e->u.tree.left);
-       l->next  = FcConfigValues (p, e->u.tree.right, binding);
+       l->next  = FcValueListPtrCreateDynamic(FcConfigValues (p, e->u.tree.right, binding));
     }
     else
     {
        l->value = FcConfigEvaluate (p, e);
-       l->next  = 0;
+       l->next  = FcValueListPtrCreateDynamic(0);
     }
     l->binding = binding;
-    while (l && l->value.type == FcTypeVoid)
+    lp = FcValueListPtrCreateDynamic(l);
+    while (FcValueListPtrU(lp) && FcValueListPtrU(lp)->value.type == FcTypeVoid)
     {
-       FcValueList     *next = l->next;
-       
-       FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
-       free (l);
-       l = next;
+       FcValueListPtr  next = FcValueListPtrU(lp)->next;
+
+       if (lp.bank == FC_BANK_DYNAMIC)
+       {
+           FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList));
+           free (l);
+       }
+       lp = next;
     }
     return l;
 }
 
 static FcBool
-FcConfigAdd (FcValueList    **head,
+FcConfigAdd (FcValueListPtr *head,
             FcValueList    *position,
             FcBool         append,
             FcValueList    *new)
 {
-    FcValueList            **prev, *last, *v;
+    FcValueListPtr  *prev, last, v;
     FcValueBinding  sameBinding;
     
     if (position)
        sameBinding = position->binding;
     else
        sameBinding = FcValueBindingWeak;
-    for (v = new; v; v = v->next)
-       if (v->binding == FcValueBindingSame)
-           v->binding = sameBinding;
+    for (v = FcValueListPtrCreateDynamic(new); FcValueListPtrU(v); 
+        v = FcValueListPtrU(v)->next)
+       if (FcValueListPtrU(v)->binding == FcValueBindingSame)
+           FcValueListPtrU(v)->binding = sameBinding;
     if (append)
     {
        if (position)
            prev = &position->next;
        else
-           for (prev = head; *prev; prev = &(*prev)->next)
+           for (prev = head; FcValueListPtrU(*prev); 
+                prev = &(FcValueListPtrU(*prev)->next))
                ;
     }
     else
     {
        if (position)
        {
-           for (prev = head; *prev; prev = &(*prev)->next)
+           for (prev = head; FcValueListPtrU(*prev); 
+                prev = &(FcValueListPtrU(*prev)->next))
            {
-               if (*prev == position)
+               if (FcValueListPtrU(*prev) == position)
                    break;
            }
        }
@@ -1113,7 +1159,7 @@ FcConfigAdd (FcValueList    **head,
 
        if (FcDebug () & FC_DBG_EDIT)
        {
-           if (!*prev)
+           if (!FcValueListPtrU(*prev))
                printf ("position not on list\n");
        }
     }
@@ -1127,12 +1173,12 @@ FcConfigAdd (FcValueList    **head,
     
     if (new)
     {
-       last = new;
-       while (last->next)
-           last = last->next;
+       last = FcValueListPtrCreateDynamic(new);
+       while (FcValueListPtrU(FcValueListPtrU(last)->next))
+           last = FcValueListPtrU(last)->next;
     
-       last->next = *prev;
-       *prev = new;
+       FcValueListPtrU(last)->next = *prev;
+       *prev = FcValueListPtrCreateDynamic(new);
     }
     
     if (FcDebug () & FC_DBG_EDIT)
@@ -1146,18 +1192,19 @@ FcConfigAdd (FcValueList    **head,
 }
 
 static void
-FcConfigDel (FcValueList    **head,
+FcConfigDel (FcValueListPtr *head,
             FcValueList    *position)
 {
-    FcValueList    **prev;
+    FcValueListPtr *prev;
 
-    for (prev = head; *prev; prev = &(*prev)->next)
+    for (prev = head; FcValueListPtrU(*prev); 
+        prev = &(FcValueListPtrU(*prev)->next))
     {
-       if (*prev == position)
+       if (FcValueListPtrU(*prev) == position)
        {
            *prev = position->next;
-           position->next = 0;
-           FcValueListDestroy (position);
+           position->next = FcValueListPtrCreateDynamic(0);
+           FcValueListDestroy (FcValueListPtrCreateDynamic(position));
            break;
        }
     }
@@ -1189,8 +1236,8 @@ FcConfigPatternDel (FcPattern     *p,
     FcPatternElt    *e = FcPatternFindElt (p, object);
     if (!e)
        return;
-    while (e->values)
-       FcConfigDel (&e->values, e->values);
+    while (FcValueListPtrU(e->values))
+       FcConfigDel (&e->values, FcValueListPtrU(e->values));
 }
 
 static void
@@ -1200,7 +1247,7 @@ FcConfigPatternCanon (FcPattern       *p,
     FcPatternElt    *e = FcPatternFindElt (p, object);
     if (!e)
        return;
-    if (!e->values)
+    if (!FcValueListPtrU(e->values))
        FcPatternDel (p, object);
 }
 
@@ -1279,12 +1326,12 @@ FcConfigSubstituteWithPat (FcConfig    *config,
             * Check to see if there is a match, mark the location
             * to apply match-relative edits
             */
-           st[i].value = FcConfigMatchValueList (m, t, st[i].elt->values);
+           st[i].value = FcConfigMatchValueList (m, t, FcValueListPtrU(st[i].elt->values));
            if (!st[i].value)
                break;
-           if (t->qual == FcQualFirst && st[i].value != st[i].elt->values)
+           if (t->qual == FcQualFirst && st[i].value != FcValueListPtrU(st[i].elt->values))
                break;
-           if (t->qual == FcQualNotFirst && st[i].value == st[i].elt->values)
+           if (t->qual == FcQualNotFirst && st[i].value == FcValueListPtrU(st[i].elt->values))
                break;
        }
        if (t)
@@ -1337,7 +1384,7 @@ FcConfigSubstituteWithPat (FcConfig    *config,
                if (t)
                {
                    FcValueList *thisValue = st[i].value;
-                   FcValueList *nextValue = thisValue ? thisValue->next : 0;
+                   FcValueList *nextValue = thisValue ? FcValueListPtrU(thisValue->next) : 0;
                    
                    /*
                     * Append the new list of values after the current value
@@ -1503,7 +1550,9 @@ FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
 #ifdef _WIN32
     if ((!path[0] || (path[strlen((char *) path)-1] != '/' &&
                      path[strlen((char *) path)-1] != '\\')) &&
-        (file[0] != '/' && file[0] != '\\'))
+       !(file[0] == '/' ||
+         file[0] == '\\' ||
+         (isalpha (file[0]) && file[1] == ':' && (file[2] == '/' || file[2] == '\\'))))
        strcat ((char *) path, "\\");
 #else
     if ((!path[0] || path[strlen((char *) path)-1] != '/') && file[0] != '/')
@@ -1603,7 +1652,7 @@ FcConfigHome (void)
            home = getenv ("USERPROFILE");
 #endif
 
-       return home;
+       return (FcChar8 *) home;
     }
     return 0;
 }