static FcBool FcCompare (FcPattern *pat, FcPattern *fnt, double *value, FcResult *result) { int i, i1, i2; for (i = 0; i < NUM_MATCH_VALUES; i++) value[i] = 0.0; i1 = 0; i2 = 0; while (i1 < pat->num && i2 < fnt->num) { FcPatternElt *elt_i1 = &FcPatternElts(pat)[i1]; FcPatternElt *elt_i2 = &FcPatternElts(fnt)[i2]; i = FcObjectCompare(elt_i1->object, elt_i2->object); if (i > 0) i2++; else if (i < 0) i1++; else { const FcMatcher *match = FcObjectToMatcher (elt_i1->object, FcFalse); if (!FcCompareValueList (elt_i1->object, match, FcPatternEltValues(elt_i1), FcPatternEltValues(elt_i2), NULL, value, NULL, result)) return FcFalse; i1++; i2++; } } return FcTrue; }
static FcBool FcCompareValueList (FcObject object, FcValueListPtr v1orig, /* pattern */ FcValueListPtr v2orig, /* target */ FcValue *bestValue, double *value, FcResult *result) { FcValueListPtr v1, v2; double v, best, bestStrong, bestWeak; int j; const FcMatcher *match = FcObjectToMatcher(object); if (!match) { if (bestValue) *bestValue = FcValueCanonicalize(&v2orig->value); return FcTrue; } best = 1e99; bestStrong = 1e99; bestWeak = 1e99; j = 1; for (v1 = v1orig; v1; v1 = FcValueListNext(v1)) { for (v2 = v2orig; v2; v2 = FcValueListNext(v2)) { 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; } 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; } } return FcTrue; }