Bug 1585931 - don't use subpixel positioning for Fontconfig fonts if full hinting is requested. r=jfkthame
authorLee Salzman <lsalzman@mozilla.com>
Mon, 21 Oct 2019 15:32:31 +0000
changeset 498390 49e3720bafb49406970c5b57dcde998a33d5a077
parent 498389 a87a4289ef3920bf9ee29f22a695046ffb825563
child 498391 66cd75467ce3492f3756863027008e90549cb0f8
push id36717
push usernbeleuzu@mozilla.com
push dateMon, 21 Oct 2019 21:51:55 +0000
treeherdermozilla-central@563f437f24b9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1585931
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1585931 - don't use subpixel positioning for Fontconfig fonts if full hinting is requested. r=jfkthame Differential Revision: https://phabricator.services.mozilla.com/D49901
gfx/2d/ScaledFontFontconfig.cpp
gfx/thebes/gfxFT2FontBase.cpp
--- a/gfx/2d/ScaledFontFontconfig.cpp
+++ b/gfx/2d/ScaledFontFontconfig.cpp
@@ -34,17 +34,19 @@ ScaledFontFontconfig::ScaledFontFontconf
     RefPtr<SharedFTFace>&& aFace, const InstanceData& aInstanceData,
     const RefPtr<UnscaledFont>& aUnscaledFont, Float aSize)
     : ScaledFontBase(aUnscaledFont, aSize),
       mFace(std::move(aFace)),
       mInstanceData(aInstanceData) {}
 
 bool ScaledFontFontconfig::UseSubpixelPosition() const {
   return mInstanceData.mAntialias != AntialiasMode::NONE &&
-         FT_IS_SCALABLE(mFace->GetFace());
+         FT_IS_SCALABLE(mFace->GetFace()) &&
+         (mInstanceData.mHinting == FontHinting::NONE ||
+          mInstanceData.mHinting == FontHinting::LIGHT);
 }
 
 #ifdef USE_SKIA
 SkTypeface* ScaledFontFontconfig::CreateSkTypeface() {
   SkPixelGeometry geo = mInstanceData.mFlags & InstanceData::SUBPIXEL_BGR
                             ? (mInstanceData.mFlags & InstanceData::LCD_VERTICAL
                                    ? kBGR_V_SkPixelGeometry
                                    : kBGR_H_SkPixelGeometry)
--- a/gfx/thebes/gfxFT2FontBase.cpp
+++ b/gfx/thebes/gfxFT2FontBase.cpp
@@ -471,18 +471,23 @@ uint32_t gfxFT2FontBase::GetGlyph(uint32
   return GetGlyph(unicode);
 }
 
 bool gfxFT2FontBase::ShouldRoundXOffset(cairo_t* aCairo) const {
   // Force rounding if outputting to a Cairo context. Otherwise, allow subpixel
   // positioning (no rounding) if rendering a scalable outline font with
   // anti-aliasing. Monochrome rendering or some bitmap fonts can become too
   // distorted with subpixel positioning, so force rounding in those cases.
+  // Also be careful not to use subpixel positioning if the user requests full
+  // hinting via Fontconfig, which we detect by checking that neither hinting
+  // was disabled nor light hinting was requested.
   return aCairo != nullptr || !mFTFace || !FT_IS_SCALABLE(mFTFace->GetFace()) ||
-         (mFTLoadFlags & FT_LOAD_MONOCHROME);
+         (mFTLoadFlags & FT_LOAD_MONOCHROME) ||
+         !((mFTLoadFlags & FT_LOAD_NO_HINTING) ||
+           FT_LOAD_TARGET_MODE(mFTLoadFlags) == FT_RENDER_MODE_LIGHT);
 }
 
 FT_Vector gfxFT2FontBase::GetEmboldenStrength(FT_Face aFace) {
   FT_Vector strength = {0, 0};
   if (!mEmbolden) {
     return strength;
   }
   // This is the embolden "strength" used by FT_GlyphSlot_Embolden.