Bug 1716433 - Create a pref to determine whether Windows font substitutes are applied always, or only as fallback for unavailable fonts. r=lsalzman, a=jcristau
authorJonathan Kew <jkew@mozilla.com>
Tue, 15 Jun 2021 16:44:24 +0000
changeset 649735 fcfe4fb4efe8b7ca99217902c65bf836dbf975e5
parent 649734 ca7b43e6dc205af9149b4c8310cf239e037e0532
child 649736 1f0a48237a14f38a4d1019510150550c97cac6d1
push id15552
push userjcristau@mozilla.com
push dateThu, 17 Jun 2021 10:26:39 +0000
treeherdermozilla-beta@7c802d0e5d88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman, jcristau
bugs1716433
milestone90.0
Bug 1716433 - Create a pref to determine whether Windows font substitutes are applied always, or only as fallback for unavailable fonts. r=lsalzman, a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D117890
gfx/thebes/gfxDWriteFontList.cpp
modules/libpref/init/StaticPrefList.yaml
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -1482,17 +1482,17 @@ enum DWriteInitError {
 
 void gfxDWriteFontList::InitSharedFontListForPlatform() {
   mGDIFontTableAccess = Preferences::GetBool(
       "gfx.font_rendering.directwrite.use_gdi_table_loading", false);
   mForceGDIClassicMaxFontSize = Preferences::GetInt(
       "gfx.font_rendering.cleartype_params.force_gdi_classic_max_size",
       mForceGDIClassicMaxFontSize);
 
-  mFontSubstitutes.Clear();
+  mSubstitutions.Clear();
   mNonExistingFonts.Clear();
 
   RefPtr<IDWriteFactory> factory = Factory::GetDWriteFactory();
   HRESULT hr = factory->GetGdiInterop(getter_AddRefs(mGDIInterop));
   if (FAILED(hr)) {
     Telemetry::Accumulate(Telemetry::DWRITEFONT_INIT_PROBLEM,
                           uint32_t(errGDIInterop));
     mSharedFontList.reset(nullptr);
@@ -1889,21 +1889,25 @@ nsresult gfxDWriteFontList::GetFontSubst
 
     NS_ConvertUTF16toUTF8 substituteName((char16_t*)aliasName);
     NS_ConvertUTF16toUTF8 actualFontName((char16_t*)actualName);
     RemoveCharsetFromFontSubstitute(substituteName);
     BuildKeyNameFromFontName(substituteName);
     RemoveCharsetFromFontSubstitute(actualFontName);
     BuildKeyNameFromFontName(actualFontName);
     if (SharedFontList()) {
-      // Font substitutions are recorded for the canonical family names; we
-      // don't need FindFamily to consider localized aliases when searching.
-      if (SharedFontList()->FindFamily(substituteName,
-                                       /*aPrimaryNameOnly*/ true)) {
-        continue;
+      // Skip substitution if the original font is available, unless the option
+      // to apply substitutions unconditionally is enabled.
+      if (!StaticPrefs::gfx_windows_font_substitutes_always_AtStartup()) {
+        // Font substitutions are recorded for the canonical family names; we
+        // don't need FindFamily to consider localized aliases when searching.
+        if (SharedFontList()->FindFamily(substituteName,
+                                         /*aPrimaryNameOnly*/ true)) {
+          continue;
+        }
       }
       if (SharedFontList()->FindFamily(actualFontName,
                                        /*aPrimaryNameOnly*/ true)) {
         mSubstitutions.InsertOrUpdate(substituteName,
                                       MakeUnique<nsCString>(actualFontName));
       } else if (mSubstitutions.Get(actualFontName)) {
         mSubstitutions.InsertOrUpdate(
             substituteName,
@@ -1938,21 +1942,25 @@ static const FontSubstitution sDirectWri
     {"Script", "Mistral"}};
 
 void gfxDWriteFontList::GetDirectWriteSubstitutes() {
   for (uint32_t i = 0; i < ArrayLength(sDirectWriteSubs); ++i) {
     const FontSubstitution& sub(sDirectWriteSubs[i]);
     nsAutoCString substituteName(sub.aliasName);
     BuildKeyNameFromFontName(substituteName);
     if (SharedFontList()) {
-      // We don't need FindFamily to consider localized aliases when searching
-      // for the DirectWrite substitutes, we know the canonical names.
-      if (SharedFontList()->FindFamily(substituteName,
-                                       /*aPrimaryNameOnly*/ true)) {
-        continue;
+      // Skip substitution if the original font is available, unless the option
+      // to apply substitutions unconditionally is enabled.
+      if (!StaticPrefs::gfx_windows_font_substitutes_always_AtStartup()) {
+        // We don't need FindFamily to consider localized aliases when searching
+        // for the DirectWrite substitutes, we know the canonical names.
+        if (SharedFontList()->FindFamily(substituteName,
+                                         /*aPrimaryNameOnly*/ true)) {
+          continue;
+        }
       }
       nsAutoCString actualFontName(sub.actualName);
       BuildKeyNameFromFontName(actualFontName);
       if (SharedFontList()->FindFamily(actualFontName,
                                        /*aPrimaryNameOnly*/ true)) {
         mSubstitutions.InsertOrUpdate(substituteName,
                                       MakeUnique<nsCString>(actualFontName));
       } else {
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -4628,16 +4628,25 @@
   value: true
   mirror: once
 
 - name: gfx.e10s.font-list.shared
   type: bool
   value: true
   mirror: once
 
+# [Windows] Whether registry FontSubstitutes entries are used unconditionally,
+# or only if the original font is not available.
+#if defined(XP_WIN)
+- name: gfx.windows-font-substitutes.always
+  type: bool
+  value: false
+  mirror: once
+#endif
+
 - name: gfx.font-list-omt.enabled
   type: bool
 #if defined(XP_MACOSX)
   value: true
 #else
   value: false
 #endif
   mirror: once