]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcmatch.c
Include $(top_srcdir), $(top_srcdir)/src before anything else.
[fontconfig.git] / src / fcmatch.c
index cf702c65db2ce008679160ab57ab078448c3a0bd..e3748e50aaf76418360087561eef7e012347f3ad 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
@@ -524,7 +524,7 @@ FcFontSetMatch (FcConfig    *config,
     FcMatcher      *weak_matchers[NUM_MATCH_VALUES];
     FcPatternElt    *pat_elts[NUM_MATCH_VALUES];
     int                    pat_elt;
-    FcBool         *match_blocked;
+    int                    *match_blocked;
     int                    block_start;
 
     if (!nsets || !sets || !p)
@@ -560,7 +560,7 @@ FcFontSetMatch (FcConfig    *config,
 
     fonts_left = nfonts;
 
-    match_blocked = (FcBool*)calloc(nfonts, sizeof(FcBool));
+    match_blocked = (int*)calloc(nfonts, sizeof(int));
 
     /* Find out all necessary matchers first, so we don't need to find them
      * in every loop.
@@ -631,7 +631,7 @@ FcFontSetMatch (FcConfig    *config,
                    int             cand_elt;
                    FcPatternElt    *cand_elts;
 
-                   if (match_blocked[f + sets_offset[set]])
+                   if (match_blocked[f + sets_offset[set]] == 1)
                        continue;
 
                    score = 1e99;
@@ -673,6 +673,13 @@ FcFontSetMatch (FcConfig    *config,
                        }
                    }
 
+                   /* We had no matching, just try the next one */
+                   if (score == 1e99)
+                   {
+                       match_blocked[f + sets_offset[set]] = 2;
+                       continue;
+                   }
+                   match_blocked[f + sets_offset[set]] = 0;
                    /* If there's a previous champion, and current score
                     * beats previous best score, on this element, then
                     * knock out the previous champion and anything
@@ -687,20 +694,21 @@ FcFontSetMatch (FcConfig    *config,
                            for (b = block_start; b < f + sets_offset[set]; ++b)
                                if (!match_blocked[b])
                                {
-                                   match_blocked[b] = FcTrue;
+                                   match_blocked[b] = 1;
                                    --fonts_left;
                                }
                        }
 
                        bestscore = score;
                        best = s->fonts[f];
-                       block_start = f + sets_offset[set];
+                       /* This kills too many fonts, unfortunately. */
+                       /* block_start = f + sets_offset[set]; */
                    }
 
                    /* If f loses, then it's out too. */
                    if (best && score > bestscore)
                    {
-                       match_blocked[f + sets_offset[set]] = FcTrue;
+                       match_blocked[f + sets_offset[set]] = 1;
                        --fonts_left;
                    }
 
@@ -783,7 +791,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;
@@ -800,16 +808,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)
                {
@@ -978,13 +990,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);