b=546315 use weak bindings to give lower priority to families after a generic r=jfkthame

This commit is contained in:
Karl Tomlinson 2011-03-23 23:14:32 -04:00
parent 7a7c138786
commit e2e2d9d82c

View File

@ -206,6 +206,16 @@ AddString(FcPattern *aPattern, const char *object, const char *aString)
gfxFontconfigUtils::ToFcChar8(aString));
}
static void
AddWeakString(FcPattern *aPattern, const char *object, const char *aString)
{
FcValue value;
value.type = FcTypeString;
value.u.s = gfxFontconfigUtils::ToFcChar8(aString);
FcPatternAddWeak(aPattern, object, value, FcTrue);
}
static void
AddLangGroup(FcPattern *aPattern, nsIAtom *aLangGroup)
{
@ -218,12 +228,14 @@ AddLangGroup(FcPattern *aPattern, nsIAtom *aLangGroup)
}
}
nsReturnRef<FcPattern>
gfxFontconfigUtils::NewPattern(const nsTArray<nsString>& aFamilies,
const gfxFontStyle& aFontStyle,
const char *aLang)
{
static const char* sFontconfigGenerics[] =
{ "sans-serif", "serif", "monospace", "fantasy", "cursive" };
nsAutoRef<FcPattern> pattern(FcPatternCreate());
if (!pattern)
return nsReturnRef<FcPattern>();
@ -236,9 +248,30 @@ gfxFontconfigUtils::NewPattern(const nsTArray<nsString>& aFamilies,
AddString(pattern, FC_LANG, aLang);
}
PRBool useWeakBinding = PR_FALSE;
for (PRUint32 i = 0; i < aFamilies.Length(); ++i) {
NS_ConvertUTF16toUTF8 family(aFamilies[i]);
AddString(pattern, FC_FAMILY, family.get());
if (!useWeakBinding) {
AddString(pattern, FC_FAMILY, family.get());
// fontconfig generic families are typically implemented with weak
// aliases (so that the preferred font depends on language).
// However, this would give them lower priority than subsequent
// non-generic families in the list. To ensure that subsequent
// families do not have a higher priority, they are given weak
// bindings.
for (PRUint32 g = 0;
g < NS_ARRAY_LENGTH(sFontconfigGenerics);
++g) {
if (FcStrCmpIgnoreCase(ToFcChar8(sFontconfigGenerics[g]),
ToFcChar8(family.get()))) {
useWeakBinding = PR_TRUE;
break;
}
}
} else {
AddWeakString(pattern, FC_FAMILY, family.get());
}
}
return pattern.out();