summaryrefslogtreecommitdiffstats
path: root/gfx/thebes/gfxMacPlatformFontList.mm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /gfx/thebes/gfxMacPlatformFontList.mm
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/thebes/gfxMacPlatformFontList.mm')
-rw-r--r--gfx/thebes/gfxMacPlatformFontList.mm169
1 files changed, 9 insertions, 160 deletions
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<std::pair<const char**, uint32_t>>
+gfxMacPlatformFontList::GetFilteredPlatformFontLists() {
+ nsTArray<std::pair<const char**, uint32_t>> 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<CGFontRef> cgFont =
- CGFontCreateWithFontName(CFStringRef(psName));
- if (!cgFont) {
- return [aFont familyName];
- }
-
- AutoCFRelease<CTFontRef> 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<gfxFontFamily> 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) {