/* * Font must have a containing value for every value in the pattern */ static FcBool FcListValueListMatchAny (FcValueListPtr patOrig, /* pattern */ FcValueListPtr fntOrig) /* font */ { FcValueListPtr pat, fnt; for (pat = patOrig; pat != NULL; pat = FcValueListNext(pat)) { 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 (&fnt->value, FC_OP (FcOpListing, FcOpFlagIgnoreBlanks), &pat->value)) break; } if (fnt == NULL) return FcFalse; } return FcTrue; }
static FcBool FcListValueListEqual (FcValueListPtr v1orig, FcValueListPtr v2orig) { FcValueListPtr v1, v2; for (v1 = v1orig; v1 != NULL; v1 = FcValueListNext(v1)) { for (v2 = v2orig; v2 != NULL; v2 = FcValueListNext(v2)) if (FcValueEqual (FcValueCanonicalize(&(v1)->value), FcValueCanonicalize(&(v2)->value))) break; if (v2 == NULL) return FcFalse; } for (v2 = v2orig; v2 != NULL; v2 = FcValueListNext(v2)) { for (v1 = v1orig; v1 != NULL; v1 = FcValueListNext(v1)) if (FcValueEqual (FcValueCanonicalize(&v1->value), FcValueCanonicalize(&v2->value))) break; if (v1 == NULL) return FcFalse; } return FcTrue; }
static int FcGetDefaultObjectLangIndex (FcPattern *font, FcObject object) { FcChar8 *lang = FcGetDefaultLang (); FcPatternElt *e = FcPatternObjectFindElt (font, object); FcValueListPtr v; FcValue value; int idx = -1; int i; if (e) { for (v = FcPatternEltValues(e), i = 0; v; v = FcValueListNext(v), ++i) { value = FcValueCanonicalize (&v->value); 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; }
static FcValueList * FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding) { FcValueList *l; if (!e) return 0; l = (FcValueList *) malloc (sizeof (FcValueList)); if (!l) return 0; FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList)); if (e->op == FcOpComma) { l->value = FcConfigEvaluate (p, e->u.tree.left); l->next = FcConfigValues (p, e->u.tree.right, binding); } else { l->value = FcConfigEvaluate (p, e); l->next = NULL; } l->binding = binding; if (l->value.type == FcTypeVoid) { FcValueList *next = FcValueListNext(l); FcMemFree (FC_MEM_VALLIST, sizeof (FcValueList)); free (l); l = next; } return l; }
void FcValueListPrintWithPosition(FcValueListPtr l, const FcValueListPtr pos) { for (; l != NULL; l = FcValueListNext(l)) { FcValuePrintWithPosition(FcValueCanonicalize(&l->value), pos != NULL && l == pos); FcValueBindingPrint(l); } if (!pos) printf(" [marker]"); }
void FcValueListPrint(FcValueListPtr l) { #ifdef _DEBUG for (; l != NULL; l = FcValueListNext(l)) { FcValuePrint(FcValueCanonicalize(&l->value)); FcValueBindingPrint(l); } #endif }
static FcChar32 FcListValueListHash (FcValueListPtr list) { FcChar32 h = 0; while (list != NULL) { h = h ^ FcListValueHash (&list->value); list = FcValueListNext(list); } return h; }
FcBool FcNameUnparseValueList (FcStrBuf *buf, FcValueListPtr v, FcChar8 *escape) { while (v) { if (!FcNameUnparseValue (buf, &v->value, escape)) return FcFalse; if ((v = FcValueListNext(v)) != NULL) if (!FcNameUnparseString (buf, (FcChar8 *) ",", 0)) return FcFalse; } return FcTrue; }
static FcValueList * FcConfigMatchValueList (FcPattern *p, FcTest *t, FcValueList *values) { FcValueList *ret = 0; FcExpr *e = t->expr; FcValue value; FcValueList *v; while (e) { /* Compute the value of the match expression */ if (e->op == FcOpComma) { value = FcConfigEvaluate (p, e->u.tree.left); e = e->u.tree.right; } else { value = FcConfigEvaluate (p, e); e = 0; } for (v = values; v; v = FcValueListNext(v)) { /* Compare the pattern value to the match expression value */ if (FcConfigCompareValue (&v->value, t->op, &value)) { if (!ret) ret = v; } else { if (t->qual == FcQualAll) { ret = 0; break; } } } FcValueDestroy (value); } return ret; }
void FcValueListPrint (FcValueListPtr l) { for (; l != NULL; l = FcValueListNext(l)) { FcValuePrint (FcValueCanonicalize(&l->value)); switch (l->binding) { case FcValueBindingWeak: printf ("(w)"); break; case FcValueBindingStrong: printf ("(s)"); break; case FcValueBindingSame: printf ("(=)"); break; } } }
static int FcGetDefaultObjectLangIndex (FcPattern *font, FcObject object, const FcChar8 *lang) { FcPatternElt *e = FcPatternObjectFindElt (font, object); FcValueListPtr v; FcValue value; int idx = -1; int defidx = -1; int i; if (e) { for (v = FcPatternEltValues(e), i = 0; v; v = FcValueListNext(v), ++i) { value = FcValueCanonicalize (&v->value); if (value.type == FcTypeString) { FcLangResult res = FcLangCompare (value.u.s, lang); if (res == FcLangEqual) return i; if (res == FcLangDifferentCountry && idx < 0) idx = i; if (defidx < 0) { /* workaround for fonts that has non-English value * at the head of values. */ res = FcLangCompare (value.u.s, (FcChar8 *)"en"); if (res == FcLangEqual) defidx = i; } } } } return (idx > 0) ? idx : (defidx > 0) ? defidx : 0; }
static FcBool FcListAppend (FcListHashTable *table, FcPattern *font, FcObjectSet *os, const FcChar8 *lang) { int o; FcPatternElt *e; FcValueListPtr v; FcChar32 hash; FcListBucket **prev, *bucket; int familyidx = -1; int fullnameidx = -1; int styleidx = -1; int defidx = 0; int idx; 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++) { if (!strcmp (os->objects[o], FC_FAMILY) || !strcmp (os->objects[o], FC_FAMILYLANG)) { if (familyidx < 0) familyidx = FcGetDefaultObjectLangIndex (font, FC_FAMILYLANG_OBJECT, lang); defidx = familyidx; } else if (!strcmp (os->objects[o], FC_FULLNAME) || !strcmp (os->objects[o], FC_FULLNAMELANG)) { if (fullnameidx < 0) fullnameidx = FcGetDefaultObjectLangIndex (font, FC_FULLNAMELANG_OBJECT, lang); defidx = fullnameidx; } else if (!strcmp (os->objects[o], FC_STYLE) || !strcmp (os->objects[o], FC_STYLELANG)) { if (styleidx < 0) styleidx = FcGetDefaultObjectLangIndex (font, FC_STYLELANG_OBJECT, lang); defidx = styleidx; } else defidx = 0; e = FcPatternObjectFindElt (font, FcObjectFromName (os->objects[o])); if (e) { for (v = FcPatternEltValues(e), idx = 0; v; v = FcValueListNext(v), ++idx) { if (!FcPatternAdd (bucket->pattern, os->objects[o], FcValueCanonicalize(&v->value), defidx != idx)) goto bail2; } } } *prev = bucket; ++table->entries; return FcTrue; bail2: FcPatternDestroy (bucket->pattern); bail1: FcMemFree (FC_MEM_LISTBUCK, sizeof (FcListBucket)); free (bucket); bail0: return FcFalse; }
void FcValueListPrint(FcValueListPtr l) { for (; l != NULL; l = FcValueListNext(l)) { FcValuePrint(FcValueCanonicalize(&l->value)); FcValueBindingPrint(l); } }
static FcBool FcCompareValueList (FcObject object, const FcMatcher *match, FcValueListPtr v1orig, /* pattern */ FcValueListPtr v2orig, /* target */ FcValue *bestValue, double *value, int *n, FcResult *result) { FcValueListPtr v1, v2; double v, best, bestStrong, bestWeak; int j, k, pos = 0; if (!match) { if (bestValue) *bestValue = FcValueCanonicalize(&v2orig->value); if (n) *n = 0; return FcTrue; } best = 1e99; bestStrong = 1e99; bestWeak = 1e99; j = 1; for (v1 = v1orig; v1; v1 = FcValueListNext(v1)) { for (v2 = v2orig, k = 0; v2; v2 = FcValueListNext(v2), k++) { v = (match->compare) (&v1->value, &v2->value); if (v < 0) { *result = FcResultTypeMismatch; return FcFalse; } v = v * 1000 + j; if (v < best) { if (bestValue) *bestValue = FcValueCanonicalize(&v2->value); best = v; pos = k; } if (v1->binding == FcValueBindingStrong) { if (v < bestStrong) bestStrong = v; } else { if (v < bestWeak) bestWeak = v; } } j++; } if (FcDebug () & FC_DBG_MATCHV) { printf (" %s: %g ", FcObjectName (object), best); FcValueListPrint (v1orig); printf (", "); FcValueListPrint (v2orig); printf ("\n"); } if (value) { int weak = match->weak; int strong = match->strong; if (weak == strong) value[strong] += best; else { value[weak] += bestWeak; value[strong] += bestStrong; } } if (n) *n = pos; return FcTrue; }