Bug 1165693 - Cache the result of calling FcConfigSubstitute for our sentinel font name, to make gfxFcPlatformFontList::FindFamily less expensive. r=jdaggett

This commit is contained in:
Jonathan Kew 2015-06-08 07:14:06 +01:00
Родитель 26d45a9e4f
Коммит b1b410165b
2 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -58,6 +58,8 @@ ToCharPtr(const FcChar8 *aStr)
}
FT_Library gfxFcPlatformFontList::sCairoFTLibrary = nullptr;
FcChar8* gfxFcPlatformFontList::sSentinelFirstFamily = nullptr;
static cairo_user_data_key_t sFcFontlistUserFontDataKey;
// canonical name ==> first en name or first name if no en name
@ -1046,6 +1048,8 @@ gfxFcPlatformFontList::InitFontList()
#endif
mOtherFamilyNamesInitialized = true;
sSentinelFirstFamily = nullptr;
return NS_OK;
}
@ -1236,13 +1240,13 @@ gfxFcPlatformFontList::FindFamily(const nsAString& aFamily,
// In this case fontconfig is including Tex Gyre Heros and
// Nimbus Sans L as alternatives for Helvetica.
// substitutions for serif pattern
const FcChar8* kSentinelName = ToFcChar8Ptr("-moz-sentinel");
nsAutoRef<FcPattern> sentinelSubst(FcPatternCreate());
FcPatternAddString(sentinelSubst, FC_FAMILY, kSentinelName);
FcConfigSubstitute(nullptr, sentinelSubst, FcMatchPattern);
FcChar8* sentinelFirstFamily = nullptr;
FcPatternGetString(sentinelSubst, FC_FAMILY, 0, &sentinelFirstFamily);
if (!sSentinelFirstFamily) {
nsAutoRef<FcPattern> sentinelSubst(FcPatternCreate());
FcPatternAddString(sentinelSubst, FC_FAMILY, kSentinelName);
FcConfigSubstitute(nullptr, sentinelSubst, FcMatchPattern);
FcPatternGetString(sentinelSubst, FC_FAMILY, 0, &sSentinelFirstFamily);
}
// substitutions for font, -moz-sentinel pattern
nsAutoRef<FcPattern> fontWithSentinel(FcPatternCreate());
@ -1251,7 +1255,7 @@ gfxFcPlatformFontList::FindFamily(const nsAString& aFamily,
FcPatternAddString(fontWithSentinel, FC_FAMILY, kSentinelName);
FcConfigSubstitute(nullptr, fontWithSentinel, FcMatchPattern);
// iterate through substitutions until hitting the first serif font
// iterate through substitutions until hitting the sentinel
FcChar8* substName = nullptr;
for (int i = 0;
FcPatternGetString(fontWithSentinel, FC_FAMILY,
@ -1259,7 +1263,8 @@ gfxFcPlatformFontList::FindFamily(const nsAString& aFamily,
i++)
{
NS_ConvertUTF8toUTF16 subst(ToCharPtr(substName));
if (sentinelFirstFamily && FcStrCmp(substName, sentinelFirstFamily) == 0) {
if (sSentinelFirstFamily &&
FcStrCmp(substName, sSentinelFirstFamily) == 0) {
break;
}
gfxFontFamily* foundFamily = gfxPlatformFontList::FindFamily(subst);

Просмотреть файл

@ -260,6 +260,7 @@ protected:
nsCountedRef<FcConfig> mLastConfig;
static FT_Library sCairoFTLibrary;
static FcChar8* sSentinelFirstFamily;
};
#endif /* GFXPLATFORMFONTLIST_H_ */