From d177494855402aa59f8bad836b1dae5e3906d448 Mon Sep 17 00:00:00 2001 From: Fatih Date: Wed, 13 Nov 2024 17:00:49 +0000 Subject: [PATCH] Bug 1902570: Enable "Stix Two Math" on macOS 13 and above. a=dmeehan Original Revision: https://phabricator.services.mozilla.com/D226945 Differential Revision: https://phabricator.services.mozilla.com/D228814 --- gfx/thebes/StandardFonts-macos.inc | 4 ++++ gfx/thebes/gfxMacPlatformFontList.mm | 29 +++++++++++++++++++++++++++- widget/GfxInfoBase.cpp | 18 ++++++++++++++++- widget/nsIGfxInfo.idl | 6 ++++-- 4 files changed, 53 insertions(+), 4 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 2b8d1fa16a38..cc8bfde2aaa7 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; @@ -182,7 +204,12 @@ nsTArray> gfxMacPlatformFontList::GetFilteredPlatformFontLists() { nsTArray> fontLists; - fontLists.AppendElement(std::make_pair(kBaseFonts, ArrayLength(kBaseFonts))); + 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 251b46ce661b..1e6c41f38cb7 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" @@ -49,6 +50,10 @@ # include "AndroidBuild.h" #endif +#if defined(XP_MACOSX) +# include "nsCocoaFeatures.h" +#endif + using namespace mozilla::widget; using namespace mozilla; using mozilla::MutexAutoLock; @@ -2077,8 +2082,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 0df8696da7a7..68712a659e65 100644 --- a/widget/nsIGfxInfo.idl +++ b/widget/nsIGfxInfo.idl @@ -46,7 +46,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, @@ -62,7 +62,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;