From e1759b760c344c9741a0914da64ccc97611fc746 Mon Sep 17 00:00:00 2001 From: Fatih Date: Thu, 7 Nov 2024 13:08:10 +0000 Subject: [PATCH] Bug 1902570: Enable "Stix Two Math" on macOS 13 and above. r=tjr Differential Revision: https://phabricator.services.mozilla.com/D226945 --- gfx/thebes/StandardFonts-macos.inc | 4 ++++ gfx/thebes/gfxMacPlatformFontList.mm | 27 +++++++++++++++++++++++++++ widget/GfxInfoBase.cpp | 18 +++++++++++++++++- widget/nsIGfxInfo.idl | 6 ++++-- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/gfx/thebes/StandardFonts-macos.inc b/gfx/thebes/StandardFonts-macos.inc index 46342eb3c46e..0d264bbd5eb8 100644 --- a/gfx/thebes/StandardFonts-macos.inc +++ b/gfx/thebes/StandardFonts-macos.inc @@ -293,3 +293,7 @@ static const char* kBaseFonts[] = { "Zapf Dingbats", "Zapfino", }; + +static const char* kBaseFonts_13_Higher[] = { + "Stix Two Math", +}; diff --git a/gfx/thebes/gfxMacPlatformFontList.mm b/gfx/thebes/gfxMacPlatformFontList.mm index 0a813191991a..a77afe36995a 100644 --- a/gfx/thebes/gfxMacPlatformFontList.mm +++ b/gfx/thebes/gfxMacPlatformFontList.mm @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "mozilla/Components.h" #include "mozilla/Logging.h" #include @@ -152,6 +153,7 @@ void gfxSingleFaceMacFontFamily::ReadOtherFamilyNames( gfxMacPlatformFontList::gfxMacPlatformFontList() : CoreTextFontList() { CheckFamilyList(kBaseFonts); + CheckFamilyList(kBaseFonts_13_Higher); // cache this in a static variable so that gfxMacFontFamily objects // don't have to repeatedly look it up @@ -162,6 +164,22 @@ gfxMacPlatformFontList::gfxMacPlatformFontList() : CoreTextFontList() { gfxFontUtils::GetPrefsFontList("font.single-face-list", mSingleFaceFonts); } +using Device = nsIGfxInfo::FontVisibilityDeviceDetermination; +Device GetFontVisibilityDevice() { + if (!NS_IsMainThread()) { + return Device::MacOS_Unknown; + } + static Device fontVisibilityDevice = Device::Unassigned; + if (fontVisibilityDevice == Device::Unassigned) { + nsCOMPtr gfxInfo = components::GfxInfo::Service(); + NS_ENSURE_SUCCESS( + gfxInfo->GetFontVisibilityDetermination(&fontVisibilityDevice), + Device::MacOS_Unknown); + } + + return fontVisibilityDevice; +} + FontVisibility gfxMacPlatformFontList::GetVisibilityForFamily( const nsACString& aName) const { if (aName[0] == '.' || aName.LowerCaseEqualsLiteral("lastresort")) { @@ -170,6 +188,10 @@ FontVisibility gfxMacPlatformFontList::GetVisibilityForFamily( if (FamilyInList(aName, kBaseFonts)) { return FontVisibility::Base; } + if (GetFontVisibilityDevice() == Device::MacOS_13_plus && + FamilyInList(aName, kBaseFonts_13_Higher)) { + return FontVisibility::Base; + } #ifdef MOZ_BUNDLED_FONTS if (mBundledFamilies.Contains(aName)) { return FontVisibility::Base; @@ -184,6 +206,11 @@ gfxMacPlatformFontList::GetFilteredPlatformFontLists() { fontLists.AppendElement(std::make_pair(kBaseFonts, std::size(kBaseFonts))); + if (GetFontVisibilityDevice() == Device::MacOS_13_plus) { + fontLists.AppendElement( + std::make_pair(kBaseFonts_13_Higher, std::size(kBaseFonts_13_Higher))); + } + return fontLists; } diff --git a/widget/GfxInfoBase.cpp b/widget/GfxInfoBase.cpp index 498e9d861061..0b7d81e45e47 100644 --- a/widget/GfxInfoBase.cpp +++ b/widget/GfxInfoBase.cpp @@ -16,6 +16,7 @@ #include "js/PropertyAndElement.h" // JS_SetElement, JS_SetProperty #include "nsCOMPtr.h" #include "nsCOMArray.h" +#include "nsIPropertyBag2.h" #include "nsString.h" #include "nsUnicharUtils.h" #include "nsVersionComparator.h" @@ -50,6 +51,10 @@ # include "AndroidBuild.h" #endif +#if defined(XP_MACOSX) +# include "nsCocoaFeatures.h" +#endif + using namespace mozilla::widget; using namespace mozilla; using mozilla::MutexAutoLock; @@ -1758,8 +1763,19 @@ std::pair* GfxInfoBase::GetFontVisibilityDeterminationPair() { } #elif defined(XP_MACOSX) - ret->first = Device::MacOS_Platform; + ret->first = Device::MacOS_Unknown; ret->second.AppendASCII("macOS Platform"); + + int major = 0; + int minor = 0; + int bugfix = 0; + nsCocoaFeatures::GetSystemVersion(major, minor, bugfix); + if (major == 0) { + return ret; + } + + ret->first = major >= 13 ? Device::MacOS_13_plus : Device::MacOS_sub_13; + ret->second.AppendPrintf("macOS %d.%d.%d", major, minor, bugfix); #elif defined(XP_WIN) ret->first = Device::Windows_Platform; ret->second.AppendASCII("Windows Platform"); diff --git a/widget/nsIGfxInfo.idl b/widget/nsIGfxInfo.idl index 58e303d9e4b9..e9f7ed9df023 100644 --- a/widget/nsIGfxInfo.idl +++ b/widget/nsIGfxInfo.idl @@ -47,7 +47,7 @@ interface nsIGfxInfo : nsISupports Unassigned = 0, Unknown_Platform = 1, Windows_Platform = 2, - MacOS_Platform = 3, + MacOS_Unknown = 3, Android_Unknown_Release_Version = 4, Android_Unknown_Peloton = 5, Android_Unknown_vbox = 6, @@ -63,7 +63,9 @@ interface nsIGfxInfo : nsISupports Linux_Ubuntu_22 = 16, Linux_Fedora_any = 17, Linux_Fedora_38 = 18, - Linux_Fedora_39 = 19 + Linux_Fedora_39 = 19, + MacOS_13_plus = 20, + MacOS_sub_13 = 21 }; readonly attribute nsIGfxInfo_FontVisibilityDeviceDetermination fontVisibilityDetermination; readonly attribute AString fontVisibilityDeterminationStr;