2002-02-15 00:34:13 +01:00
|
|
|
/*
|
2003-03-05 06:52:31 +01:00
|
|
|
* $RCSId: xc/lib/fontconfig/src/fclist.c,v 1.11tsi Exp $
|
2002-02-15 00:34:13 +01:00
|
|
|
*
|
2004-12-07 02:14:46 +01:00
|
|
|
* Copyright © 2000 Keith Packard
|
2002-02-15 00:34:13 +01:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of Keith Packard not be used in
|
|
|
|
* advertising or publicity pertaining to distribution of the software without
|
|
|
|
* specific, written prior permission. Keith Packard makes no
|
|
|
|
* representations about the suitability of this software for any purpose. It
|
|
|
|
* is provided "as is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fcint.h"
|
2006-04-25 07:57:41 +02:00
|
|
|
#include <stdlib.h>
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
|
|
FcObjectSet *
|
|
|
|
FcObjectSetCreate (void)
|
|
|
|
{
|
|
|
|
FcObjectSet *os;
|
|
|
|
|
|
|
|
os = (FcObjectSet *) malloc (sizeof (FcObjectSet));
|
|
|
|
if (!os)
|
|
|
|
return 0;
|
|
|
|
FcMemAlloc (FC_MEM_OBJECTSET, sizeof (FcObjectSet));
|
|
|
|
os->nobject = 0;
|
|
|
|
os->sobject = 0;
|
|
|
|
os->objects = 0;
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool
|
|
|
|
FcObjectSetAdd (FcObjectSet *os, const char *object)
|
|
|
|
{
|
|
|
|
int s;
|
2005-08-24 08:21:30 +02:00
|
|
|
const char **objects;
|
2002-06-03 10:31:15 +02:00
|
|
|
int high, low, mid, c;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
|
|
if (os->nobject == os->sobject)
|
|
|
|
{
|
|
|
|
s = os->sobject + 4;
|
|
|
|
if (os->objects)
|
2005-08-24 08:21:30 +02:00
|
|
|
objects = (const char **) realloc ((void *) os->objects,
|
|
|
|
s * sizeof (const char *));
|
2002-02-15 00:34:13 +01:00
|
|
|
else
|
2005-08-24 08:21:30 +02:00
|
|
|
objects = (const char **) malloc (s * sizeof (const char *));
|
2002-02-15 00:34:13 +01:00
|
|
|
if (!objects)
|
|
|
|
return FcFalse;
|
|
|
|
if (os->sobject)
|
|
|
|
FcMemFree (FC_MEM_OBJECTPTR, os->sobject * sizeof (const char *));
|
|
|
|
FcMemAlloc (FC_MEM_OBJECTPTR, s * sizeof (const char *));
|
|
|
|
os->objects = objects;
|
|
|
|
os->sobject = s;
|
|
|
|
}
|
2002-06-03 10:31:15 +02:00
|
|
|
high = os->nobject - 1;
|
|
|
|
low = 0;
|
|
|
|
mid = 0;
|
|
|
|
c = 1;
|
2005-09-11 04:16:09 +02:00
|
|
|
object = (char *)FcStrStaticName ((FcChar8 *)object);
|
2002-06-03 10:31:15 +02:00
|
|
|
while (low <= high)
|
|
|
|
{
|
|
|
|
mid = (low + high) >> 1;
|
2005-08-24 08:21:30 +02:00
|
|
|
c = os->objects[mid] - object;
|
2002-06-03 10:31:15 +02:00
|
|
|
if (c == 0)
|
|
|
|
return FcTrue;
|
|
|
|
if (c < 0)
|
|
|
|
low = mid + 1;
|
|
|
|
else
|
|
|
|
high = mid - 1;
|
|
|
|
}
|
|
|
|
if (c < 0)
|
|
|
|
mid++;
|
2002-06-18 18:47:12 +02:00
|
|
|
memmove (os->objects + mid + 1, os->objects + mid,
|
2005-08-24 08:21:30 +02:00
|
|
|
(os->nobject - mid) * sizeof (const char *));
|
|
|
|
os->objects[mid] = object;
|
2002-06-03 10:31:15 +02:00
|
|
|
os->nobject++;
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FcObjectSetDestroy (FcObjectSet *os)
|
|
|
|
{
|
|
|
|
if (os->objects)
|
|
|
|
{
|
|
|
|
FcMemFree (FC_MEM_OBJECTPTR, os->sobject * sizeof (const char *));
|
|
|
|
free ((void *) os->objects);
|
|
|
|
}
|
|
|
|
FcMemFree (FC_MEM_OBJECTSET, sizeof (FcObjectSet));
|
|
|
|
free (os);
|
|
|
|
}
|
|
|
|
|
|
|
|
FcObjectSet *
|
|
|
|
FcObjectSetVaBuild (const char *first, va_list va)
|
|
|
|
{
|
|
|
|
FcObjectSet *ret;
|
|
|
|
|
|
|
|
FcObjectSetVapBuild (ret, first, va);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcObjectSet *
|
|
|
|
FcObjectSetBuild (const char *first, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
FcObjectSet *os;
|
|
|
|
|
|
|
|
va_start (va, first);
|
|
|
|
FcObjectSetVapBuild (os, first, va);
|
|
|
|
va_end (va);
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2003-07-20 18:06:18 +02:00
|
|
|
/*
|
|
|
|
* Font must have a containing value for every value in the pattern
|
|
|
|
*/
|
2002-02-15 00:34:13 +01:00
|
|
|
static FcBool
|
2005-06-28 05:41:02 +02:00
|
|
|
FcListValueListMatchAny (FcValueListPtr patOrig, /* pattern */
|
|
|
|
FcValueListPtr fntOrig) /* font */
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtr pat, fnt;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
for (pat = patOrig; pat != NULL; pat = FcValueListNext(pat))
|
2003-07-20 18:06:18 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
for (fnt = fntOrig; fnt != NULL; fnt = FcValueListNext(fnt))
|
2003-07-20 18:06:18 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* make sure the font 'contains' the pattern.
|
|
|
|
* (OpListing is OpContains except for strings
|
|
|
|
* where it requires an exact match)
|
|
|
|
*/
|
2006-08-30 13:16:22 +02:00
|
|
|
if (FcConfigCompareValue (&fnt->value,
|
2003-07-20 18:06:18 +02:00
|
|
|
FcOpListing,
|
2006-08-30 13:16:22 +02:00
|
|
|
&pat->value))
|
2003-07-20 18:06:18 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
if (fnt == NULL)
|
2003-07-20 18:06:18 +02:00
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
return FcTrue;
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static FcBool
|
2005-06-28 05:41:02 +02:00
|
|
|
FcListValueListEqual (FcValueListPtr v1orig,
|
|
|
|
FcValueListPtr v2orig)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtr v1, v2;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
for (v1 = v1orig; v1 != NULL; v1 = FcValueListNext(v1))
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
for (v2 = v2orig; v2 != NULL; v2 = FcValueListNext(v2))
|
|
|
|
if (FcValueEqual (FcValueCanonicalize(&(v1)->value),
|
|
|
|
FcValueCanonicalize(&(v2)->value)))
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
2006-08-30 13:16:22 +02:00
|
|
|
if (v2 == NULL)
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcFalse;
|
|
|
|
}
|
2006-08-30 13:16:22 +02:00
|
|
|
for (v2 = v2orig; v2 != NULL; v2 = FcValueListNext(v2))
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
for (v1 = v1orig; v1 != NULL; v1 = FcValueListNext(v1))
|
|
|
|
if (FcValueEqual (FcValueCanonicalize(&v1->value),
|
|
|
|
FcValueCanonicalize(&v2->value)))
|
2002-02-15 00:34:13 +01:00
|
|
|
break;
|
2006-08-30 13:16:22 +02:00
|
|
|
if (v1 == NULL)
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FcBool
|
2002-06-03 10:31:15 +02:00
|
|
|
FcListPatternEqual (FcPattern *p1,
|
|
|
|
FcPattern *p2,
|
|
|
|
FcObjectSet *os)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
int i;
|
2002-06-03 10:31:15 +02:00
|
|
|
FcPatternElt *e1, *e2;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
for (i = 0; i < os->nobject; i++)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
e1 = FcPatternObjectFindElt (p1, FcObjectFromName (os->objects[i]));
|
|
|
|
e2 = FcPatternObjectFindElt (p2, FcObjectFromName (os->objects[i]));
|
2002-06-03 10:31:15 +02:00
|
|
|
if (!e1 && !e2)
|
2002-08-22 20:53:22 +02:00
|
|
|
continue;
|
2002-06-03 10:31:15 +02:00
|
|
|
if (!e1 || !e2)
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcFalse;
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!FcListValueListEqual (FcPatternEltValues(e1),
|
|
|
|
FcPatternEltValues(e2)))
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
/*
|
|
|
|
* FcTrue iff all objects in "p" match "font"
|
|
|
|
*/
|
|
|
|
|
2004-12-04 20:41:10 +01:00
|
|
|
FcBool
|
|
|
|
FcListPatternMatchAny (const FcPattern *p,
|
|
|
|
const FcPattern *font)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2002-06-03 10:31:15 +02:00
|
|
|
for (i = 0; i < p->num; i++)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternElt *pe = &FcPatternElts(p)[i];
|
|
|
|
FcPatternElt *fe = FcPatternObjectFindElt (font, pe->object);
|
|
|
|
if (!fe)
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcFalse;
|
2006-08-30 13:16:22 +02:00
|
|
|
if (!FcListValueListMatchAny (FcPatternEltValues(pe), /* pat elts */
|
|
|
|
FcPatternEltValues(fe))) /* font elts */
|
2002-02-15 00:34:13 +01:00
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FcChar32
|
|
|
|
FcListMatrixHash (const FcMatrix *m)
|
|
|
|
{
|
|
|
|
int xx = (int) (m->xx * 100),
|
|
|
|
xy = (int) (m->xy * 100),
|
|
|
|
yx = (int) (m->yx * 100),
|
|
|
|
yy = (int) (m->yy * 100);
|
|
|
|
|
|
|
|
return ((FcChar32) xx) ^ ((FcChar32) xy) ^ ((FcChar32) yx) ^ ((FcChar32) yy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static FcChar32
|
2005-08-24 08:21:30 +02:00
|
|
|
FcListValueHash (FcValue *value)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2005-08-24 08:21:30 +02:00
|
|
|
FcValue v = FcValueCanonicalize(value);
|
2002-02-15 00:34:13 +01:00
|
|
|
switch (v.type) {
|
|
|
|
case FcTypeVoid:
|
|
|
|
return 0;
|
|
|
|
case FcTypeInteger:
|
|
|
|
return (FcChar32) v.u.i;
|
|
|
|
case FcTypeDouble:
|
|
|
|
return (FcChar32) (int) v.u.d;
|
|
|
|
case FcTypeString:
|
2005-08-24 08:21:30 +02:00
|
|
|
return FcStrHashIgnoreCase (v.u.s);
|
2002-02-15 00:34:13 +01:00
|
|
|
case FcTypeBool:
|
|
|
|
return (FcChar32) v.u.b;
|
|
|
|
case FcTypeMatrix:
|
2005-08-24 08:21:30 +02:00
|
|
|
return FcListMatrixHash (v.u.m);
|
2002-02-15 00:34:13 +01:00
|
|
|
case FcTypeCharSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
return FcCharSetCount (v.u.c);
|
2002-06-02 23:07:57 +02:00
|
|
|
case FcTypeFTFace:
|
2002-09-18 19:11:46 +02:00
|
|
|
return (long) v.u.f;
|
2002-08-22 09:36:45 +02:00
|
|
|
case FcTypeLangSet:
|
2005-08-24 08:21:30 +02:00
|
|
|
return FcLangSetHash (v.u.l);
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FcChar32
|
2005-06-28 05:41:02 +02:00
|
|
|
FcListValueListHash (FcValueListPtr list)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcChar32 h = 0;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
while (list != NULL)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
h = h ^ FcListValueHash (&list->value);
|
|
|
|
list = FcValueListNext(list);
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FcChar32
|
|
|
|
FcListPatternHash (FcPattern *font,
|
|
|
|
FcObjectSet *os)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
FcPatternElt *e;
|
|
|
|
FcChar32 h = 0;
|
|
|
|
|
|
|
|
for (n = 0; n < os->nobject; n++)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
e = FcPatternObjectFindElt (font, FcObjectFromName (os->objects[n]));
|
2002-02-15 00:34:13 +01:00
|
|
|
if (e)
|
2006-08-30 13:16:22 +02:00
|
|
|
h = h ^ FcListValueListHash (FcPatternEltValues(e));
|
2002-02-15 00:34:13 +01:00
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct _FcListBucket {
|
|
|
|
struct _FcListBucket *next;
|
|
|
|
FcChar32 hash;
|
|
|
|
FcPattern *pattern;
|
|
|
|
} FcListBucket;
|
|
|
|
|
|
|
|
#define FC_LIST_HASH_SIZE 4099
|
|
|
|
|
|
|
|
typedef struct _FcListHashTable {
|
|
|
|
int entries;
|
|
|
|
FcListBucket *buckets[FC_LIST_HASH_SIZE];
|
|
|
|
} FcListHashTable;
|
|
|
|
|
|
|
|
static void
|
|
|
|
FcListHashTableInit (FcListHashTable *table)
|
|
|
|
{
|
|
|
|
table->entries = 0;
|
|
|
|
memset (table->buckets, '\0', sizeof (table->buckets));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FcListHashTableCleanup (FcListHashTable *table)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FcListBucket *bucket, *next;
|
|
|
|
|
|
|
|
for (i = 0; i < FC_LIST_HASH_SIZE; i++)
|
|
|
|
{
|
|
|
|
for (bucket = table->buckets[i]; bucket; bucket = next)
|
|
|
|
{
|
|
|
|
next = bucket->next;
|
|
|
|
FcPatternDestroy (bucket->pattern);
|
|
|
|
FcMemFree (FC_MEM_LISTBUCK, sizeof (FcListBucket));
|
|
|
|
free (bucket);
|
|
|
|
}
|
|
|
|
table->buckets[i] = 0;
|
|
|
|
}
|
|
|
|
table->entries = 0;
|
|
|
|
}
|
|
|
|
|
2005-10-22 16:21:14 +02:00
|
|
|
static int
|
2006-08-30 13:16:22 +02:00
|
|
|
FcGetDefaultObjectLangIndex (FcPattern *font, FcObject object)
|
2005-10-22 16:21:14 +02:00
|
|
|
{
|
|
|
|
FcChar8 *lang = FcGetDefaultLang ();
|
2006-08-30 13:16:22 +02:00
|
|
|
FcPatternElt *e = FcPatternObjectFindElt (font, object);
|
2005-10-22 16:21:14 +02:00
|
|
|
FcValueListPtr v;
|
|
|
|
FcValue value;
|
|
|
|
int idx = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
for (v = FcPatternEltValues(e), i = 0; v; v = FcValueListNext(v), ++i)
|
2005-10-22 16:21:14 +02:00
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
value = FcValueCanonicalize (&v->value);
|
2005-10-22 16:21:14 +02:00
|
|
|
|
|
|
|
if (value.type == FcTypeString)
|
|
|
|
{
|
|
|
|
FcLangResult res = FcLangCompare (value.u.s, lang);
|
|
|
|
if (res == FcLangEqual || (res == FcLangDifferentCountry && idx < 0))
|
|
|
|
idx = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (idx > 0) ? idx : 0;
|
|
|
|
}
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
static FcBool
|
|
|
|
FcListAppend (FcListHashTable *table,
|
|
|
|
FcPattern *font,
|
|
|
|
FcObjectSet *os)
|
|
|
|
{
|
|
|
|
int o;
|
|
|
|
FcPatternElt *e;
|
2005-06-28 05:41:02 +02:00
|
|
|
FcValueListPtr v;
|
2002-02-15 00:34:13 +01:00
|
|
|
FcChar32 hash;
|
|
|
|
FcListBucket **prev, *bucket;
|
2005-10-22 16:21:14 +02:00
|
|
|
int familyidx = -1;
|
|
|
|
int fullnameidx = -1;
|
|
|
|
int styleidx = -1;
|
|
|
|
int defidx = 0;
|
|
|
|
int idx;
|
2002-02-15 00:34:13 +01:00
|
|
|
|
|
|
|
hash = FcListPatternHash (font, os);
|
|
|
|
for (prev = &table->buckets[hash % FC_LIST_HASH_SIZE];
|
|
|
|
(bucket = *prev); prev = &(bucket->next))
|
|
|
|
{
|
|
|
|
if (bucket->hash == hash &&
|
|
|
|
FcListPatternEqual (bucket->pattern, font, os))
|
|
|
|
return FcTrue;
|
|
|
|
}
|
|
|
|
bucket = (FcListBucket *) malloc (sizeof (FcListBucket));
|
|
|
|
if (!bucket)
|
|
|
|
goto bail0;
|
|
|
|
FcMemAlloc (FC_MEM_LISTBUCK, sizeof (FcListBucket));
|
|
|
|
bucket->next = 0;
|
|
|
|
bucket->hash = hash;
|
|
|
|
bucket->pattern = FcPatternCreate ();
|
|
|
|
if (!bucket->pattern)
|
|
|
|
goto bail1;
|
|
|
|
|
|
|
|
for (o = 0; o < os->nobject; o++)
|
|
|
|
{
|
2005-10-22 16:21:14 +02:00
|
|
|
if (!strcmp (os->objects[o], FC_FAMILY) || !strcmp (os->objects[o], FC_FAMILYLANG))
|
|
|
|
{
|
|
|
|
if (familyidx < 0)
|
2006-08-30 13:16:22 +02:00
|
|
|
familyidx = FcGetDefaultObjectLangIndex (font, FC_FAMILYLANG_OBJECT);
|
2005-10-22 16:21:14 +02:00
|
|
|
defidx = familyidx;
|
|
|
|
}
|
|
|
|
else if (!strcmp (os->objects[o], FC_FULLNAME) || !strcmp (os->objects[o], FC_FULLNAMELANG))
|
|
|
|
{
|
|
|
|
if (fullnameidx < 0)
|
2006-08-30 13:16:22 +02:00
|
|
|
fullnameidx = FcGetDefaultObjectLangIndex (font, FC_FULLNAMELANG_OBJECT);
|
2005-10-22 16:21:14 +02:00
|
|
|
defidx = fullnameidx;
|
|
|
|
}
|
|
|
|
else if (!strcmp (os->objects[o], FC_STYLE) || !strcmp (os->objects[o], FC_STYLELANG))
|
|
|
|
{
|
|
|
|
if (styleidx < 0)
|
2006-08-30 13:16:22 +02:00
|
|
|
styleidx = FcGetDefaultObjectLangIndex (font, FC_STYLELANG_OBJECT);
|
2005-10-22 16:21:14 +02:00
|
|
|
defidx = styleidx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
defidx = 0;
|
|
|
|
|
2006-08-30 13:16:22 +02:00
|
|
|
e = FcPatternObjectFindElt (font, FcObjectFromName (os->objects[o]));
|
2002-02-15 00:34:13 +01:00
|
|
|
if (e)
|
|
|
|
{
|
2006-08-30 13:16:22 +02:00
|
|
|
for (v = FcPatternEltValues(e), idx = 0; v;
|
|
|
|
v = FcValueListNext(v), ++idx)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
if (!FcPatternAdd (bucket->pattern,
|
2005-08-24 08:21:30 +02:00
|
|
|
os->objects[o],
|
2006-08-30 13:16:22 +02:00
|
|
|
FcValueCanonicalize(&v->value), defidx != idx))
|
2002-02-15 00:34:13 +01:00
|
|
|
goto bail2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*prev = bucket;
|
|
|
|
++table->entries;
|
|
|
|
|
|
|
|
return FcTrue;
|
|
|
|
|
|
|
|
bail2:
|
|
|
|
FcPatternDestroy (bucket->pattern);
|
|
|
|
bail1:
|
|
|
|
FcMemFree (FC_MEM_LISTBUCK, sizeof (FcListBucket));
|
|
|
|
free (bucket);
|
|
|
|
bail0:
|
|
|
|
return FcFalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcFontSet *
|
2002-02-28 17:51:48 +01:00
|
|
|
FcFontSetList (FcConfig *config,
|
|
|
|
FcFontSet **sets,
|
|
|
|
int nsets,
|
|
|
|
FcPattern *p,
|
|
|
|
FcObjectSet *os)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
|
|
|
FcFontSet *ret;
|
|
|
|
FcFontSet *s;
|
|
|
|
int f;
|
2002-02-28 17:51:48 +01:00
|
|
|
int set;
|
2002-02-15 00:34:13 +01:00
|
|
|
FcListHashTable table;
|
|
|
|
int i;
|
|
|
|
FcListBucket *bucket;
|
|
|
|
|
|
|
|
if (!config)
|
|
|
|
{
|
2002-05-21 19:06:22 +02:00
|
|
|
if (!FcInitBringUptoDate ())
|
|
|
|
goto bail0;
|
|
|
|
|
2002-02-15 00:34:13 +01:00
|
|
|
config = FcConfigGetCurrent ();
|
|
|
|
if (!config)
|
|
|
|
goto bail0;
|
|
|
|
}
|
|
|
|
FcListHashTableInit (&table);
|
|
|
|
/*
|
|
|
|
* Walk all available fonts adding those that
|
|
|
|
* match to the hash table
|
|
|
|
*/
|
2002-02-28 17:51:48 +01:00
|
|
|
for (set = 0; set < nsets; set++)
|
2002-02-15 00:34:13 +01:00
|
|
|
{
|
2002-02-28 17:51:48 +01:00
|
|
|
s = sets[set];
|
2002-02-15 00:34:13 +01:00
|
|
|
if (!s)
|
|
|
|
continue;
|
|
|
|
for (f = 0; f < s->nfont; f++)
|
2003-07-20 18:06:18 +02:00
|
|
|
if (FcListPatternMatchAny (p, /* pattern */
|
|
|
|
s->fonts[f])) /* font */
|
2002-02-15 00:34:13 +01:00
|
|
|
if (!FcListAppend (&table, s->fonts[f], os))
|
|
|
|
goto bail1;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
int max = 0;
|
|
|
|
int full = 0;
|
|
|
|
int ents = 0;
|
|
|
|
int len;
|
|
|
|
for (i = 0; i < FC_LIST_HASH_SIZE; i++)
|
|
|
|
{
|
|
|
|
if ((bucket = table.buckets[i]))
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
for (; bucket; bucket = bucket->next)
|
|
|
|
{
|
|
|
|
ents++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
if (len > max)
|
|
|
|
max = len;
|
|
|
|
full++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ("used: %d max: %d avg: %g\n", full, max,
|
|
|
|
(double) ents / FC_LIST_HASH_SIZE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Walk the hash table and build
|
|
|
|
* a font set
|
|
|
|
*/
|
|
|
|
ret = FcFontSetCreate ();
|
|
|
|
if (!ret)
|
|
|
|
goto bail0;
|
|
|
|
for (i = 0; i < FC_LIST_HASH_SIZE; i++)
|
|
|
|
while ((bucket = table.buckets[i]))
|
|
|
|
{
|
|
|
|
if (!FcFontSetAdd (ret, bucket->pattern))
|
|
|
|
goto bail2;
|
|
|
|
table.buckets[i] = bucket->next;
|
|
|
|
FcMemFree (FC_MEM_LISTBUCK, sizeof (FcListBucket));
|
|
|
|
free (bucket);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
bail2:
|
|
|
|
FcFontSetDestroy (ret);
|
|
|
|
bail1:
|
|
|
|
FcListHashTableCleanup (&table);
|
|
|
|
bail0:
|
|
|
|
return 0;
|
|
|
|
}
|
2002-02-28 17:51:48 +01:00
|
|
|
|
|
|
|
FcFontSet *
|
|
|
|
FcFontList (FcConfig *config,
|
|
|
|
FcPattern *p,
|
|
|
|
FcObjectSet *os)
|
|
|
|
{
|
|
|
|
FcFontSet *sets[2];
|
|
|
|
int nsets;
|
|
|
|
|
|
|
|
if (!config)
|
|
|
|
{
|
|
|
|
config = FcConfigGetCurrent ();
|
|
|
|
if (!config)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
nsets = 0;
|
|
|
|
if (config->fonts[FcSetSystem])
|
|
|
|
sets[nsets++] = config->fonts[FcSetSystem];
|
|
|
|
if (config->fonts[FcSetApplication])
|
|
|
|
sets[nsets++] = config->fonts[FcSetApplication];
|
|
|
|
return FcFontSetList (config, sets, nsets, p, os);
|
|
|
|
}
|