Allow bitmap fonts to force scaling and bypass tolerance check in gfxFcPlatformFontList.

This commit is contained in:
wolfbeast 2018-03-27 21:20:57 +02:00 • committed by Roy Tam
commit 4a9865465f
2 changed files with 23 additions and 4 deletions

View file

@ -811,6 +811,15 @@ ChooseFontSize(gfxFontconfigFontEntry* aEntry,
bestSize = size; bestSize = size;
} }
} }
// If the font has bitmaps but wants to be scaled, then let it scale.
if (bestSize >= 0.0) {
FcBool scalable;
if (FcPatternGetBool(aEntry->GetPattern(),
FC_SCALABLE, 0, &scalable) == FcResultMatch &&
scalable) {
return requestedSize;
}
}
return bestSize; return bestSize;
} }
@ -950,6 +959,12 @@ gfxFontconfigFontFamily::AddFontPattern(FcPattern* aFontPattern)
if (FcPatternGetBool(aFontPattern, FC_OUTLINE, 0, &outline) != FcResultMatch || if (FcPatternGetBool(aFontPattern, FC_OUTLINE, 0, &outline) != FcResultMatch ||
!outline) { !outline) {
mHasNonScalableFaces = true; mHasNonScalableFaces = true;
FcBool scalable;
if (FcPatternGetBool(aFontPattern, FC_SCALABLE, 0, &scalable) == FcResultMatch &&
scalable) {
mForceScalable = true;
}
} }
nsCountedRef<FcPattern> pattern(aFontPattern); nsCountedRef<FcPattern> pattern(aFontPattern);
@ -961,7 +976,9 @@ static const double kRejectDistance = 10000.0;
// Calculate a distance score representing the size disparity between the // Calculate a distance score representing the size disparity between the
// requested style's size and the font entry's size. // requested style's size and the font entry's size.
static double static double
SizeDistance(gfxFontconfigFontEntry* aEntry, const gfxFontStyle& aStyle) SizeDistance(gfxFontconfigFontEntry* aEntry,
const gfxFontStyle& aStyle,
bool aForceScalable)
{ {
double requestedSize = SizeForStyle(aEntry, aStyle); double requestedSize = SizeForStyle(aEntry, aStyle);
double bestDist = -1.0; double bestDist = -1.0;
@ -978,7 +995,7 @@ SizeDistance(gfxFontconfigFontEntry* aEntry, const gfxFontStyle& aStyle)
if (bestDist < 0.0) { if (bestDist < 0.0) {
// No size means scalable // No size means scalable
return -1.0; return -1.0;
} else if (5.0 * bestDist < requestedSize) { } else if (aForceScalable || 5.0 * bestDist < requestedSize) {
// fontconfig prefers a matching family or lang to pixelsize of bitmap // fontconfig prefers a matching family or lang to pixelsize of bitmap
// fonts. CSS suggests a tolerance of 20% on pixelsize. // fonts. CSS suggests a tolerance of 20% on pixelsize.
return bestDist; return bestDist;
@ -1012,7 +1029,7 @@ gfxFontconfigFontFamily::FindAllFontsForStyle(const gfxFontStyle& aFontStyle,
for (size_t i = 0; i < aFontEntryList.Length(); i++) { for (size_t i = 0; i < aFontEntryList.Length(); i++) {
gfxFontconfigFontEntry* entry = gfxFontconfigFontEntry* entry =
static_cast<gfxFontconfigFontEntry*>(aFontEntryList[i]); static_cast<gfxFontconfigFontEntry*>(aFontEntryList[i]);
double dist = SizeDistance(entry, aFontStyle); double dist = SizeDistance(entry, aFontStyle, mForceScalable);
// If the entry is scalable or has a style that does not match // If the entry is scalable or has a style that does not match
// the group of unscalable fonts, then start a new group. // the group of unscalable fonts, then start a new group.
if (dist < 0.0 || if (dist < 0.0 ||

View file

@ -175,7 +175,8 @@ public:
explicit gfxFontconfigFontFamily(const nsAString& aName) : explicit gfxFontconfigFontFamily(const nsAString& aName) :
gfxFontFamily(aName), gfxFontFamily(aName),
mContainsAppFonts(false), mContainsAppFonts(false),
mHasNonScalableFaces(false) mHasNonScalableFaces(false),
mForceScalable(false)
{ } { }
void FindStyleVariations(FontInfoData *aFontInfoData = nullptr) override; void FindStyleVariations(FontInfoData *aFontInfoData = nullptr) override;
@ -201,6 +202,7 @@ protected:
bool mContainsAppFonts; bool mContainsAppFonts;
bool mHasNonScalableFaces; bool mHasNonScalableFaces;
bool mForceScalable;
}; };
class gfxFontconfigFont : public gfxFontconfigFontBase { class gfxFontconfigFont : public gfxFontconfigFontBase {