static FcBool FcLangContains (const FcChar8 *super, const FcChar8 *sub) { FcChar8 c1, c2; for (;;) { c1 = *super++; c2 = *sub++; c1 = FcToLower (c1); c2 = FcToLower (c2); if (c1 != c2) { /* see if super has a country while sub is mising one */ if (c1 == '-' && c2 == '\0') return FcTrue; /* see if sub has a country while super is mising one */ if (c1 == '\0' && c2 == '-') return FcTrue; return FcFalse; } else if (!c1) return FcTrue; } }
FcLangResult FcLangCompare (const FcChar8 *s1, const FcChar8 *s2) { FcChar8 c1, c2; FcLangResult result = FcLangDifferentLang; for (;;) { c1 = *s1++; c2 = *s2++; c1 = FcToLower (c1); c2 = FcToLower (c2); if (c1 != c2) { if (FcLangEnd (c1) && FcLangEnd (c2)) result = FcLangDifferentTerritory; return result; } else if (!c1) return FcLangEqual; else if (c1 == '-') result = FcLangDifferentTerritory; } }
FcBool FcNameBool (const FcChar8 *v, FcBool *result) { char c0, c1; c0 = *v; c0 = FcToLower (c0); if (c0 == 't' || c0 == 'y' || c0 == '1') { *result = FcTrue; return FcTrue; } if (c0 == 'f' || c0 == 'n' || c0 == '0') { *result = FcFalse; return FcTrue; } if (c0 == 'o') { c1 = v[1]; c1 = FcToLower (c1); if (c1 == 'n') { *result = FcTrue; return FcTrue; } if (c1 == 'f') { *result = FcFalse; return FcTrue; } } return FcFalse; }
static double FcCompareFamily (FcValue *v1, FcValue *v2) { /* rely on the guarantee in FcPatternObjectAddWithBinding that * families are always FcTypeString. */ const FcChar8* v1_string = FcValueString(v1); const FcChar8* v2_string = FcValueString(v2); if (FcToLower(*v1_string) != FcToLower(*v2_string) && *v1_string != ' ' && *v2_string != ' ') return 1.0; return (double) FcStrCmpIgnoreBlanksAndCase (v1_string, v2_string) != 0; }
static FcBool FcCompareValueList (const char *object, FcValueList *v1orig, /* pattern */ FcValueList *v2orig, /* target */ FcValue *bestValue, double *value, FcResult *result) { FcValueList *v1, *v2; double v, best, bestStrong, bestWeak; int i; int j; /* * Locate the possible matching entry by examining the * first few characters in object */ i = -1; switch (FcToLower (object[0])) { case 'f': switch (FcToLower (object[1])) { case 'o': switch (FcToLower (object[2])) { case 'u': i = MATCH_FOUNDRY; break; case 'n': i = MATCH_FONTVERSION; break; } break; case 'a': i = MATCH_FAMILY; break; } break; case 'c': i = MATCH_CHARSET; break; case 'a': i = MATCH_ANTIALIAS; break; case 'l': i = MATCH_LANG; break; case 's': switch (FcToLower (object[1])) { case 'p': i = MATCH_SPACING; break; case 't': i = MATCH_STYLE; break; case 'l': i = MATCH_SLANT; break; } break; case 'p': i = MATCH_PIXEL_SIZE; break; case 'w': switch (FcToLower (object[1])) { case 'i': i = MATCH_WIDTH; break; case 'e': i = MATCH_WEIGHT; break; } break; case 'r': i = MATCH_RASTERIZER; break; case 'o': i = MATCH_OUTLINE; break; } if (i == -1 || FcStrCmpIgnoreCase ((FcChar8 *) _FcMatchers[i].object, (FcChar8 *) object) != 0) { if (bestValue) *bestValue = v2orig->value; return FcTrue; } #if 0 for (i = 0; i < NUM_MATCHER; i++) { if (!FcStrCmpIgnoreCase ((FcChar8 *) _FcMatchers[i].object, (FcChar8 *) object)) break; } if (i == NUM_MATCHER) { if (bestValue) *bestValue = v2orig->value; return FcTrue; } #endif best = 1e99; bestStrong = 1e99; bestWeak = 1e99; j = 0; for (v1 = v1orig; v1; v1 = v1->next) { for (v2 = v2orig; v2; v2 = v2->next) { v = (*_FcMatchers[i].compare) (_FcMatchers[i].object, v1->value, v2->value); if (v < 0) { *result = FcResultTypeMismatch; return FcFalse; } if (FcDebug () & FC_DBG_MATCHV) printf (" v %g j %d ", v, j); v = v * 100 + j; if (v < best) { if (bestValue) *bestValue = 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 ", object, best); FcValueListPrint (v1orig); printf (", "); FcValueListPrint (v2orig); printf ("\n"); } if (value) { int weak = _FcMatchers[i].weak; int strong = _FcMatchers[i].strong; if (weak == strong) value[strong] += best; else { value[weak] += bestWeak; value[strong] += bestStrong; } } return FcTrue; }