Bug 1588407 - If a requested font-family name may be a styled legacy family, force immediate loading of additional family names so that the correct font can be found. r=jwatt
authorJonathan Kew <jkew@mozilla.com>
Wed, 23 Oct 2019 10:40:16 +0000
changeset 498686 782f341be605f1a30e8a9bfbfc13ce389e620a24
parent 498685 2cc0126220511d9b7ce15b4f54c1e8640339328a
child 498687 ee9d1b4986a579025764d7d78b90b2b4a486a9b1
push id36723
push userapavel@mozilla.com
push dateWed, 23 Oct 2019 15:48:18 +0000
treeherdermozilla-central@782f341be605 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1588407
milestone72.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 1588407 - If a requested font-family name may be a styled legacy family, force immediate loading of additional family names so that the correct font can be found. r=jwatt Differential Revision: https://phabricator.services.mozilla.com/D49181
gfx/thebes/gfxPlatformFontList.cpp
--- a/gfx/thebes/gfxPlatformFontList.cpp
+++ b/gfx/thebes/gfxPlatformFontList.cpp
@@ -961,23 +961,45 @@ bool gfxPlatformFontList::FindAndAddFami
       aOutput->AppendElement(FamilyAndGeneric(family, aGeneric));
       return true;
     }
     // If not found, and other family names have not yet been initialized,
     // initialize the rest of the list and try again. This is done lazily
     // since reading name table entries is expensive.
     // Although ASCII localized family names are possible they don't occur
     // in practice, so avoid pulling in names at startup.
-    if (!mOtherFamilyNamesInitialized && !IsAscii(aFamily)) {
-      InitOtherFamilyNames(
-          !(aFlags & FindFamiliesFlags::eForceOtherFamilyNamesLoading));
-      family = SharedFontList()->FindFamily(key);
-      if (family) {
-        aOutput->AppendElement(FamilyAndGeneric(family, aGeneric));
-        return true;
+    if (!mOtherFamilyNamesInitialized) {
+      bool triggerLoading = true;
+      bool mayDefer =
+          !(aFlags & FindFamiliesFlags::eForceOtherFamilyNamesLoading);
+      if (IsAscii(key)) {
+        // If `key` is an ASCII name, only trigger loading if it includes a
+        // space, and the "base" name (up to the last space) exists as a known
+        // family, so that this might be a legacy styled-family name.
+        const char* data = key.BeginReading();
+        int32_t index = key.Length();
+        while (--index > 0) {
+          if (data[index] == ' ') {
+            break;
+          }
+        }
+        nsAutoCString base(Substring(key, 0, index));
+        if (index > 0 && SharedFontList()->FindFamily(base)) {
+          mayDefer = false;
+        } else {
+          triggerLoading = false;
+        }
+      }
+      if (triggerLoading) {
+        InitOtherFamilyNames(mayDefer);
+        family = SharedFontList()->FindFamily(key);
+        if (family) {
+          aOutput->AppendElement(FamilyAndGeneric(family, aGeneric));
+          return true;
+        }
       }
       if (!family && !mOtherFamilyNamesInitialized &&
           !(aFlags & FindFamiliesFlags::eNoAddToNamesMissedWhenSearching)) {
         // localized family names load timed out, add name to list of
         // names to check after localized names are loaded
         if (!mOtherNamesMissed) {
           mOtherNamesMissed = MakeUnique<nsTHashtable<nsCStringHashKey>>(2);
         }