From e9be9cd10a24b75480a26be834041d312d8217b4 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 3 Jun 2002 08:31:15 +0000 Subject: [PATCH] Add FcPatternEqualSubset for Pango, clean up some internal FcPattern interfaces --- fontconfig/fontconfig.h | 7 +- src/fccfg.c | 12 +-- src/fcint.h | 7 +- src/fclist.c | 72 +++++++++++------- src/fcmatch.c | 6 +- src/fcname.c | 8 +- src/fcpat.c | 161 ++++++++++++++++++++++++---------------- 7 files changed, 166 insertions(+), 107 deletions(-) diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h index 1d11553..3d00ec0 100644 --- a/fontconfig/fontconfig.h +++ b/fontconfig/fontconfig.h @@ -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); diff --git a/src/fccfg.c b/src/fccfg.c index b5a9ade..0cee6de 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -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; diff --git a/src/fcint.h b/src/fcint.h index beaa7c9..d0dcf6a 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -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 */ diff --git a/src/fclist.c b/src/fclist.c index 88e6eab..414af11 100644 --- a/src/fclist.c +++ b/src/fclist.c @@ -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) diff --git a/src/fcmatch.c b/src/fcmatch.c index e796e4b..c616c63 100644 --- a/src/fcmatch.c +++ b/src/fcmatch.c @@ -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); } diff --git a/src/fcname.c b/src/fcname.c index c93706f..9f677a8 100644 --- a/src/fcname.c +++ b/src/fcname.c @@ -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)) diff --git a/src/fcpat.c b/src/fcpat.c index 2ed2eca..68ded72 100644 --- a/src/fcpat.c +++ b/src/fcpat.c @@ -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) -- 2.39.5