]> git.wh0rd.org - fontconfig.git/commitdiff
Add FcPatternEqualSubset for Pango, clean up some internal FcPattern
authorKeith Packard <keithp@keithp.com>
Mon, 3 Jun 2002 08:31:15 +0000 (08:31 +0000)
committerKeith Packard <keithp@keithp.com>
Mon, 3 Jun 2002 08:31:15 +0000 (08:31 +0000)
    interfaces

fontconfig/fontconfig.h
src/fccfg.c
src/fcint.h
src/fclist.c
src/fcmatch.c
src/fcname.c
src/fcpat.c

index 1d1155335ae40bb55fe88cefe2ae98fb1039e067..3d00ec0554ad1c77739e6bdcf94b365d662d6d3a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/fontconfig/fontconfig.h,v 1.14 2002/05/31 23:21:24 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/fontconfig/fontconfig.h,v 1.15 2002/06/02 20:52:06 keithp Exp $
  *
  * Copyright © 2001 Keith Packard, member of The XFree86 Project, Inc.
  *
@@ -598,7 +598,10 @@ void
 FcPatternDestroy (FcPattern *p);
 
 FcBool
-FcPatternEqual (FcPattern *pa, FcPattern *pb);
+FcPatternEqual (const FcPattern *pa, const FcPattern *pb);
+
+FcBool
+FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os);
 
 FcBool
 FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append);
index b5a9ade5d80014cf24559fc600b1e93e78462a46..0cee6de3d2dbcaac5c597391bdde0a5012a1db68 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fccfg.c,v 1.8 2002/06/02 19:51:36 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fccfg.c,v 1.7 2002/05/29 08:21:33 keithp Exp $
  *
  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
  *
@@ -1027,7 +1027,7 @@ FcConfigPatternAdd (FcPattern     *p,
 {
     if (list)
     {
-       FcPatternElt    *e = FcPatternFind (p, object, FcTrue);
+       FcPatternElt    *e = FcPatternInsertElt (p, object);
     
        if (!e)
            return;
@@ -1042,7 +1042,7 @@ static void
 FcConfigPatternDel (FcPattern  *p,
                    const char  *object)
 {
-    FcPatternElt    *e = FcPatternFind (p, object, FcFalse);
+    FcPatternElt    *e = FcPatternFindElt (p, object);
     if (!e)
        return;
     while (e->values)
@@ -1053,7 +1053,7 @@ static void
 FcConfigPatternCanon (FcPattern            *p,
                      const char    *object)
 {
-    FcPatternElt    *e = FcPatternFind (p, object, FcFalse);
+    FcPatternElt    *e = FcPatternFindElt (p, object);
     if (!e)
        return;
     if (!e->values)
@@ -1106,7 +1106,7 @@ FcConfigSubstitute (FcConfig      *config,
                printf ("FcConfigSubstitute test ");
                FcTestPrint (t);
            }
-           st[i].elt = FcPatternFind (p, t->field, FcFalse);
+           st[i].elt = FcPatternFindElt (p, t->field);
            /*
             * If there's no such field in the font,
             * then FcQualAll matches while FcQualAny does not
@@ -1158,7 +1158,7 @@ FcConfigSubstitute (FcConfig      *config,
                 * If there was a test, then replace the matched
                 * value with the new list of values
                 */
-               if (t && st[i].elt)
+               if (t)
                {
                    FcValueList *thisValue = st[i].value;
                    FcValueList *nextValue = thisValue ? thisValue->next : 0;
index beaa7c9931633d81bf6727b37bda2530ab4c0c5f..d0dcf6a662a3c74fa3058fa4e76325894d3eb2fa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.11 2002/05/31 04:42:42 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fcint.h,v 1.12 2002/05/31 23:21:25 keithp Exp $
  *
  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
  *
@@ -470,7 +470,10 @@ void
 FcValueListDestroy (FcValueList *l);
     
 FcPatternElt *
-FcPatternFind (FcPattern *p, const char *object, FcBool insert);
+FcPatternFindElt (const FcPattern *p, const char *object);
+
+FcPatternElt *
+FcPatternInsertElt (FcPattern *p, const char *object);
 
 /* fcrender.c */
 
index 88e6eabd9f4e7e19ed85b6de755e5fbfbd4a097e..414af11b61884de294a7afd38820313b5d5931cb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fclist.c,v 1.3 2002/05/21 17:06:22 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fclist.c,v 1.4 2002/06/02 21:07:56 keithp Exp $
  *
  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
  *
@@ -45,6 +45,7 @@ FcObjectSetAdd (FcObjectSet *os, const char *object)
 {
     int                s;
     const char **objects;
+    int                high, low, mid, c;
     
     if (os->nobject == os->sobject)
     {
@@ -62,7 +63,26 @@ FcObjectSetAdd (FcObjectSet *os, const char *object)
        os->objects = objects;
        os->sobject = s;
     }
-    os->objects[os->nobject++] = object;
+    high = os->nobject - 1;
+    low = 0;
+    mid = 0;
+    c = 1;
+    while (low <= high)
+    {
+       mid = (low + high) >> 1;
+       c = strcmp (os->objects[mid], object);
+       if (c == 0)
+           return FcTrue;
+       if (c < 0)
+           low = mid + 1;
+       else
+           high = mid - 1;
+    }
+    if (c < 0)
+       mid++;
+    memmove (os->objects + mid + 1, os->objects + mid, os->nobject - mid);
+    os->objects[mid] = object;
+    os->nobject++;
     return FcTrue;
 }
 
@@ -137,45 +157,45 @@ FcListValueListEqual (FcValueList   *v1orig,
     return FcTrue;
 }
 
-/*
- * FcTrue iff all objects in "p" match "font"
- */
-
 static FcBool
-FcListPatternMatchAny (FcPattern *p,
-                      FcPattern *font)
+FcListPatternEqual (FcPattern  *p1,
+                   FcPattern   *p2,
+                   FcObjectSet *os)
 {
     int                    i;
-    FcPatternElt   *e;
+    FcPatternElt    *e1, *e2;
 
-    for (i = 0; i < p->num; i++)
+    for (i = 0; i < os->nobject; i++)
     {
-       e = FcPatternFind (font, p->elts[i].object, FcFalse);
-       if (!e)
+       e1 = FcPatternFindElt (p1, os->objects[i]);
+       e2 = FcPatternFindElt (p2, os->objects[i]);
+       if (!e1 && !e2)
+           return FcTrue;
+       if (!e1 || !e2)
            return FcFalse;
-       if (!FcListValueListMatchAny (p->elts[i].values, e->values))
+       if (!FcListValueListEqual (e1->values, e2->values))
            return FcFalse;
     }
     return FcTrue;
 }
 
+/*
+ * FcTrue iff all objects in "p" match "font"
+ */
+
 static FcBool
-FcListPatternEqual (FcPattern  *p1,
-                   FcPattern   *p2,
-                   FcObjectSet *os)
+FcListPatternMatchAny (FcPattern *p,
+                      FcPattern *font)
 {
     int                    i;
-    FcPatternElt    *e1, *e2;
+    FcPatternElt   *e;
 
-    for (i = 0; i < os->nobject; i++)
+    for (i = 0; i < p->num; i++)
     {
-       e1 = FcPatternFind (p1, os->objects[i], FcFalse);
-       e2 = FcPatternFind (p2, os->objects[i], FcFalse);
-       if (!e1 && !e2)
-           return FcTrue;
-       if (!e1 || !e2)
+       e = FcPatternFindElt (font, p->elts[i].object);
+       if (!e)
            return FcFalse;
-       if (!FcListValueListEqual (e1->values, e2->values))
+       if (!FcListValueListMatchAny (p->elts[i].values, e->values))
            return FcFalse;
     }
     return FcTrue;
@@ -253,7 +273,7 @@ FcListPatternHash (FcPattern        *font,
 
     for (n = 0; n < os->nobject; n++)
     {
-       e = FcPatternFind (font, os->objects[n], FcFalse);
+       e = FcPatternFindElt (font, os->objects[n]);
        if (e)
            h = h ^ FcListValueListHash (e->values);
     }
@@ -331,7 +351,7 @@ FcListAppend (FcListHashTable       *table,
     
     for (o = 0; o < os->nobject; o++)
     {
-       e = FcPatternFind (font, os->objects[o], FcFalse);
+       e = FcPatternFindElt (font, os->objects[o]);
        if (e)
        {
            for (v = e->values; v; v = v->next)
index e796e4bc8a1958a9d256d83f9c5dddbb14519985..c616c631f83b27b9f65b73230fb0c840b7e8278a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fcmatch.c,v 1.8 2002/05/31 04:42:42 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fcmatch.c,v 1.9 2002/06/02 21:07:56 keithp Exp $
  *
  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
  *
@@ -326,7 +326,7 @@ FcFontRenderPrepare (FcConfig           *config,
     for (i = 0; i < font->num; i++)
     {
        fe = &font->elts[i];
-       pe = FcPatternFind (pat, fe->object, FcFalse);
+       pe = FcPatternFindElt (pat, fe->object);
        if (pe)
        {
            if (!FcCompareValueList (pe->object, pe->values, 
@@ -343,7 +343,7 @@ FcFontRenderPrepare (FcConfig           *config,
     for (i = 0; i < pat->num; i++)
     {
        pe = &pat->elts[i];
-       fe = FcPatternFind (font, pe->object, FcFalse);
+       fe = FcPatternFindElt (font, pe->object);
        if (!fe)
            FcPatternAdd (new, pe->object, pe->values->value, FcTrue);
     }
index c93706f5429c549fc30cab74ccdd3f67cec7224e..9f677a8108da1d5d29c4b1f8252902ade3001db5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fcname.c,v 1.5 2002/06/02 20:52:06 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fcname.c,v 1.6 2002/06/02 21:07:57 keithp Exp $
  *
  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
  *
@@ -500,13 +500,13 @@ FcNameUnparse (FcPattern *pat)
     const FcObjectType     *o;
 
     FcStrBufInit (&buf, buf_static, sizeof (buf_static));
-    e = FcPatternFind (pat, FC_FAMILY, FcFalse);
+    e = FcPatternFindElt (pat, FC_FAMILY);
     if (e)
     {
        if (!FcNameUnparseValueList (&buf, e->values, (FcChar8 *) FC_ESCAPE_FIXED))
            goto bail0;
     }
-    e = FcPatternFind (pat, FC_SIZE, FcFalse);
+    e = FcPatternFindElt (pat, FC_SIZE);
     if (e)
     {
        if (!FcNameUnparseString (&buf, (FcChar8 *) "-", 0))
@@ -524,7 +524,7 @@ FcNameUnparse (FcPattern *pat)
                !strcmp (o->object, FC_FILE))
                continue;
            
-           e = FcPatternFind (pat, o->object, FcFalse);
+           e = FcPatternFindElt (pat, o->object);
            if (e)
            {
                if (!FcNameUnparseString (&buf, (FcChar8 *) ":", 0))
index 2ed2eca102465e4afd12644405c35ad6914510eb..68ded728c068eb406fd7b995cebce3dd04773fc5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $XFree86: xc/lib/fontconfig/src/fcpat.c,v 1.5 2002/05/29 22:07:33 keithp Exp $
+ * $XFree86: xc/lib/fontconfig/src/fcpat.c,v 1.6 2002/05/31 23:21:25 keithp Exp $
  *
  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
  *
@@ -183,84 +183,91 @@ FcPatternDestroy (FcPattern *p)
     free (p);
 }
 
-FcPatternElt *
-FcPatternFind (FcPattern *p, const char *object, FcBool insert)
+static int
+FcPatternPosition (const FcPattern *p, const char *object)
 {
-    int                    i;
-    int                    s;
-    FcPatternElt   *e;
-    
-    int                    low, high;
+    int            low, high, mid, c;
 
-    /* match existing */
     low = 0;
-    high = p->num;
-
-    while (low + 1 < high)
+    high = p->num - 1;
+    c = 1;
+    mid = 0;
+    while (low <= high)
     {
-       i = (low + high) >> 1;
-       s = strcmp (object, p->elts[i].object);
-       if (s == 0)
-           return &p->elts[i];
-       if (s > 0)
-           low = i;
+       mid = (low + high) >> 1;
+       c = strcmp (p->elts[mid].object, object);
+       if (c == 0)
+           return mid;
+       if (c < 0)
+           low = mid + 1;
        else
-           high = i;
-    }
-
-    i = low;
-    while (i < high)
-    {
-       s = strcmp (object, p->elts[i].object);
-       if (s == 0)
-           return &p->elts[i];
-       if (s < 0)
-           break;
-       i++;
+           high = mid - 1;
     }
+    if (c < 0)
+       mid++;
+    return -(mid + 1);
+}
 
-    if (!insert)
+FcPatternElt *
+FcPatternFindElt (const FcPattern *p, const char *object)
+{
+    int            i = FcPatternPosition (p, object);
+    if (i < 0)
        return 0;
+    return &p->elts[i];
+}
 
-    /* grow array */
-    if (p->num + 1 >= p->size)
+FcPatternElt *
+FcPatternInsertElt (FcPattern *p, const char *object)
+{
+    int                    i;
+    FcPatternElt   *e;
+    
+    i = FcPatternPosition (p, object);
+    if (i < 0)
     {
-       s = p->size + 16;
-       if (p->elts)
-           e = (FcPatternElt *) realloc (p->elts, s * sizeof (FcPatternElt));
-       else
-           e = (FcPatternElt *) malloc (s * sizeof (FcPatternElt));
-       if (!e)
-           return FcFalse;
-       p->elts = e;
-       if (p->size)
-           FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt));
-       FcMemAlloc (FC_MEM_PATELT, s * sizeof (FcPatternElt));
-       while (p->size < s)
+       i = -i - 1;
+    
+       /* grow array */
+       if (p->num + 1 >= p->size)
        {
-           p->elts[p->size].object = 0;
-           p->elts[p->size].values = 0;
-           p->size++;
+           int s = p->size + 16;
+           if (p->elts)
+               e = (FcPatternElt *) realloc (p->elts, s * sizeof (FcPatternElt));
+           else
+               e = (FcPatternElt *) malloc (s * sizeof (FcPatternElt));
+           if (!e)
+               return FcFalse;
+           p->elts = e;
+           if (p->size)
+               FcMemFree (FC_MEM_PATELT, p->size * sizeof (FcPatternElt));
+           FcMemAlloc (FC_MEM_PATELT, s * sizeof (FcPatternElt));
+           while (p->size < s)
+           {
+               p->elts[p->size].object = 0;
+               p->elts[p->size].values = 0;
+               p->size++;
+           }
        }
+       
+       /* move elts up */
+       memmove (p->elts + i + 1,
+                p->elts + i,
+                sizeof (FcPatternElt) *
+                (p->num - i));
+                
+       /* bump count */
+       p->num++;
+       
+       p->elts[i].object = object;
+       p->elts[i].values = 0;
     }
     
-    /* move elts up */
-    memmove (p->elts + i + 1,
-            p->elts + i,
-            sizeof (FcPatternElt) *
-            (p->num - i));
-            
-    /* bump count */
-    p->num++;
-    
-    p->elts[i].object = object;
-    p->elts[i].values = 0;
-    
     return &p->elts[i];
 }
 
 FcBool
-FcPatternEqual (FcPattern *pa, FcPattern *pb)
+FcPatternEqual (const FcPattern *pa, const FcPattern *pb)
 {
     int        i;
 
@@ -276,6 +283,32 @@ FcPatternEqual (FcPattern *pa, FcPattern *pb)
     return FcTrue;
 }
 
+FcBool
+FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os)
+{
+    FcPatternElt    *ea, *eb;
+    int                    i;
+    
+    for (i = 0; i < os->nobject; i++)
+    {
+       ea = FcPatternFindElt (pa, os->objects[i]);
+       eb = FcPatternFindElt (pb, os->objects[i]);
+       if (ea)
+       {
+           if (!eb)
+               return FcFalse;
+           if (!FcValueListEqual (ea->values, eb->values))
+               return FcFalse;
+       }
+       else
+       {
+           if (eb)
+               return FcFalse;
+       }
+    }
+    return FcTrue;
+}
+
 FcBool
 FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append)
 {
@@ -295,7 +328,7 @@ FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append)
     new->value = value;
     new->next = 0;
     
-    e = FcPatternFind (p, object, FcTrue);
+    e = FcPatternInsertElt (p, object);
     if (!e)
        goto bail2;
     
@@ -339,7 +372,7 @@ FcPatternDel (FcPattern *p, const char *object)
     FcPatternElt   *e;
     int                    i;
 
-    e = FcPatternFind (p, object, FcFalse);
+    e = FcPatternFindElt (p, object);
     if (!e)
        return FcFalse;
 
@@ -434,7 +467,7 @@ FcPatternGet (FcPattern *p, const char *object, int id, FcValue *v)
     FcPatternElt   *e;
     FcValueList    *l;
 
-    e = FcPatternFind (p, object, FcFalse);
+    e = FcPatternFindElt (p, object);
     if (!e)
        return FcResultNoMatch;
     for (l = e->values; l; l = l->next)