Bug 1640816 - Record base font-family name in family alias records. r=jwatt
authorJonathan Kew <jkew@mozilla.com>
Thu, 04 Jun 2020 11:48:46 +0000
changeset 597969 5c1025c06228cdae0e3f56bf45d1c804d5d2fe1b
parent 597968 bef16d556f0946c0f9210b1be1b522fff5784e22
child 597970 a99ed7e04b9483121d2c5584e98eecf4d88292ef
push id13310
push userffxbld-merge
push dateMon, 29 Jun 2020 14:50:06 +0000
treeherdermozilla-beta@15a59a0afa5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1640816
milestone79.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 1640816 - Record base font-family name in family alias records. r=jwatt Differential Revision: https://phabricator.services.mozilla.com/D77909
gfx/thebes/SharedFontList-impl.h
gfx/thebes/SharedFontList.cpp
gfx/thebes/gfxDWriteFontList.cpp
gfx/thebes/gfxMacPlatformFontList.mm
--- a/gfx/thebes/SharedFontList-impl.h
+++ b/gfx/thebes/SharedFontList-impl.h
@@ -29,23 +29,25 @@ namespace fontlist {
  * Data used to initialize a font family alias (a "virtual" family that refers
  * to some or all of the faces of another family, used when alternate family
  * names are found in the font resource for localization or for styled
  * subfamilies). AliasData records are collected incrementally while scanning
  * the fonts, and then used to set up the Aliases list in the shared font list.
  */
 struct AliasData {
   nsTArray<Pointer> mFaces;
+  nsCString mBaseFamily;
   uint32_t mIndex = 0;
   FontVisibility mVisibility = FontVisibility::Unknown;
   bool mBundled = false;
   bool mBadUnderline = false;
   bool mForceClassic = false;
 
-  void InitFromFamily(const Family* aFamily) {
+  void InitFromFamily(const Family* aFamily, const nsCString& aBaseFamily) {
+    mBaseFamily = aBaseFamily;
     mIndex = aFamily->Index();
     mVisibility = aFamily->Visibility();
     mBundled = aFamily->IsBundled();
     mBadUnderline = aFamily->IsBadUnderlineFamily();
     mForceClassic = aFamily->IsForceClassic();
   }
 };
 
--- a/gfx/thebes/SharedFontList.cpp
+++ b/gfx/thebes/SharedFontList.cpp
@@ -700,36 +700,36 @@ void FontList::SetAliases(
   Header& header = GetHeader();
 
   // Build an array of Family::InitData records based on the entries in
   // aAliasTable, then sort them and store into the fontlist.
   nsTArray<Family::InitData> aliasArray;
   aliasArray.SetCapacity(aAliasTable.Count());
   for (auto i = aAliasTable.Iter(); !i.Done(); i.Next()) {
     aliasArray.AppendElement(Family::InitData(
-        i.Key(), i.Key(), i.Data()->mIndex, i.Data()->mVisibility,
+        i.Key(), i.Data()->mBaseFamily, i.Data()->mIndex, i.Data()->mVisibility,
         i.Data()->mBundled, i.Data()->mBadUnderline, i.Data()->mForceClassic));
   }
   aliasArray.Sort();
 
   size_t count = aliasArray.Length();
   if (count < header.mAliasCount) {
     // This shouldn't happen, but handle it safely by just bailing out.
     NS_WARNING("cannot reduce number of aliases");
     return;
   }
   fontlist::Pointer ptr = Alloc(count * sizeof(Family));
   Family* aliases = static_cast<Family*>(ptr.ToPtr(this));
   for (size_t i = 0; i < count; i++) {
     (void)new (&aliases[i]) Family(this, aliasArray[i]);
     LOG_FONTLIST(("(shared-fontlist) alias family %u (%s)", (unsigned)i,
                   aliasArray[i].mName.get()));
-    aliases[i].SetFacePtrs(this, aAliasTable.Get(aliasArray[i].mName)->mFaces);
+    aliases[i].SetFacePtrs(this, aAliasTable.Get(aliasArray[i].mKey)->mFaces);
     if (LOG_FONTLIST_ENABLED()) {
-      const auto& faces = aAliasTable.Get(aliasArray[i].mName)->mFaces;
+      const auto& faces = aAliasTable.Get(aliasArray[i].mKey)->mFaces;
       for (unsigned j = 0; j < faces.Length(); j++) {
         auto face = static_cast<const fontlist::Face*>(faces[j].ToPtr(this));
         const nsCString& desc = face->mDescriptor.AsString(this);
         nsAutoCString weight, style, stretch;
         face->mWeight.ToString(weight);
         face->mStyle.ToString(style);
         face->mStretch.ToString(stretch);
         LOG_FONTLIST(
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -1242,17 +1242,17 @@ void gfxDWriteFontList::ReadFaceNamesFor
 
     AutoTArray<nsCString, 4> otherFamilyNames;
     gfxFontUtils::ReadOtherFamilyNamesForFace(familyName, data, size,
                                               otherFamilyNames, false);
     for (const auto& alias : otherFamilyNames) {
       nsAutoCString key(alias);
       ToLowerCase(key);
       auto aliasData = mAliasTable.LookupOrAdd(key);
-      aliasData->InitFromFamily(aFamily);
+      aliasData->InitFromFamily(aFamily, familyName);
       aliasData->mFaces.AppendElement(facePtrs[i]);
     }
 
     nsAutoCString psname, fullname;
     if (NS_SUCCEEDED(gfxFontUtils::ReadCanonicalName(
             data, size, gfxFontUtils::NAME_ID_POSTSCRIPT, psname))) {
       ToLowerCase(psname);
       mLocalNameTable.Put(psname, fontlist::LocalFaceRec::InitData(key, i));
--- a/gfx/thebes/gfxMacPlatformFontList.mm
+++ b/gfx/thebes/gfxMacPlatformFontList.mm
@@ -1055,16 +1055,17 @@ void gfxMacPlatformFontList::InitAliases
           // just ignore it.
           MOZ_ASSERT(false, "single-face family already known");
           break;
         }
         auto aliasData = mAliasTable.LookupOrAdd(key);
         // The "alias" here isn't based on an existing family, so we don't call
         // aliasData->InitFromFamily(); the various flags are left as defaults.
         aliasData->mFaces.AppendElement(facePtrs[i]);
+        aliasData->mBaseFamily = familyName;
         break;
       }
     }
   }
 }
 
 void gfxMacPlatformFontList::InitSingleFaceList() {
   AutoTArray<nsCString, 10> singleFaceFonts;
@@ -1772,17 +1773,17 @@ void gfxMacPlatformFontList::ReadFaceNam
     const char* nameData = hb_blob_get_data(nameTable, &dataLength);
     AutoTArray<nsCString, 4> otherFamilyNames;
     gfxFontUtils::ReadOtherFamilyNamesForFace(canonicalName, nameData, dataLength, otherFamilyNames,
                                               false);
     for (const auto& alias : otherFamilyNames) {
       nsAutoCString key;
       GenerateFontListKey(alias, key);
       auto aliasData = mAliasTable.LookupOrAdd(key);
-      aliasData->InitFromFamily(aFamily);
+      aliasData->InitFromFamily(aFamily, canonicalName);
       aliasData->mFaces.AppendElement(facePtrs[i]);
     }
   }
 }
 
 #ifdef MOZ_BUNDLED_FONTS
 
 void gfxMacPlatformFontList::ActivateBundledFonts() {