]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcmatch.c
Revert to original FcFontSetMatch algorithm to avoid losing fonts.
[fontconfig.git] / src / fcmatch.c
index 74829a70b8dc84be6fde4bf7389c8202bd268291..739ef3e28d4b8e6593d905d7d33c2be917a75ebd 100644 (file)
@@ -22,9 +22,9 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include "fcint.h"
 #include <string.h>
 #include <ctype.h>
-#include "fcint.h"
 #include <stdio.h>
 
 static double
@@ -267,25 +267,12 @@ FcMatchObjectPtrsInit (void)
     matchObjectPtrsInit = FcTrue;
 }
 
-static FcBool
-FcCompareValueList (FcObjectPtr o,
-                   FcValueListPtr v1orig,      /* pattern */
-                   FcValueListPtr v2orig,      /* target */
-                   FcValue     *bestValue,
-                   double      *value,
-                   FcResult    *result)
+static FcMatcher*
+FcObjectPtrToMatcher (FcObjectPtr o)
 {
-    FcValueListPtr  v1, v2;
-    FcValueList     *v1_ptrU, *v2_ptrU;
-    double         v, best, bestStrong, bestWeak;
-    int                    i;
-    int                    j;
-    const char     *object = FcObjectPtrU(o);
+    int        i;
+    const char  *object = FcObjectPtrU(o);
 
-    /*
-     * Locate the possible matching entry by examining the
-     * first few characters in object
-     */
     i = -1;
     switch (object[0]) {
     case 'f':
@@ -334,18 +321,40 @@ FcCompareValueList (FcObjectPtr o,
        i = MATCH_OUTLINE; break;
     }
 
+    if (i < 0)
+       return 0;
+
     if (!matchObjectPtrsInit)
         FcMatchObjectPtrsInit();
-    if (_FcMatchers[i].objectPtr != o) i = -1;
 
-    if (i == -1 || 
-       FcStrCmpIgnoreCase ((FcChar8 *) _FcMatchers[i].object,
-                           (FcChar8 *) object) != 0)
+    if (o != _FcMatchers[i].objectPtr)
+       return 0;
+
+    return _FcMatchers+i;
+}
+
+static FcBool
+FcCompareValueList (FcObjectPtr o,
+                   FcValueListPtr v1orig,      /* pattern */
+                   FcValueListPtr v2orig,      /* target */
+                   FcValue     *bestValue,
+                   double      *value,
+                   FcResult    *result)
+{
+    FcValueListPtr  v1, v2;
+    FcValueList     *v1_ptrU, *v2_ptrU;
+    double         v, best, bestStrong, bestWeak;
+    int                    j;
+    const char     *object = FcObjectPtrU(o);
+    FcMatcher       *match = FcObjectPtrToMatcher(o);
+
+    if (!match)
     {
        if (bestValue)
            *bestValue = FcValueCanonicalize(&FcValueListPtrU(v2orig)->value);
        return FcTrue;
     }
+
     best = 1e99;
     bestStrong = 1e99;
     bestWeak = 1e99;
@@ -356,8 +365,7 @@ FcCompareValueList (FcObjectPtr o,
        for (v2 = v2orig, v2_ptrU = FcValueListPtrU(v2); v2_ptrU;
             v2 = v2_ptrU->next, v2_ptrU = FcValueListPtrU(v2))
        {
-           v = (*_FcMatchers[i].compare) (&v1_ptrU->value,
-                                          &v2_ptrU->value);
+           v = (match->compare) (&v1_ptrU->value, &v2_ptrU->value);
            if (v < 0)
            {
                *result = FcResultTypeMismatch;
@@ -393,8 +401,8 @@ FcCompareValueList (FcObjectPtr o,
     }
     if (value)
     {
-       int weak    = _FcMatchers[i].weak;
-       int strong  = _FcMatchers[i].strong;
+       int weak    = match->weak;
+       int strong  = match->strong;
        if (weak == strong)
            value[strong] += best;
        else
@@ -487,9 +495,6 @@ FcFontRenderPrepare (FcConfig           *config,
                           FcValueCanonicalize(&FcValueListPtrU(pe->values)->value), FcTrue);
     }
 
-    if (FcPatternFindElt (font, FC_FILE))
-       FcPatternTransferFullFname (new, font);
-
     FcConfigSubstituteWithPat (config, new, pat, FcMatchFont);
     return new;
 }
@@ -520,10 +525,7 @@ FcFontSetMatch (FcConfig    *config,
     {
        config = FcConfigGetCurrent ();
        if (!config)
-       {
-           *result = FcResultOutOfMemory;
            return 0;
-       }
     }
     for (set = 0; set < nsets; set++)
     {
@@ -621,7 +623,7 @@ FcSortCompare (const void *aa, const void *ab)
 }
 
 static FcBool
-FcSortWalk (FcSortNode **n, int nnode, FcFontSet *fs, FcCharSet **cs, FcBool trim)
+FcSortWalk (FcSortNode **n, int nnode, FcFontSet *fs, FcCharSet **cs, FcBool trim, FcBool build_cs)
 {
     FcCharSet  *ncs;
     FcSortNode *node;
@@ -638,16 +640,20 @@ FcSortWalk (FcSortNode **n, int nnode, FcFontSet *fs, FcCharSet **cs, FcBool tri
             */
            if (!trim || !*cs || !FcCharSetIsSubset (ncs, *cs))
            {
-               if (*cs)
-               {
-                   ncs = FcCharSetUnion (ncs, *cs);
-                   if (!ncs)
-                       return FcFalse;
-                   FcCharSetDestroy (*cs);
-               }
-               else
-                   ncs = FcCharSetCopy (ncs);
-               *cs = ncs;
+                if (trim || build_cs)
+                {
+                    if (*cs)
+                    {
+                        ncs = FcCharSetUnion (ncs, *cs);
+                        if (!ncs)
+                            return FcFalse;
+                        FcCharSetDestroy (*cs);
+                    }
+                    else
+                        ncs = FcCharSetCopy (ncs);
+                    *cs = ncs;
+                }
+
                FcPatternReference (node->pattern);
                if (FcDebug () & FC_DBG_MATCH)
                {
@@ -816,13 +822,16 @@ FcFontSetSort (FcConfig       *config,
 
     cs = 0;
 
-    if (!FcSortWalk (nodeps, nnodes, ret, &cs, trim))
+    if (!FcSortWalk (nodeps, nnodes, ret, &cs, trim, (csp!=0)))
        goto bail2;
 
     if (csp)
        *csp = cs;
     else
-       FcCharSetDestroy (cs);
+    {
+        if (cs)
+            FcCharSetDestroy (cs);
+    }
 
     free (nodes);