Bug 921858 - whitelist font families to avoid space lookup check for default features. r=jfkthame

This commit is contained in:
John Daggett 2014-03-20 14:43:31 +08:00
parent ba7d1fb3a6
commit 5e38053edc
5 changed files with 88 additions and 17 deletions

View File

@ -1020,6 +1020,9 @@ gfxFT2FontList::AddFaceToList(const nsCString& aEntryName, uint32_t aIndex,
if (!family) {
family = new FT2FontFamily(name);
mFontFamilies.Put(name, family);
if (mSkipSpaceLookupCheckFamilies.Contains(name)) {
family->SetSkipSpaceFeatureCheck(true);
}
if (mBadUnderlineFamilyNames.Contains(name)) {
family->SetBadUnderlineFamily();
}
@ -1318,6 +1321,9 @@ gfxFT2FontList::AppendFaceFromFontListEntry(const FontListEntry& aFLE,
if (!family) {
family = new FT2FontFamily(name);
mFontFamilies.Put(name, family);
if (mSkipSpaceLookupCheckFamilies.Contains(name)) {
family->SetSkipSpaceFeatureCheck(true);
}
if (mBadUnderlineFamilyNames.Contains(name)) {
family->SetBadUnderlineFamily();
}
@ -1348,12 +1354,27 @@ gfxFT2FontList::GetFontList(InfallibleTArray<FontListEntry>* retValue)
mFontFamilies.Enumerate(AddFamilyToFontList, retValue);
}
static void
LoadSkipSpaceLookupCheck(nsTHashtable<nsStringHashKey>& aSkipSpaceLookupCheck)
{
nsAutoTArray<nsString, 5> skiplist;
gfxFontUtils::GetPrefsFontList("font.whitelist.skip_space_lookup_check",
skiplist);
uint32_t numFonts = skiplist.Length();
for (uint32_t i = 0; i < numFonts; i++) {
ToLowerCase(skiplist[i]);
aSkipSpaceLookupCheck.PutEntry(skiplist[i]);
}
}
nsresult
gfxFT2FontList::InitFontList()
{
// reset font lists
gfxPlatformFontList::InitFontList();
LoadSkipSpaceLookupCheck(mSkipSpaceLookupCheckFamilies);
FindFonts();
return NS_OK;

View File

@ -156,6 +156,8 @@ protected:
#ifdef ANDROID
void FindFontsInDir(const nsCString& aDir, FontNameCache* aFNC);
#endif
nsTHashtable<nsStringHashKey> mSkipSpaceLookupCheckFamilies;
};
#endif /* GFX_FT2FONTLIST_H */

View File

@ -79,6 +79,14 @@ static uint32_t gGlyphExtentsSetupLazyTight = 0;
static uint32_t gGlyphExtentsSetupFallBackToTight = 0;
#endif
#ifdef PR_LOGGING
#define LOG_FONTINIT(args) PR_LOG(gfxPlatform::GetLog(eGfxLog_fontinit), \
PR_LOG_DEBUG, args)
#define LOG_FONTINIT_ENABLED() PR_LOG_TEST( \
gfxPlatform::GetLog(eGfxLog_fontinit), \
PR_LOG_DEBUG)
#endif // PR_LOGGING
void
gfxCharacterMap::NotifyReleased()
{
@ -104,6 +112,7 @@ gfxFontEntry::gfxFontEntry() :
mHasSpaceFeatures(false),
mHasSpaceFeaturesKerning(false),
mHasSpaceFeaturesNonKerning(false),
mSkipDefaultFeatureSpaceCheck(false),
mCheckedForGraphiteTables(false),
mHasCmapTable(false),
mGrFaceInitialized(false),
@ -132,6 +141,7 @@ gfxFontEntry::gfxFontEntry(const nsAString& aName, bool aIsStandardFace) :
mHasSpaceFeatures(false),
mHasSpaceFeaturesKerning(false),
mHasSpaceFeaturesNonKerning(false),
mSkipDefaultFeatureSpaceCheck(false),
mCheckedForGraphiteTables(false),
mHasCmapTable(false),
mGrFaceInitialized(false),
@ -2196,6 +2206,14 @@ gfxFont::CheckForFeaturesInvolvingSpace()
{
mFontEntry->mHasSpaceFeaturesInitialized = true;
#ifdef PR_LOGGING
bool log = LOG_FONTINIT_ENABLED();
TimeStamp start;
if (MOZ_UNLIKELY(log)) {
start = TimeStamp::Now();
}
#endif
bool result = false;
uint32_t spaceGlyph = GetSpaceGlyph();
@ -2291,10 +2309,14 @@ gfxFont::CheckForFeaturesInvolvingSpace()
hb_face_destroy(face);
mFontEntry->mHasSpaceFeatures = result;
#ifdef DEBUG_SPACE_LOOKUPS
printf("font: %s - subst default: %8.8x %8.8x %8.8x %8.8x "
#ifdef PR_LOGGING
if (MOZ_UNLIKELY(log)) {
TimeDuration elapsed = TimeStamp::Now() - start;
LOG_FONTINIT((
"(fontinit-spacelookups) font: %s - "
"subst default: %8.8x %8.8x %8.8x %8.8x "
"subst non-default: %8.8x %8.8x %8.8x %8.8x "
"kerning: %s non-kerning: %s\n",
"kerning: %s non-kerning: %s time: %6.3f\n",
NS_ConvertUTF16toUTF8(mFontEntry->Name()).get(),
mFontEntry->mDefaultSubSpaceFeatures[3],
mFontEntry->mDefaultSubSpaceFeatures[2],
@ -2305,8 +2327,10 @@ gfxFont::CheckForFeaturesInvolvingSpace()
mFontEntry->mNonDefaultSubSpaceFeatures[1],
mFontEntry->mNonDefaultSubSpaceFeatures[0],
(mFontEntry->mHasSpaceFeaturesKerning ? "true" : "false"),
(mFontEntry->mHasSpaceFeaturesNonKerning ? "true" : "false")
);
(mFontEntry->mHasSpaceFeaturesNonKerning ? "true" : "false"),
elapsed.ToMilliseconds()
));
}
#endif
}
@ -2348,6 +2372,14 @@ gfxFont::HasSubstitutionRulesWithSpaceLookups(int32_t aRunScript)
bool
gfxFont::SpaceMayParticipateInShaping(int32_t aRunScript)
{
// avoid checking fonts known not to include default space-dependent features
if (MOZ_UNLIKELY(mFontEntry->mSkipDefaultFeatureSpaceCheck)) {
if (!mKerningSet && mStyle.featureSettings.IsEmpty() &&
mFontEntry->mFeatureSettings.IsEmpty()) {
return false;
}
}
// We record the presence of space-dependent features in the font entry
// so that subsequent instantiations for the same font face won't
// require us to re-check the tables; however, the actual check is done

View File

@ -438,6 +438,7 @@ public:
bool mHasSpaceFeatures : 1;
bool mHasSpaceFeaturesKerning : 1;
bool mHasSpaceFeaturesNonKerning : 1;
bool mSkipDefaultFeatureSpaceCheck : 1;
bool mHasGraphiteTables : 1;
bool mCheckedForGraphiteTables : 1;
bool mHasCmapTable : 1;
@ -676,7 +677,8 @@ public:
mHasStyles(false),
mIsSimpleFamily(false),
mIsBadUnderlineFamily(false),
mFamilyCharacterMapInitialized(false)
mFamilyCharacterMapInitialized(false),
mSkipDefaultFeatureSpaceCheck(false)
{ }
virtual ~gfxFontFamily() { }
@ -697,6 +699,7 @@ public:
aFontEntry->mIgnoreGDEF = true;
}
aFontEntry->mFamilyName = Name();
aFontEntry->mSkipDefaultFeatureSpaceCheck = mSkipDefaultFeatureSpaceCheck;
mAvailableFonts.AppendElement(aFontEntry);
}
@ -798,6 +801,10 @@ public:
return false;
}
void SetSkipSpaceFeatureCheck(bool aSkipCheck) {
mSkipDefaultFeatureSpaceCheck = aSkipCheck;
}
protected:
// fills in an array with weights of faces that match style,
// returns whether any matching entries found
@ -828,6 +835,7 @@ protected:
bool mIsSimpleFamily : 1;
bool mIsBadUnderlineFamily : 1;
bool mFamilyCharacterMapInitialized : 1;
bool mSkipDefaultFeatureSpaceCheck : 1;
enum {
// for "simple" families, the faces are stored in mAvailableFonts

View File

@ -1512,6 +1512,14 @@ pref("font.mathfont-family", "MathJax_Main, STIXNonUnicode, STIXSizeOneSym, STIX
// These fonts are ignored the underline offset, instead of it, the underline is lowered to bottom of its em descent.
pref("font.blacklist.underline_offset", "FangSong,Gulim,GulimChe,MingLiU,MingLiU-ExtB,MingLiU_HKSCS,MingLiU-HKSCS-ExtB,MS Gothic,MS Mincho,MS PGothic,MS PMincho,MS UI Gothic,PMingLiU,PMingLiU-ExtB,SimHei,SimSun,SimSun-ExtB,Hei,Kai,Apple LiGothic,Apple LiSung,Osaka");
#ifdef MOZ_WIDGET_GONK
// Whitelist of fonts that ship with B2G that do not include space lookups in
// default features. This allows us to skip analyzing the GSUB/GPOS tables
// unless features are explicitly enabled.
// Use NSPR_LOG_MODULES=fontinit:5 to dump out details of space lookups
pref("font.whitelist.skip_default_features_space_check", "Fira Sans OT,Fira Mono OT");
#endif
pref("images.dither", "auto");
pref("security.directory", "");