X-Git-Url: https://git.wh0rd.org/?p=fontconfig.git;a=blobdiff_plain;f=src%2Ffclist.c;h=9a84b5c7e9e7b9edf4ed7eb79358fc502ce4292c;hp=35d68aed421e56b3936527e5ec5d5d52b79b2ca9;hb=HEAD;hpb=904426816df300fad816238f0f27ef595a6a539b diff --git a/src/fclist.c b/src/fclist.c index 35d68ae..9a84b5c 100644 --- a/src/fclist.c +++ b/src/fclist.c @@ -1,5 +1,5 @@ /* - * $RCSId: xc/lib/fontconfig/src/fclist.c,v 1.11tsi Exp $ + * fontconfig/src/fclist.c * * Copyright © 2000 Keith Packard * @@ -7,23 +7,23 @@ * 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 + * documentation, and that the name of the author(s) not be used in * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no + * specific, written prior permission. The authors make 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, + * THE AUTHOR(S) 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 + * EVENT SHALL THE AUTHOR(S) 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 #include "fcint.h" +#include FcObjectSet * FcObjectSetCreate (void) @@ -46,7 +46,7 @@ FcObjectSetAdd (FcObjectSet *os, const char *object) int s; const char **objects; int high, low, mid, c; - + if (os->nobject == os->sobject) { s = os->sobject + 4; @@ -81,7 +81,7 @@ FcObjectSetAdd (FcObjectSet *os, const char *object) } if (c < 0) mid++; - memmove (os->objects + mid + 1, os->objects + mid, + memmove (os->objects + mid + 1, os->objects + mid, (os->nobject - mid) * sizeof (const char *)); os->objects[mid] = object; os->nobject++; @@ -130,23 +130,21 @@ FcListValueListMatchAny (FcValueListPtr patOrig, /* pattern */ { FcValueListPtr pat, fnt; - for (pat = patOrig; FcValueListPtrU(pat); - pat = FcValueListPtrU(pat)->next) + for (pat = patOrig; pat != NULL; pat = FcValueListNext(pat)) { - for (fnt = fntOrig; FcValueListPtrU(fnt); - fnt = FcValueListPtrU(fnt)->next) + for (fnt = fntOrig; fnt != NULL; fnt = FcValueListNext(fnt)) { /* * make sure the font 'contains' the pattern. * (OpListing is OpContains except for strings * where it requires an exact match) */ - if (FcConfigCompareValue (&FcValueListPtrU(fnt)->value, - FcOpListing, - &FcValueListPtrU(pat)->value)) + if (FcConfigCompareValue (&fnt->value, + FcOpListing, + &pat->value)) break; } - if (!FcValueListPtrU(fnt)) + if (fnt == NULL) return FcFalse; } return FcTrue; @@ -158,26 +156,22 @@ FcListValueListEqual (FcValueListPtr v1orig, { FcValueListPtr v1, v2; - for (v1 = v1orig; FcValueListPtrU(v1); - v1 = FcValueListPtrU(v1)->next) + for (v1 = v1orig; v1 != NULL; v1 = FcValueListNext(v1)) { - for (v2 = v2orig; FcValueListPtrU(v2); - v2 = FcValueListPtrU(v2)->next) - if (FcValueEqual (FcValueCanonicalize(&FcValueListPtrU(v1)->value), - FcValueCanonicalize(&FcValueListPtrU(v2)->value))) + for (v2 = v2orig; v2 != NULL; v2 = FcValueListNext(v2)) + if (FcValueEqual (FcValueCanonicalize(&(v1)->value), + FcValueCanonicalize(&(v2)->value))) break; - if (!FcValueListPtrU(v2)) + if (v2 == NULL) return FcFalse; } - for (v2 = v2orig; FcValueListPtrU(v2); - v2 = FcValueListPtrU(v2)->next) + for (v2 = v2orig; v2 != NULL; v2 = FcValueListNext(v2)) { - for (v1 = v1orig; FcValueListPtrU(v1); - v1 = FcValueListPtrU(v1)->next) - if (FcValueEqual (FcValueCanonicalize(&FcValueListPtrU(v1)->value), - FcValueCanonicalize(&FcValueListPtrU(v2)->value))) + for (v1 = v1orig; v1 != NULL; v1 = FcValueListNext(v1)) + if (FcValueEqual (FcValueCanonicalize(&v1->value), + FcValueCanonicalize(&v2->value))) break; - if (!FcValueListPtrU(v1)) + if (v1 == NULL) return FcFalse; } return FcTrue; @@ -193,13 +187,14 @@ FcListPatternEqual (FcPattern *p1, for (i = 0; i < os->nobject; i++) { - e1 = FcPatternFindElt (p1, os->objects[i]); - e2 = FcPatternFindElt (p2, os->objects[i]); + e1 = FcPatternObjectFindElt (p1, FcObjectFromName (os->objects[i])); + e2 = FcPatternObjectFindElt (p2, FcObjectFromName (os->objects[i])); if (!e1 && !e2) continue; if (!e1 || !e2) return FcFalse; - if (!FcListValueListEqual (e1->values, e2->values)) + if (!FcListValueListEqual (FcPatternEltValues(e1), + FcPatternEltValues(e2))) return FcFalse; } return FcTrue; @@ -214,16 +209,15 @@ FcListPatternMatchAny (const FcPattern *p, const FcPattern *font) { int i; - FcPatternElt *e; for (i = 0; i < p->num; i++) { - e = FcPatternFindElt (font, - FcObjectPtrU((FcPatternEltU(p->elts)+i)->object)); - if (!e) + FcPatternElt *pe = &FcPatternElts(p)[i]; + FcPatternElt *fe = FcPatternObjectFindElt (font, pe->object); + if (!fe) return FcFalse; - if (!FcListValueListMatchAny ((FcPatternEltU(p->elts)+i)->values, /* pat elts */ - e->values)) /* font elts */ + if (!FcListValueListMatchAny (FcPatternEltValues(pe), /* pat elts */ + FcPatternEltValues(fe))) /* font elts */ return FcFalse; } return FcTrue; @@ -232,8 +226,8 @@ FcListPatternMatchAny (const FcPattern *p, static FcChar32 FcListMatrixHash (const FcMatrix *m) { - int xx = (int) (m->xx * 100), - xy = (int) (m->xy * 100), + int xx = (int) (m->xx * 100), + xy = (int) (m->xy * 100), yx = (int) (m->yx * 100), yy = (int) (m->yy * 100); @@ -271,11 +265,11 @@ static FcChar32 FcListValueListHash (FcValueListPtr list) { FcChar32 h = 0; - - while (FcValueListPtrU(list)) + + while (list != NULL) { - h = h ^ FcListValueHash (&FcValueListPtrU(list)->value); - list = FcValueListPtrU(list)->next; + h = h ^ FcListValueHash (&list->value); + list = FcValueListNext(list); } return h; } @@ -290,9 +284,9 @@ FcListPatternHash (FcPattern *font, for (n = 0; n < os->nobject; n++) { - e = FcPatternFindElt (font, os->objects[n]); + e = FcPatternObjectFindElt (font, FcObjectFromName (os->objects[n])); if (e) - h = h ^ FcListValueListHash (e->values); + h = h ^ FcListValueListHash (FcPatternEltValues(e)); } return h; } @@ -309,7 +303,7 @@ typedef struct _FcListHashTable { int entries; FcListBucket *buckets[FC_LIST_HASH_SIZE]; } FcListHashTable; - + static void FcListHashTableInit (FcListHashTable *table) { @@ -338,10 +332,10 @@ FcListHashTableCleanup (FcListHashTable *table) } static int -FcGetDefaultObjectLangIndex (FcPattern *font, const char *object) +FcGetDefaultObjectLangIndex (FcPattern *font, FcObject object) { FcChar8 *lang = FcGetDefaultLang (); - FcPatternElt *e = FcPatternFindElt (font, object); + FcPatternElt *e = FcPatternObjectFindElt (font, object); FcValueListPtr v; FcValue value; int idx = -1; @@ -349,14 +343,17 @@ FcGetDefaultObjectLangIndex (FcPattern *font, const char *object) if (e) { - for (v = e->values, i = 0; FcValueListPtrU(v); v = FcValueListPtrU(v)->next, ++i) + for (v = FcPatternEltValues(e), i = 0; v; v = FcValueListNext(v), ++i) { - value = FcValueCanonicalize (&FcValueListPtrU (v)->value); + value = FcValueCanonicalize (&v->value); if (value.type == FcTypeString) { FcLangResult res = FcLangCompare (value.u.s, lang); - if (res == FcLangEqual || (res == FcLangDifferentCountry && idx < 0)) + if (res == FcLangEqual) + return i; + + if (res == FcLangDifferentCountry && idx < 0) idx = i; } } @@ -385,7 +382,7 @@ FcListAppend (FcListHashTable *table, for (prev = &table->buckets[hash % FC_LIST_HASH_SIZE]; (bucket = *prev); prev = &(bucket->next)) { - if (bucket->hash == hash && + if (bucket->hash == hash && FcListPatternEqual (bucket->pattern, font, os)) return FcTrue; } @@ -398,39 +395,39 @@ FcListAppend (FcListHashTable *table, bucket->pattern = FcPatternCreate (); if (!bucket->pattern) goto bail1; - + for (o = 0; o < os->nobject; o++) { if (!strcmp (os->objects[o], FC_FAMILY) || !strcmp (os->objects[o], FC_FAMILYLANG)) { if (familyidx < 0) - familyidx = FcGetDefaultObjectLangIndex (font, FC_FAMILYLANG); + familyidx = FcGetDefaultObjectLangIndex (font, FC_FAMILYLANG_OBJECT); defidx = familyidx; } else if (!strcmp (os->objects[o], FC_FULLNAME) || !strcmp (os->objects[o], FC_FULLNAMELANG)) { if (fullnameidx < 0) - fullnameidx = FcGetDefaultObjectLangIndex (font, FC_FULLNAMELANG); + fullnameidx = FcGetDefaultObjectLangIndex (font, FC_FULLNAMELANG_OBJECT); defidx = fullnameidx; } else if (!strcmp (os->objects[o], FC_STYLE) || !strcmp (os->objects[o], FC_STYLELANG)) { if (styleidx < 0) - styleidx = FcGetDefaultObjectLangIndex (font, FC_STYLELANG); + styleidx = FcGetDefaultObjectLangIndex (font, FC_STYLELANG_OBJECT); defidx = styleidx; } else defidx = 0; - e = FcPatternFindElt (font, os->objects[o]); + e = FcPatternObjectFindElt (font, FcObjectFromName (os->objects[o])); if (e) { - for (v = e->values, idx = 0; FcValueListPtrU(v); - v = FcValueListPtrU(v)->next, ++idx) + for (v = FcPatternEltValues(e), idx = 0; v; + v = FcValueListNext(v), ++idx) { - if (!FcPatternAdd (bucket->pattern, - os->objects[o], - FcValueCanonicalize(&FcValueListPtrU(v)->value), defidx != idx)) + if (!FcPatternAdd (bucket->pattern, + os->objects[o], + FcValueCanonicalize(&v->value), defidx != idx)) goto bail2; } } @@ -439,7 +436,7 @@ FcListAppend (FcListHashTable *table, ++table->entries; return FcTrue; - + bail2: FcPatternDestroy (bucket->pattern); bail1: @@ -463,6 +460,7 @@ FcFontSetList (FcConfig *config, FcListHashTable table; int i; FcListBucket *bucket; + int destroy_os = 0; if (!config) { @@ -474,6 +472,13 @@ FcFontSetList (FcConfig *config, goto bail0; } FcListHashTableInit (&table); + + if (!os) + { + os = FcObjectGetSet (); + destroy_os = 1; + } + /* * Walk all available fonts adding those that * match to the hash table @@ -510,7 +515,7 @@ FcFontSetList (FcConfig *config, full++; } } - printf ("used: %d max: %d avg: %g\n", full, max, + printf ("used: %d max: %d avg: %g\n", full, max, (double) ents / FC_LIST_HASH_SIZE); } #endif @@ -530,7 +535,7 @@ FcFontSetList (FcConfig *config, FcMemFree (FC_MEM_LISTBUCK, sizeof (FcListBucket)); free (bucket); } - + return ret; bail2: @@ -538,6 +543,8 @@ bail2: bail1: FcListHashTableCleanup (&table); bail0: + if (destroy_os) + FcObjectSetDestroy (os); return 0; } @@ -551,6 +558,9 @@ FcFontList (FcConfig *config, if (!config) { + if (!FcInitBringUptoDate ()) + return 0; + config = FcConfigGetCurrent (); if (!config) return 0; @@ -562,3 +572,6 @@ FcFontList (FcConfig *config, sets[nsets++] = config->fonts[FcSetApplication]; return FcFontSetList (config, sets, nsets, p, os); } +#define __fclist__ +#include "fcaliastail.h" +#undef __fclist__