Bug 1478720 - Increase the fractional adjustment applied to 'opsz' on macOS to avoid using the font's default setting, which may be mishandled by Core Text. r=lsalzman
authorJonathan Kew <jkew@mozilla.com>
Mon, 30 Jul 2018 17:53:09 +0100
changeset 429270 9068ee10e9109a46416bcb76eb36d67b8cd275e7
parent 429269 5459f3286f111c1366d20ec4fc9891acd827c61e
child 429271 e4f654755cc5cb80fb0a5a91707e8a2eff425e3e
push id67094
push userccoroiu@mozilla.com
push dateMon, 30 Jul 2018 22:02:32 +0000
treeherderautoland@397b4d841690 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1478720
milestone63.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 1478720 - Increase the fractional adjustment applied to 'opsz' on macOS to avoid using the font's default setting, which may be mishandled by Core Text. r=lsalzman
gfx/thebes/gfxMacFont.cpp
--- a/gfx/thebes/gfxMacFont.cpp
+++ b/gfx/thebes/gfxMacFont.cpp
@@ -51,21 +51,22 @@ gfxMacFont::gfxMacFont(const RefPtr<Unsc
 
         // Get the variation settings needed to instantiate the fontEntry
         // for a particular fontStyle.
         AutoTArray<gfxFontVariation,4> vars;
         aFontEntry->GetVariationsForStyle(vars, *aFontStyle);
 
         // Because of a Core Text bug, we need to ensure that if the font has
         // an 'opsz' axis, it is always explicitly set, and NOT to the font's
-        // default value. (See bug 1457417.)
+        // default value. (See bug 1457417, bug 1478720.)
         // We record the result of searching the font's axes in the font entry,
         // so that this only has to be done by the first instance created for
         // a given font resource.
         const uint32_t kOpszTag = HB_TAG('o','p','s','z');
+        const float kOpszFudgeAmount = 0.01f;
 
         if (!aFontEntry->mCheckedForOpszAxis) {
             aFontEntry->mCheckedForOpszAxis = true;
             AutoTArray<gfxFontVariationAxis,4> axes;
             aFontEntry->GetVariationAxes(axes);
             auto index =
                 axes.IndexOf(kOpszTag, 0, TagEquals<gfxFontVariationAxis>());
             if (index == axes.NoIndex) {
@@ -74,35 +75,35 @@ gfxMacFont::gfxMacFont(const RefPtr<Unsc
                 const auto& axis = axes[index];
                 aFontEntry->mHasOpszAxis = true;
                 aFontEntry->mOpszAxis = axis;
                 // Pick a slightly-adjusted version of the default that we'll
                 // use to work around Core Text's habit of ignoring any attempt
                 // to explicitly set the default value.
                 aFontEntry->mAdjustedDefaultOpsz =
                     axis.mDefaultValue == axis.mMinValue
-                        ? axis.mDefaultValue + 0.001f
-                        : axis.mDefaultValue - 0.001f;
+                        ? axis.mDefaultValue + kOpszFudgeAmount
+                        : axis.mDefaultValue - kOpszFudgeAmount;
             }
         }
 
         // Add 'opsz' if not present, or tweak its value if it looks too close
         // to the default (after clamping to the font's available range).
         if (aFontEntry->mHasOpszAxis) {
             auto index =
                 vars.IndexOf(kOpszTag, 0, TagEquals<gfxFontVariation>());
             if (index == vars.NoIndex) {
                 gfxFontVariation opsz{kOpszTag, aFontEntry->mAdjustedDefaultOpsz};
                 vars.AppendElement(opsz);
             } else {
                 // Figure out a "safe" value that Core Text won't ignore.
                 auto& value = vars[index].mValue;
                 auto& axis = aFontEntry->mOpszAxis;
                 value = fmin(fmax(value, axis.mMinValue), axis.mMaxValue);
-                if (std::abs(value - axis.mDefaultValue) < 0.001f) {
+                if (std::abs(value - axis.mDefaultValue) < kOpszFudgeAmount) {
                     value = aFontEntry->mAdjustedDefaultOpsz;
                 }
             }
         }
 
         mCGFont =
             UnscaledFontMac::CreateCGFontWithVariations(baseFont,
                                                         vars.Length(),