]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcmatch.c
Allow double or integer for numeric values in matching
[fontconfig.git] / src / fcmatch.c
index 99e9fd1b7c094b414865c542a733e1de9567cf30..ca2198f56e36112e59156c3dc2dcc3359edf4f6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fcmatch.c,v 1.16 2002/07/06 23:47:44 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fcmatch.c,v 1.20 2002/08/31 22:17:32 keithp Exp $
  *
  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
  *
 #include <stdio.h>
 
 static double
-FcCompareInteger (char *object, FcValue value1, FcValue value2)
+FcCompareNumber (char *object, FcValue value1, FcValue value2)
 {
-    int        v;
+    double  v1, v2, v;
     
-    if (value2.type != FcTypeInteger || value1.type != FcTypeInteger)
+    switch (value1.type) {
+    case FcTypeInteger:
+       v1 = (double) value1.u.i;
+       break;
+    case FcTypeDouble:
+       v1 = value1.u.d;
+       break;
+    default:
+       return -1.0;
+    }
+    switch (value2.type) {
+    case FcTypeInteger:
+       v2 = (double) value2.u.i;
+       break;
+    case FcTypeDouble:
+       v2 = value2.u.d;
+       break;
+    default:
        return -1.0;
-    v = value2.u.i - value1.u.i;
+    }
+    v = v2 - v1;
     if (v < 0)
        v = -v;
     return (double) v;
@@ -61,9 +79,34 @@ FcCompareLang (char *object, FcValue value1, FcValue value2)
 {
     FcLangResult    result;
     
-    if (value2.type != FcTypeString || value1.type != FcTypeString)
+    switch (value1.type) {
+    case FcTypeLangSet:
+       switch (value2.type) {
+       case FcTypeLangSet:
+           result = FcLangSetCompare (value1.u.l, value2.u.l);
+           break;
+       case FcTypeString:
+           result = FcLangSetHasLang (value1.u.l, value2.u.s);
+           break;
+       default:
+           return -1.0;
+       }
+       break;
+    case FcTypeString:
+       switch (value2.type) {
+       case FcTypeLangSet:
+           result = FcLangSetHasLang (value2.u.l, value1.u.s);
+           break;
+       case FcTypeString:
+           result = FcLangCompare (value1.u.s, value2.u.s);
+           break;
+       default:
+           return -1.0;
+       }
+       break;
+    default:
        return -1.0;
-    result = FcLangCompare (value1.u.s, value2.u.s);
+    }
     switch (result) {
     case FcLangEqual:
        return 0;
@@ -148,7 +191,7 @@ static FcMatcher _FcMatchers [] = {
     { FC_LANG,         FcCompareLang,          3, 3 },
 #define MATCH_LANG         3
     
-    { FC_SPACING,      FcCompareInteger,       5, 5 },
+    { FC_SPACING,      FcCompareNumber,        5, 5 },
 #define MATCH_SPACING      4
     
     { FC_PIXEL_SIZE,   FcCompareSize,          6, 6 },
@@ -157,10 +200,10 @@ static FcMatcher _FcMatchers [] = {
     { FC_STYLE,                FcCompareString,        7, 7 },
 #define MATCH_STYLE        6
     
-    { FC_SLANT,                FcCompareInteger,       8, 8 },
+    { FC_SLANT,                FcCompareNumber,        8, 8 },
 #define MATCH_SLANT        7
     
-    { FC_WEIGHT,       FcCompareInteger,       9, 9 },
+    { FC_WEIGHT,       FcCompareNumber,        9, 9 },
 #define MATCH_WEIGHT       8
     
     { FC_ANTIALIAS,    FcCompareBool,          10, 10 },
@@ -171,9 +214,12 @@ static FcMatcher _FcMatchers [] = {
     
     { FC_OUTLINE,      FcCompareBool,          12, 12 },
 #define MATCH_OUTLINE      11
+
+    { FC_FONTVERSION,  FcCompareNumber,        13, 13 },
+#define MATCH_FONTVERSION   12
 };
 
-#define NUM_MATCH_VALUES    13
+#define NUM_MATCH_VALUES    14
 
 static FcBool
 FcCompareValueList (const char  *object,
@@ -197,7 +243,13 @@ FcCompareValueList (const char  *object,
     case 'f':
        switch (FcToLower (object[1])) {
        case 'o':
-           i = MATCH_FOUNDRY; break;
+           switch (FcToLower (object[2])) {
+           case 'u':
+               i = MATCH_FOUNDRY; break;
+           case 'n':
+               i = MATCH_FONTVERSION; break;
+           }
+           break;
        case 'a':
            i = MATCH_FAMILY; break;
        }
@@ -402,8 +454,7 @@ FcFontRenderPrepare (FcConfig           *config,
        if (!fe)
            FcPatternAdd (new, pe->object, pe->values->value, FcTrue);
     }
-    FcPatternAddPattern (new, FC_PATTERN, pat);
-    FcConfigSubstitute (config, new, FcMatchFont);
+    FcConfigSubstituteWithPat (config, new, pat, FcMatchFont);
     return new;
 }
 
@@ -616,6 +667,7 @@ FcFontSetSort (FcConfig         *config,
     }
     if (!nnodes)
        goto bail0;
+    /* freed below */
     nodes = malloc (nnodes * sizeof (FcSortNode) + nnodes * sizeof (FcSortNode *));
     if (!nodes)
        goto bail0;