From fee6d28be86408697912c8cb55eb217361973493 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Wed, 26 Jun 2019 18:58:48 +0000 Subject: [PATCH] Bug 1561600 - Support the special Osaka-mono font (family) for Japanese on macOS, by hooking up the font.single-face-list pref to the shared font-list's alias table. r=jwatt Differential Revision: https://phabricator.services.mozilla.com/D36023 --HG-- extra : moz-landing-system : lando --- gfx/thebes/gfxMacPlatformFontList.h | 1 + gfx/thebes/gfxMacPlatformFontList.mm | 65 ++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/gfx/thebes/gfxMacPlatformFontList.h b/gfx/thebes/gfxMacPlatformFontList.h index a2693a469e66..a7a00f0dbff9 100644 --- a/gfx/thebes/gfxMacPlatformFontList.h +++ b/gfx/thebes/gfxMacPlatformFontList.h @@ -164,6 +164,7 @@ class gfxMacPlatformFontList : public gfxPlatformFontList { // special case font faces treated as font families (set via prefs) void InitSingleFaceList(); + void InitAliasesForSingleFaceList(); // initialize system fonts void InitSystemFontNames(); diff --git a/gfx/thebes/gfxMacPlatformFontList.mm b/gfx/thebes/gfxMacPlatformFontList.mm index 38dad8ad5d85..f6b423647d22 100644 --- a/gfx/thebes/gfxMacPlatformFontList.mm +++ b/gfx/thebes/gfxMacPlatformFontList.mm @@ -1010,10 +1010,75 @@ void gfxMacPlatformFontList::InitSharedFontListForPlatform() { ApplyWhitelist(families); families.Sort(); SharedFontList()->SetFamilyNames(families); + InitAliasesForSingleFaceList(); GetPrefsAndStartLoader(); } } +void gfxMacPlatformFontList::InitAliasesForSingleFaceList() { + AutoTArray singleFaceFonts; + gfxFontUtils::GetPrefsFontList("font.single-face-list", singleFaceFonts); + + for (auto& familyName : singleFaceFonts) { + LOG_FONTLIST(("(fontlist-singleface) face name: %s\n", familyName.get())); + // Each entry in the "single face families" list is expected to be a + // colon-separated pair of FaceName:Family, + // where FaceName is the individual face name (psname) of a font + // that should be exposed as a separate family name, + // and Family is the standard family to which that face belongs. + // The only such face listed by default is + // Osaka-Mono:Osaka + auto colon = familyName.FindChar(':'); + if (colon == kNotFound) { + continue; + } + + // Look for the parent family in the main font family list, + // and ensure we have loaded its list of available faces. + nsAutoCString key; + GenerateFontListKey(Substring(familyName, colon + 1), key); + fontlist::Family* family = SharedFontList()->FindFamily(key); + if (!family) { + // The parent family is not present, so just ignore this entry. + continue; + } + if (!family->IsInitialized()) { + if (!gfxPlatformFontList::InitializeFamily(family)) { + // This shouldn't ever fail, but if it does, we can safely ignore it. + MOZ_ASSERT(false, "failed to initialize font family"); + continue; + } + } + + // Truncate the entry from prefs at the colon, so now it is just the + // desired single-face-family name. + familyName.Truncate(colon); + + // Look through the family's faces to see if this one is present. + fontlist::FontList* list = SharedFontList(); + const fontlist::Pointer* facePtrs = family->Faces(list); + for (size_t i = 0; i < family->NumFaces(); i++) { + if (facePtrs[i].IsNull()) { + continue; + } + auto face = static_cast(facePtrs[i].ToPtr(list)); + if (face->mDescriptor.AsString(list).Equals(familyName)) { + // Found it! Create an entry in the Alias table. + GenerateFontListKey(familyName, key); + if (SharedFontList()->FindFamily(key) || mAliasTable.Get(familyName)) { + // If the family name is already known, something's misconfigured; + // just ignore it. + MOZ_ASSERT(false, "single-face family already known"); + break; + } + auto af = mAliasTable.LookupOrAdd(familyName); + af->AppendElement(facePtrs[i]); + break; + } + } + } +} + void gfxMacPlatformFontList::InitSingleFaceList() { AutoTArray singleFaceFonts; gfxFontUtils::GetPrefsFontList("font.single-face-list", singleFaceFonts);