From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- gfx/thebes/gfxMacPlatformFontList.mm | 169 ++--------------------------------- 1 file changed, 9 insertions(+), 160 deletions(-) (limited to 'gfx/thebes/gfxMacPlatformFontList.mm') diff --git a/gfx/thebes/gfxMacPlatformFontList.mm b/gfx/thebes/gfxMacPlatformFontList.mm index e36c9c8a25..2b8d1fa16a 100644 --- a/gfx/thebes/gfxMacPlatformFontList.mm +++ b/gfx/thebes/gfxMacPlatformFontList.mm @@ -72,80 +72,6 @@ static NSString* GetNSStringForString(const nsAString& aSrc) { #define LOG_CMAPDATA_ENABLED() \ MOZ_LOG_TEST(gfxPlatform::GetLog(eGfxLog_cmapdata), mozilla::LogLevel::Debug) -class gfxMacFontFamily final : public CTFontFamily { - public: - gfxMacFontFamily(const nsACString& aName, NSFont* aSystemFont) - : CTFontFamily(aName, FontVisibility::Unknown), - mForSystemFont(aSystemFont) { - // I don't think the system font instance is at much risk of being deleted, - // but to be on the safe side let's retain a reference until we're finished - // using it for lazy initialization. - [mForSystemFont retain]; - } - - void FindStyleVariationsLocked(FontInfoData* aFontInfoData = nullptr) - MOZ_REQUIRES(mLock) override; - - protected: - // If non-null, this is a family representing the system UI font, and should - // use the given NSFont as the basis for initialization as the normal - // font-manager APIs based on family name won't handle it. - NSFont* mForSystemFont = nullptr; -}; - -void gfxMacFontFamily::FindStyleVariationsLocked(FontInfoData* aFontInfoData) { - if (mHasStyles) { - return; - } - - AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING("gfxMacFontFamily::FindStyleVariations", - LAYOUT, mName); - - nsAutoreleasePool localPool; - - if (mForSystemFont) { - MOZ_ASSERT(gfxPlatform::HasVariationFontSupport()); - - auto addToFamily = [&](NSFont* aNSFont) MOZ_REQUIRES(mLock) { - NSString* psNameNS = aNSFont.fontDescriptor.postscriptName; - nsAutoString nameUTF16; - nsAutoCString psName; - nsCocoaUtils::GetStringForNSString(psNameNS, nameUTF16); - CopyUTF16toUTF8(nameUTF16, psName); - - auto* fe = - new CTFontEntry(psName, WeightRange(FontWeight::NORMAL), true, 0.0); - - // Set the appropriate style, assuming it may not have a variation range. - fe->mStyleRange = SlantStyleRange( - (aNSFont.fontDescriptor.symbolicTraits & NSFontItalicTrait) - ? FontSlantStyle::ITALIC - : FontSlantStyle::NORMAL); - - // Set up weight (and width, if present) ranges. - fe->SetupVariationRanges(); - AddFontEntryLocked(fe); - }; - - addToFamily(mForSystemFont); - - // See if there is a corresponding italic face, and add it to the family. - NSFont* italicFont = [sFontManager convertFont:mForSystemFont - toHaveTrait:NSItalicFontMask]; - if (italicFont != mForSystemFont) { - addToFamily(italicFont); - } - - [mForSystemFont release]; - mForSystemFont = nullptr; - SetHasStyles(true); - - return; - } - - CTFontFamily::FindStyleVariationsLocked(aFontInfoData); -} - /* gfxSingleFaceMacFontFamily */ class gfxSingleFaceMacFontFamily final : public gfxFontFamily { @@ -252,6 +178,15 @@ FontVisibility gfxMacPlatformFontList::GetVisibilityForFamily( return FontVisibility::User; } +nsTArray> +gfxMacPlatformFontList::GetFilteredPlatformFontLists() { + nsTArray> fontLists; + + fontLists.AppendElement(std::make_pair(kBaseFonts, ArrayLength(kBaseFonts))); + + return fontLists; +} + bool gfxMacPlatformFontList::DeprecatedFamilyIsAvailable( const nsACString& aName) { NSString* family = GetNSStringForString(NS_ConvertUTF8toUTF16(aName)); @@ -394,92 +329,6 @@ void gfxMacPlatformFontList::InitSingleFaceList() { } } -// System fonts under OSX may contain weird "meta" names but if we create -// a new font using just the Postscript name, the NSFont api returns an object -// with the actual real family name. For example, under OSX 10.11: -// -// [[NSFont menuFontOfSize:8.0] familyName] ==> .AppleSystemUIFont -// [[NSFont fontWithName:[[[NSFont menuFontOfSize:8.0] fontDescriptor] -// postscriptName] -// size:8.0] familyName] ==> .SF NS Text - -static NSString* GetRealFamilyName(NSFont* aFont) { - NSString* psName = [[aFont fontDescriptor] postscriptName]; - // With newer macOS versions and SDKs (e.g. when compiled against SDK 10.15), - // [NSFont fontWithName:] fails for hidden system fonts, because the - // underlying Core Text functions it uses reject such names and tell us to use - // the special CTFontCreateUIFontForLanguage API instead. To work around this, - // as we don't yet work directly with the CTFontUIFontType identifiers, we - // create a Core Graphics font (as it doesn't reject system font names), and - // use this to create a Core Text font that we can query for the family name. - // Eventually we should move to using CTFontUIFontType constants to identify - // system fonts, and eliminate the need to instantiate them (indirectly) from - // their postscript names. - AutoCFRelease cgFont = - CGFontCreateWithFontName(CFStringRef(psName)); - if (!cgFont) { - return [aFont familyName]; - } - - AutoCFRelease ctFont = - CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr); - if (!ctFont) { - return [aFont familyName]; - } - NSString* familyName = (NSString*)CTFontCopyFamilyName(ctFont); - - return [familyName autorelease]; -} - -void gfxMacPlatformFontList::InitSystemFontNames() { - // text font family - NSFont* sys = [NSFont systemFontOfSize:0.0]; - NSString* textFamilyName = GetRealFamilyName(sys); - nsAutoString familyName; - nsCocoaUtils::GetStringForNSString(textFamilyName, familyName); - CopyUTF16toUTF8(familyName, mSystemFontFamilyName); - - // We store an in-process gfxFontFamily for the system font even if using the - // shared fontlist to manage "normal" fonts, because the hidden system fonts - // may be excluded from the font list altogether. This family will be - // populated based on the given NSFont. - RefPtr fam = new gfxMacFontFamily(mSystemFontFamilyName, sys); - if (fam) { - nsAutoCString key; - GenerateFontListKey(mSystemFontFamilyName, key); - mFontFamilies.InsertOrUpdate(key, std::move(fam)); - } - -#ifdef DEBUG - // different system font API's always map to the same family under OSX, so - // just assume that and emit a warning if that ever changes - NSString* sysFamily = GetRealFamilyName([NSFont systemFontOfSize:0.0]); - if ([sysFamily compare:GetRealFamilyName([NSFont - boldSystemFontOfSize:0.0])] != NSOrderedSame || - [sysFamily compare:GetRealFamilyName([NSFont - controlContentFontOfSize:0.0])] != NSOrderedSame || - [sysFamily compare:GetRealFamilyName([NSFont menuBarFontOfSize:0.0])] != - NSOrderedSame || - [sysFamily compare:GetRealFamilyName([NSFont toolTipsFontOfSize:0.0])] != - NSOrderedSame) { - NS_WARNING("system font types map to different font families" - " -- please log a bug!!"); - } -#endif -} - -FontFamily gfxMacPlatformFontList::GetDefaultFontForPlatform( - nsPresContext* aPresContext, const gfxFontStyle* aStyle, - nsAtom* aLanguage) { - nsAutoreleasePool localPool; - - NSString* defaultFamily = [[NSFont userFontOfSize:aStyle->size] familyName]; - nsAutoString familyName; - - GetStringForNSString(defaultFamily, familyName); - return FindFamily(aPresContext, NS_ConvertUTF16toUTF8(familyName)); -} - void gfxMacPlatformFontList::LookupSystemFont(LookAndFeel::FontID aSystemFontID, nsACString& aSystemFontName, gfxFontStyle& aFontStyle) { -- cgit v1.2.3