Add FcPatternEqualSubset for Pango, clean up some internal FcPattern

interfaces
This commit is contained in:
Keith Packard 2002-06-03 08:31:15 +00:00
parent 88c747e206
commit e9be9cd10a
7 changed files with 171 additions and 112 deletions

View 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);

View 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;

View 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 */

View 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,6 +157,28 @@ FcListValueListEqual (FcValueList *v1orig,
return FcTrue;
}
static FcBool
FcListPatternEqual (FcPattern *p1,
FcPattern *p2,
FcObjectSet *os)
{
int i;
FcPatternElt *e1, *e2;
for (i = 0; i < os->nobject; i++)
{
e1 = FcPatternFindElt (p1, os->objects[i]);
e2 = FcPatternFindElt (p2, os->objects[i]);
if (!e1 && !e2)
return FcTrue;
if (!e1 || !e2)
return FcFalse;
if (!FcListValueListEqual (e1->values, e2->values))
return FcFalse;
}
return FcTrue;
}
/*
* FcTrue iff all objects in "p" match "font"
*/
@ -150,7 +192,7 @@ FcListPatternMatchAny (FcPattern *p,
for (i = 0; i < p->num; i++)
{
e = FcPatternFind (font, p->elts[i].object, FcFalse);
e = FcPatternFindElt (font, p->elts[i].object);
if (!e)
return FcFalse;
if (!FcListValueListMatchAny (p->elts[i].values, e->values))
@ -159,28 +201,6 @@ FcListPatternMatchAny (FcPattern *p,
return FcTrue;
}
static FcBool
FcListPatternEqual (FcPattern *p1,
FcPattern *p2,
FcObjectSet *os)
{
int i;
FcPatternElt *e1, *e2;
for (i = 0; i < os->nobject; i++)
{
e1 = FcPatternFind (p1, os->objects[i], FcFalse);
e2 = FcPatternFind (p2, os->objects[i], FcFalse);
if (!e1 && !e2)
return FcTrue;
if (!e1 || !e2)
return FcFalse;
if (!FcListValueListEqual (e1->values, e2->values))
return FcFalse;
}
return FcTrue;
}
static FcChar32
FcListStringHash (const FcChar8 *s)
{
@ -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)

View 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);
}

View 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))

View 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);
}
static int
FcPatternPosition (const FcPattern *p, const char *object)
{
int low, high, mid, c;
low = 0;
high = p->num - 1;
c = 1;
mid = 0;
while (low <= high)
{
mid = (low + high) >> 1;
c = strcmp (p->elts[mid].object, object);
if (c == 0)
return mid;
if (c < 0)
low = mid + 1;
else
high = mid - 1;
}
if (c < 0)
mid++;
return -(mid + 1);
}
FcPatternElt *
FcPatternFind (FcPattern *p, const char *object, FcBool insert)
FcPatternFindElt (const FcPattern *p, const char *object)
{
int i = FcPatternPosition (p, object);
if (i < 0)
return 0;
return &p->elts[i];
}
FcPatternElt *
FcPatternInsertElt (FcPattern *p, const char *object)
{
int i;
int s;
FcPatternElt *e;
int low, high;
/* match existing */
low = 0;
high = p->num;
while (low + 1 < high)
i = FcPatternPosition (p, object);
if (i < 0)
{
i = (low + high) >> 1;
s = strcmp (object, p->elts[i].object);
if (s == 0)
return &p->elts[i];
if (s > 0)
low = i;
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++;
}
if (!insert)
return 0;
/* grow array */
if (p->num + 1 >= p->size)
{
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)