Bug 1388059 - Ignore font size tolerance when selecting faces from a font family during global fallback. r=lsalzman
--- a/gfx/thebes/gfxFcPlatformFontList.cpp
+++ b/gfx/thebes/gfxFcPlatformFontList.cpp
@@ -1095,38 +1095,41 @@ SizeDistance(gfxFontconfigFontEntry* aEn
// Reject any non-scalable fonts that are not within tolerance.
return kRejectDistance;
}
}
void
gfxFontconfigFontFamily::FindAllFontsForStyle(const gfxFontStyle& aFontStyle,
nsTArray<gfxFontEntry*>& aFontEntryList,
- bool& aNeedsSyntheticBold)
+ bool& aNeedsSyntheticBold,
+ bool aIgnoreSizeTolerance)
{
gfxFontFamily::FindAllFontsForStyle(aFontStyle,
aFontEntryList,
- aNeedsSyntheticBold);
+ aNeedsSyntheticBold,
+ aIgnoreSizeTolerance);
if (!mHasNonScalableFaces) {
return;
}
// Iterate over the the available fonts while compacting any groups
// of unscalable fonts with matching styles into a single entry
// corresponding to the closest available size. If the closest
- // available size is rejected for being outside tolernace, then the
+ // available size is rejected for being outside tolerance, then the
// entire group will be skipped.
size_t skipped = 0;
gfxFontconfigFontEntry* bestEntry = nullptr;
double bestDist = -1.0;
for (size_t i = 0; i < aFontEntryList.Length(); i++) {
gfxFontconfigFontEntry* entry =
static_cast<gfxFontconfigFontEntry*>(aFontEntryList[i]);
- double dist = SizeDistance(entry, aFontStyle, mForceScalable);
+ double dist = SizeDistance(entry, aFontStyle,
+ mForceScalable || aIgnoreSizeTolerance);
// If the entry is scalable or has a style that does not match
// the group of unscalable fonts, then start a new group.
if (dist < 0.0 ||
!bestEntry ||
bestEntry->Stretch() != entry->Stretch() ||
bestEntry->Weight() != entry->Weight() ||
bestEntry->mStyle != entry->mStyle) {
// If the best entry in this group is still outside the tolerance,
@@ -1761,17 +1764,17 @@ gfxFcPlatformFontList::GetFTLibrary()
// so use the hacky method below of making a font and extracting
// the library pointer from that.
bool needsBold;
gfxFontStyle style;
gfxPlatformFontList* pfl = gfxPlatformFontList::PlatformFontList();
gfxFontFamily* family = pfl->GetDefaultFont(&style);
NS_ASSERTION(family, "couldn't find a default font family");
- gfxFontEntry* fe = family->FindFontForStyle(style, needsBold);
+ gfxFontEntry* fe = family->FindFontForStyle(style, needsBold, true);
if (!fe) {
return nullptr;
}
RefPtr<gfxFont> font = fe->FindOrMakeFont(&style, false);
if (!font) {
return nullptr;
}
--- a/gfx/thebes/gfxFcPlatformFontList.h
+++ b/gfx/thebes/gfxFcPlatformFontList.h
@@ -191,17 +191,18 @@ public:
void SetFamilyContainsAppFonts(bool aContainsAppFonts)
{
mContainsAppFonts = aContainsAppFonts;
}
void
FindAllFontsForStyle(const gfxFontStyle& aFontStyle,
nsTArray<gfxFontEntry*>& aFontEntryList,
- bool& aNeedsSyntheticBold) override;
+ bool& aNeedsSyntheticBold,
+ bool aIgnoreSizeTolerance) override;
protected:
virtual ~gfxFontconfigFontFamily();
nsTArray<nsCountedRef<FcPattern> > mFontPatterns;
bool mContainsAppFonts;
bool mHasNonScalableFaces;
--- a/gfx/thebes/gfxFontEntry.cpp
+++ b/gfx/thebes/gfxFontEntry.cpp
@@ -1096,20 +1096,22 @@ gfxFontFamily::HasOtherFamilyNames()
if (!mOtherFamilyNamesInitialized) {
ReadOtherFamilyNames(gfxPlatformFontList::PlatformFontList()); // sets mHasOtherFamilyNames
}
return mHasOtherFamilyNames;
}
gfxFontEntry*
gfxFontFamily::FindFontForStyle(const gfxFontStyle& aFontStyle,
- bool& aNeedsSyntheticBold)
+ bool& aNeedsSyntheticBold,
+ bool aIgnoreSizeTolerance)
{
AutoTArray<gfxFontEntry*,4> matched;
- FindAllFontsForStyle(aFontStyle, matched, aNeedsSyntheticBold);
+ FindAllFontsForStyle(aFontStyle, matched, aNeedsSyntheticBold,
+ aIgnoreSizeTolerance);
if (!matched.IsEmpty()) {
return matched[0];
}
return nullptr;
}
#define STYLE_SHIFT 2 // number of bits to contain style distance
@@ -1229,17 +1231,18 @@ WeightStyleStretchDistance(gfxFontEntry*
return (stretchDist << (STYLE_SHIFT + WEIGHT_SHIFT)) |
(styleDist << WEIGHT_SHIFT) |
weightDist;
}
void
gfxFontFamily::FindAllFontsForStyle(const gfxFontStyle& aFontStyle,
nsTArray<gfxFontEntry*>& aFontEntryList,
- bool& aNeedsSyntheticBold)
+ bool& aNeedsSyntheticBold,
+ bool aIgnoreSizeTolerance)
{
if (!mHasStyles) {
FindStyleVariations(); // collect faces for the family, if not already done
}
NS_ASSERTION(mAvailableFonts.Length() > 0, "font family with no faces!");
NS_ASSERTION(aFontEntryList.IsEmpty(), "non-empty fontlist passed in");
@@ -1464,17 +1467,17 @@ gfxFontFamily::FindFontForChar(GlobalFon
// so bail out immediately
return;
}
bool needsBold;
gfxFontEntry *fe =
FindFontForStyle(aMatchData->mStyle ? *aMatchData->mStyle
: gfxFontStyle(),
- needsBold);
+ needsBold, true);
if (fe && !fe->SkipDuringSystemFallback()) {
int32_t rank = 0;
if (fe->HasCharacter(aMatchData->mCh)) {
rank += RANK_MATCHED_CMAP;
aMatchData->mCount++;
--- a/gfx/thebes/gfxFontEntry.h
+++ b/gfx/thebes/gfxFontEntry.h
@@ -638,22 +638,24 @@ public:
void SetHasStyles(bool aHasStyles) { mHasStyles = aHasStyles; }
// choose a specific face to match a style using CSS font matching
// rules (weight matching occurs here). may return a face that doesn't
// precisely match (e.g. normal face when no italic face exists).
// aNeedsSyntheticBold is set to true when synthetic bolding is
// needed, false otherwise
gfxFontEntry *FindFontForStyle(const gfxFontStyle& aFontStyle,
- bool& aNeedsSyntheticBold);
+ bool& aNeedsSyntheticBold,
+ bool aIgnoreSizeTolerance = false);
virtual void
FindAllFontsForStyle(const gfxFontStyle& aFontStyle,
nsTArray<gfxFontEntry*>& aFontEntryList,
- bool& aNeedsSyntheticBold);
+ bool& aNeedsSyntheticBold,
+ bool aIgnoreSizeTolerance = false);
// checks for a matching font within the family
// used as part of the font fallback process
void FindFontForChar(GlobalFontMatch *aMatchData);
// checks all fonts for a matching font within the family
void SearchAllFontsForChar(GlobalFontMatch *aMatchData);