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
This commit is contained in:
Jonathan Kew 2019-06-26 18:58:48 +00:00
Родитель aaec1d24b3
Коммит fee6d28be8
2 изменённых файлов: 66 добавлений и 0 удалений

Просмотреть файл

@ -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();

Просмотреть файл

@ -1010,10 +1010,75 @@ void gfxMacPlatformFontList::InitSharedFontListForPlatform() {
ApplyWhitelist(families);
families.Sort();
SharedFontList()->SetFamilyNames(families);
InitAliasesForSingleFaceList();
GetPrefsAndStartLoader();
}
}
void gfxMacPlatformFontList::InitAliasesForSingleFaceList() {
AutoTArray<nsCString, 10> 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<const fontlist::Face*>(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<nsCString, 10> singleFaceFonts;
gfxFontUtils::GetPrefsFontList("font.single-face-list", singleFaceFonts);