From 110918269f20ae8e3b278850e5072ed516ee855d Mon Sep 17 00:00:00 2001 From: John Daggett Date: Thu, 8 Oct 2015 15:04:08 +0900 Subject: [PATCH] Bug 1201318 - revise OSX system font handling. r=mstange Rework system font lookup under OSX so that the style system passes around the same "meta" name used by Webkit, -apple-system. This makes it so that the hidden system fonts used aren't exposed to authors. It also allows us to handle the two optical sizes of font families used under OSX 10.11, which uses San Francisco as the new UI font, with one family for text sizes and another for larger, display sizes. The patch here: - moves system font lookup into gfxMacPlatformFontList - assigns the font family name to "-apple-system" - derives FindFamily to take a gfxFontStyle parameter to allow size-based lookups - maintains a list of hidden system font families (not exposed to authors) - maintains a mapping from -apple-system to the underlying hidden font families --- gfx/thebes/gfxDWriteFontList.cpp | 4 +- gfx/thebes/gfxDWriteFontList.h | 5 +- gfx/thebes/gfxFcPlatformFontList.cpp | 7 +- gfx/thebes/gfxFcPlatformFontList.h | 3 +- gfx/thebes/gfxFontEntry.cpp | 6 +- gfx/thebes/gfxGDIFontList.cpp | 4 +- gfx/thebes/gfxGDIFontList.h | 5 +- gfx/thebes/gfxMacPlatformFontList.h | 69 +++++++--- gfx/thebes/gfxMacPlatformFontList.mm | 193 ++++++++++++++++++++++++++- gfx/thebes/gfxPlatformFontList.cpp | 18 +-- gfx/thebes/gfxPlatformFontList.h | 8 +- gfx/thebes/gfxPlatformMac.cpp | 11 ++ gfx/thebes/gfxPlatformMac.h | 9 ++ gfx/thebes/gfxTextRun.cpp | 24 +--- widget/cocoa/nsLookAndFeel.mm | 105 +-------------- 15 files changed, 283 insertions(+), 188 deletions(-) diff --git a/gfx/thebes/gfxDWriteFontList.cpp b/gfx/thebes/gfxDWriteFontList.cpp index aaa8d8d82b1..046964c500c 100644 --- a/gfx/thebes/gfxDWriteFontList.cpp +++ b/gfx/thebes/gfxDWriteFontList.cpp @@ -1255,9 +1255,7 @@ gfxDWriteFontList::GetStandardFamilyName(const nsAString& aFontName, } gfxFontFamily* -gfxDWriteFontList::FindFamily(const nsAString& aFamily, - nsIAtom* aLanguage, - bool aUseSystemFonts) +gfxDWriteFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle) { nsAutoString keyName(aFamily); BuildKeyNameFromFontName(keyName); diff --git a/gfx/thebes/gfxDWriteFontList.h b/gfx/thebes/gfxDWriteFontList.h index 9d2920d717e..8479137c9b0 100644 --- a/gfx/thebes/gfxDWriteFontList.h +++ b/gfx/thebes/gfxDWriteFontList.h @@ -364,9 +364,8 @@ public: IDWriteGdiInterop *GetGDIInterop() { return mGDIInterop; } bool UseGDIFontTableAccess() { return mGDIFontTableAccess; } - virtual gfxFontFamily* FindFamily(const nsAString& aFamily, - nsIAtom* aLanguage = nullptr, - bool aUseSystemFonts = false); + gfxFontFamily* FindFamily(const nsAString& aFamily, + gfxFontStyle* aStyle = nullptr) override; gfxFloat GetForceGDIClassicMaxFontSize() { return mForceGDIClassicMaxFontSize; } diff --git a/gfx/thebes/gfxFcPlatformFontList.cpp b/gfx/thebes/gfxFcPlatformFontList.cpp index e26cb32b516..c324e4ac9c9 100644 --- a/gfx/thebes/gfxFcPlatformFontList.cpp +++ b/gfx/thebes/gfxFcPlatformFontList.cpp @@ -1215,12 +1215,11 @@ gfxFcPlatformFontList::MakePlatformFont(const nsAString& aFontName, } gfxFontFamily* -gfxFcPlatformFontList::FindFamily(const nsAString& aFamily, - nsIAtom* aLanguage, - bool aUseSystemFonts) +gfxFcPlatformFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle) { nsAutoString familyName(aFamily); ToLowerCase(familyName); + nsIAtom* language = (aStyle ? aStyle->language.get() : nullptr); // deprecated generic names are explicitly converted to standard generics bool isDeprecatedGeneric = false; @@ -1236,7 +1235,7 @@ gfxFcPlatformFontList::FindFamily(const nsAString& aFamily, // fontconfig generics? use fontconfig to determine the family for lang if (isDeprecatedGeneric || mozilla::FontFamilyName::Convert(familyName).IsGeneric()) { - return FindGenericFamily(familyName, aLanguage); + return FindGenericFamily(familyName, language); } // fontconfig allows conditional substitutions in such a way that it's diff --git a/gfx/thebes/gfxFcPlatformFontList.h b/gfx/thebes/gfxFcPlatformFontList.h index bcb3e03c50b..fc6a13ae3b2 100644 --- a/gfx/thebes/gfxFcPlatformFontList.h +++ b/gfx/thebes/gfxFcPlatformFontList.h @@ -218,8 +218,7 @@ public: uint32_t aLength) override; gfxFontFamily* FindFamily(const nsAString& aFamily, - nsIAtom* aLanguage = nullptr, - bool aUseSystemFonts = false) override; + gfxFontStyle* aStyle = nullptr) override; bool GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) override; diff --git a/gfx/thebes/gfxFontEntry.cpp b/gfx/thebes/gfxFontEntry.cpp index 0596580d379..5f309d81ca6 100644 --- a/gfx/thebes/gfxFontEntry.cpp +++ b/gfx/thebes/gfxFontEntry.cpp @@ -1115,15 +1115,15 @@ gfxFontEntry::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf, // ////////////////////////////////////////////////////////////////////////////// -// we consider faces with mStandardFace == true to be "greater than" those with false, -// because during style matching, later entries will replace earlier ones +// we consider faces with mStandardFace == true to be "less than" those with false, +// because during style matching, earlier entries are tried first class FontEntryStandardFaceComparator { public: bool Equals(const nsRefPtr& a, const nsRefPtr& b) const { return a->mStandardFace == b->mStandardFace; } bool LessThan(const nsRefPtr& a, const nsRefPtr& b) const { - return (a->mStandardFace == false && b->mStandardFace == true); + return (a->mStandardFace == true && b->mStandardFace == false); } }; diff --git a/gfx/thebes/gfxGDIFontList.cpp b/gfx/thebes/gfxGDIFontList.cpp index 0dfd9403619..877e70d858b 100644 --- a/gfx/thebes/gfxGDIFontList.cpp +++ b/gfx/thebes/gfxGDIFontList.cpp @@ -828,9 +828,7 @@ gfxGDIFontList::MakePlatformFont(const nsAString& aFontName, } gfxFontFamily* -gfxGDIFontList::FindFamily(const nsAString& aFamily, - nsIAtom* aLanguage, - bool aUseSystemFonts) +gfxGDIFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle) { nsAutoString keyName(aFamily); BuildKeyNameFromFontName(keyName); diff --git a/gfx/thebes/gfxGDIFontList.h b/gfx/thebes/gfxGDIFontList.h index 53ff41f2cdf..81ad45aa760 100644 --- a/gfx/thebes/gfxGDIFontList.h +++ b/gfx/thebes/gfxGDIFontList.h @@ -305,9 +305,8 @@ public: virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle); - virtual gfxFontFamily* FindFamily(const nsAString& aFamily, - nsIAtom* aLanguage = nullptr, - bool aUseSystemFonts = false); + gfxFontFamily* FindFamily(const nsAString& aFamily, + gfxFontStyle* aStyle = nullptr) override; virtual gfxFontEntry* LookupLocalFont(const nsAString& aFontName, uint16_t aWeight, diff --git a/gfx/thebes/gfxMacPlatformFontList.h b/gfx/thebes/gfxMacPlatformFontList.h index a6499dc3131..7414e2578f5 100644 --- a/gfx/thebes/gfxMacPlatformFontList.h +++ b/gfx/thebes/gfxMacPlatformFontList.h @@ -18,6 +18,7 @@ #include "nsUnicharUtils.h" #include "nsTArray.h" +#include "mozilla/LookAndFeel.h" class gfxMacPlatformFontList; @@ -78,21 +79,31 @@ public: static int32_t AppleWeightToCSSWeight(int32_t aAppleWeight); - virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle); + gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle) override; - virtual bool GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName); + bool GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) override; - virtual gfxFontEntry* LookupLocalFont(const nsAString& aFontName, - uint16_t aWeight, - int16_t aStretch, - bool aItalic); + gfxFontEntry* LookupLocalFont(const nsAString& aFontName, + uint16_t aWeight, + int16_t aStretch, + bool aItalic) override; - virtual gfxFontEntry* MakePlatformFont(const nsAString& aFontName, - uint16_t aWeight, - int16_t aStretch, - bool aItalic, - const uint8_t* aFontData, - uint32_t aLength); + gfxFontEntry* MakePlatformFont(const nsAString& aFontName, + uint16_t aWeight, + int16_t aStretch, + bool aItalic, + const uint8_t* aFontData, + uint32_t aLength) override; + + gfxFontFamily* FindFamily(const nsAString& aFamily, + gfxFontStyle* aStyle = nullptr) override; + + // lookup the system font for a particular system font type and set + // the name and style characteristics + void LookupSystemFont(mozilla::LookAndFeel::FontID aSystemFontID, + nsAString& aSystemFontName, + gfxFontStyle &aFontStyle, + float aDevPixPerCSSPixel); private: friend class gfxPlatformMac; @@ -101,11 +112,17 @@ private: virtual ~gfxMacPlatformFontList(); // initialize font lists - virtual nsresult InitFontList(); + nsresult InitFontList() override; // special case font faces treated as font families (set via prefs) void InitSingleFaceList(); + // initialize system fonts + void InitSystemFonts(); + + // helper function to lookup in both hidden system fonts and normal fonts + gfxFontFamily* FindSystemFontFamily(const nsAString& aFamily); + static void RegisteredFontsChangedNotificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, @@ -113,15 +130,15 @@ private: CFDictionaryRef userInfo); // search fonts system-wide for a given character, null otherwise - virtual gfxFontEntry* GlobalFontFallback(const uint32_t aCh, - int32_t aRunScript, - const gfxFontStyle* aMatchStyle, - uint32_t& aCmapCount, - gfxFontFamily** aMatchedFamily); + gfxFontEntry* GlobalFontFallback(const uint32_t aCh, + int32_t aRunScript, + const gfxFontStyle* aMatchStyle, + uint32_t& aCmapCount, + gfxFontFamily** aMatchedFamily) override; - virtual bool UsesSystemFallback() { return true; } + bool UsesSystemFallback() override { return true; } - virtual already_AddRefed CreateFontInfoData(); + already_AddRefed CreateFontInfoData() override; // Add the specified family to mSystemFontFamilies or mFontFamilies. // Ideally we'd use NSString* instead of CFStringRef here, but this header @@ -140,6 +157,18 @@ private: // default font for use with system-wide font fallback CTFontRef mDefaultFont; + + // hidden system fonts used within UI elements, there may be a whole set + // for different locales (e.g. .Helvetica Neue UI, .SF NS Text) + FontFamilyTable mSystemFontFamilies; + + // font families that -apple-system maps to + // Pre-10.11 this was always a single font family, such as Lucida Grande + // or Helvetica Neue. For OSX 10.11, Apple uses pair of families + // for the UI, one for text sizes and another for display sizes + bool mUseSizeSensitiveSystemFont; + nsRefPtr mSystemTextFontFamily; + nsRefPtr mSystemDisplayFontFamily; // only used on OSX 10.11 }; #endif /* gfxMacPlatformFontList_H_ */ diff --git a/gfx/thebes/gfxMacPlatformFontList.mm b/gfx/thebes/gfxMacPlatformFontList.mm index fe2f97a1309..f88e01a82f0 100644 --- a/gfx/thebes/gfxMacPlatformFontList.mm +++ b/gfx/thebes/gfxMacPlatformFontList.mm @@ -552,7 +552,6 @@ gfxMacFontFamily::FindStyleVariations(FontInfoData *aFontInfoData) } } - /* gfxSingleFaceMacFontFamily */ #pragma mark- @@ -629,7 +628,8 @@ gfxSingleFaceMacFontFamily::ReadOtherFamilyNames(gfxPlatformFontList *aPlatformF gfxMacPlatformFontList::gfxMacPlatformFontList() : gfxPlatformFontList(false), - mDefaultFont(nullptr) + mDefaultFont(nullptr), + mUseSizeSensitiveSystemFont(false) { #ifdef MOZ_BUNDLED_FONTS ActivateBundledFonts(); @@ -645,6 +645,18 @@ gfxMacPlatformFontList::gfxMacPlatformFontList() : // cache this in a static variable so that MacOSFontFamily objects // don't have to repeatedly look it up sFontManager = [NSFontManager sharedFontManager]; + +#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 = [[NSFont systemFontOfSize:0.0] familyName]; + if ([sysFamily compare:[[NSFont boldSystemFontOfSize:0.0] familyName]] != NSOrderedSame || + [sysFamily compare:[[NSFont controlContentFontOfSize:0.0] familyName]] != NSOrderedSame || + [sysFamily compare:[[NSFont menuBarFontOfSize:0.0] familyName]] != NSOrderedSame || + [sysFamily compare:[[NSFont toolTipsFontOfSize:0.0] familyName]] != NSOrderedSame) { + NS_WARNING("system font types map to different font families -- please log a bug!!"); + } +#endif } gfxMacPlatformFontList::~gfxMacPlatformFontList() @@ -708,6 +720,8 @@ gfxMacPlatformFontList::InitFontList() InitSingleFaceList(); + InitSystemFonts(); + // to avoid full search of font name tables, seed the other names table with localized names from // some of the prefs fonts which are accessed via their localized names. changes in the pref fonts will only cause // a font lookup miss earlier. this is a simple optimization, it's not required for correctness @@ -757,6 +771,90 @@ 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) +{ + NSFont* f = [NSFont fontWithName: [[aFont fontDescriptor] postscriptName] + size: 0.0]; + return [f familyName]; +} + +// System fonts under OSX 10.11 use a combination of two families, one +// for text sizes and another for larger, display sizes. Each has a +// different number of weights. There aren't efficient API's for looking +// this information up, so hard code the logic here but confirm via +// debug assertions that the logic is correct. + +const CGFloat kTextDisplayCrossover = 20.0; // use text family below this size + +void +gfxMacPlatformFontList::InitSystemFonts() +{ + // system font under 10.11 are two distinct families for text/display sizes + if (nsCocoaFeatures::OnElCapitanOrLater()) { + mUseSizeSensitiveSystemFont = true; + } + + // text font family + NSFont* sys = [NSFont systemFontOfSize: 0.0]; + NSString* textFamilyName = GetRealFamilyName(sys); + nsAutoString familyName; + nsCocoaUtils::GetStringForNSString(textFamilyName, familyName); + mSystemTextFontFamily = FindSystemFontFamily(familyName); + NS_ASSERTION(mSystemTextFontFamily, "null system display font family"); + + // display font family, if on OSX 10.11 + if (mUseSizeSensitiveSystemFont) { + sys = [NSFont systemFontOfSize: 128.0]; + NSString* displayFamilyName = GetRealFamilyName(sys); + nsCocoaUtils::GetStringForNSString(displayFamilyName, familyName); + mSystemDisplayFontFamily = FindSystemFontFamily(familyName); + NS_ASSERTION(mSystemDisplayFontFamily, "null system display font family"); + +#if DEBUG + // confirm that the optical size switch is at 20.0 + NS_ASSERTION(mSystemTextFontFamily && mSystemDisplayFontFamily && + [textFamilyName compare:displayFamilyName] != NSOrderedSame, + "system text/display fonts are the same!"); + NSString* fam19 = GetRealFamilyName([NSFont systemFontOfSize: + (kTextDisplayCrossover - 1.0)]); + NSString* fam20 = GetRealFamilyName([NSFont systemFontOfSize: + kTextDisplayCrossover]); + NS_ASSERTION(fam19 && fam20 && [fam19 compare:fam20] != NSOrderedSame, + "system text/display font size switch point is not as expected!"); +#endif + } + +} + +gfxFontFamily* +gfxMacPlatformFontList::FindSystemFontFamily(const nsAString& aFamily) +{ + nsAutoString key; + GenerateFontListKey(aFamily, key); + + gfxFontFamily* familyEntry; + + // lookup in hidden system family name list + if ((familyEntry = mSystemFontFamilies.GetWeak(key))) { + return CheckFamily(familyEntry); + } + + // lookup in user-exposed family name list + if ((familyEntry = mFontFamilies.GetWeak(key))) { + return CheckFamily(familyEntry); + } + + return nullptr; +} + bool gfxMacPlatformFontList::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) { @@ -996,6 +1094,97 @@ gfxMacPlatformFontList::MakePlatformFont(const nsAString& aFontName, return nullptr; } +// Webkit code uses a system font meta name, so mimic that here +// WebCore/platform/graphics/mac/FontCacheMac.mm +static const char kSystemFont_system[] = "-apple-system"; + +gfxFontFamily* +gfxMacPlatformFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle) +{ + // search for special system font name, -apple-system + if (aFamily.EqualsLiteral(kSystemFont_system)) { + if (mUseSizeSensitiveSystemFont && + aStyle && aStyle->size >= kTextDisplayCrossover) { + return mSystemDisplayFontFamily; + } + return mSystemTextFontFamily; + } + + return gfxPlatformFontList::FindFamily(aFamily, aStyle); +} + +void +gfxMacPlatformFontList::LookupSystemFont(LookAndFeel::FontID aSystemFontID, + nsAString& aSystemFontName, + gfxFontStyle &aFontStyle, + float aDevPixPerCSSPixel) +{ + // code moved here from widget/cocoa/nsLookAndFeel.mm + NSFont *font = nullptr; + char* systemFontName = nullptr; + switch (aSystemFontID) { + case LookAndFeel::eFont_MessageBox: + case LookAndFeel::eFont_StatusBar: + case LookAndFeel::eFont_List: + case LookAndFeel::eFont_Field: + case LookAndFeel::eFont_Button: + case LookAndFeel::eFont_Widget: + font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; + systemFontName = (char*) kSystemFont_system; + break; + + case LookAndFeel::eFont_SmallCaption: + font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]]; + systemFontName = (char*) kSystemFont_system; + break; + + case LookAndFeel::eFont_Icon: // used in urlbar; tried labelFont, but too small + case LookAndFeel::eFont_Workspace: + case LookAndFeel::eFont_Desktop: + case LookAndFeel::eFont_Info: + font = [NSFont controlContentFontOfSize:0.0]; + systemFontName = (char*) kSystemFont_system; + break; + + case LookAndFeel::eFont_PullDownMenu: + font = [NSFont menuBarFontOfSize:0.0]; + systemFontName = (char*) kSystemFont_system; + break; + + case LookAndFeel::eFont_Tooltips: + font = [NSFont toolTipsFontOfSize:0.0]; + systemFontName = (char*) kSystemFont_system; + break; + + case LookAndFeel::eFont_Caption: + case LookAndFeel::eFont_Menu: + case LookAndFeel::eFont_Dialog: + default: + font = [NSFont systemFontOfSize:0.0]; + systemFontName = (char*) kSystemFont_system; + break; + } + NS_ASSERTION(font, "system font not set"); + NS_ASSERTION(systemFontName, "system font name not set"); + + if (systemFontName) { + aSystemFontName.AssignASCII(systemFontName); + } + + NSFontSymbolicTraits traits = [[font fontDescriptor] symbolicTraits]; + aFontStyle.style = + (traits & NSFontItalicTrait) ? NS_FONT_STYLE_ITALIC : NS_FONT_STYLE_NORMAL; + aFontStyle.weight = + (traits & NSFontBoldTrait) ? NS_FONT_WEIGHT_BOLD : NS_FONT_WEIGHT_NORMAL; + aFontStyle.stretch = + (traits & NSFontExpandedTrait) ? + NS_FONT_STRETCH_EXPANDED : (traits & NSFontCondensedTrait) ? + NS_FONT_STRETCH_CONDENSED : NS_FONT_STRETCH_NORMAL; + // convert size from css pixels to device pixels + aFontStyle.size = [font pointSize] * aDevPixPerCSSPixel; + aFontStyle.systemFont = true; +} + // used to load system-wide font info on off-main thread class MacFontInfo : public FontInfoData { public: diff --git a/gfx/thebes/gfxPlatformFontList.cpp b/gfx/thebes/gfxPlatformFontList.cpp index 95e10665d2f..9f5b4dd5e3b 100644 --- a/gfx/thebes/gfxPlatformFontList.cpp +++ b/gfx/thebes/gfxPlatformFontList.cpp @@ -657,9 +657,7 @@ gfxPlatformFontList::CheckFamily(gfxFontFamily *aFamily) } gfxFontFamily* -gfxPlatformFontList::FindFamily(const nsAString& aFamily, - nsIAtom* aLanguage, - bool aUseSystemFonts) +gfxPlatformFontList::FindFamily(const nsAString& aFamily, gfxFontStyle* aStyle) { nsAutoString key; gfxFontFamily *familyEntry; @@ -672,15 +670,6 @@ gfxPlatformFontList::FindFamily(const nsAString& aFamily, return CheckFamily(familyEntry); } -#if defined(XP_MACOSX) - // for system font types allow hidden system fonts to be referenced - if (aUseSystemFonts) { - if ((familyEntry = mSystemFontFamilies.GetWeak(key)) != nullptr) { - return CheckFamily(familyEntry); - } - } -#endif - // lookup in other family names list (mostly localized names) if ((familyEntry = mOtherFamilyNames.GetWeak(key)) != nullptr) { return CheckFamily(familyEntry); @@ -874,8 +863,11 @@ gfxPlatformFontList::ResolveGenericFontNames( // lookup and add platform fonts uniquely for (const nsString& genericFamily : genericFamilies) { + gfxFontStyle style; + style.language = langGroup; + style.systemFont = false; nsRefPtr family = - FindFamily(genericFamily, langGroup, false); + FindFamily(genericFamily, &style); if (family) { bool notFound = true; for (const gfxFontFamily* f : *aGenericFamilies) { diff --git a/gfx/thebes/gfxPlatformFontList.h b/gfx/thebes/gfxPlatformFontList.h index 80b4bacbcf2..d5c1dd8d220 100644 --- a/gfx/thebes/gfxPlatformFontList.h +++ b/gfx/thebes/gfxPlatformFontList.h @@ -130,8 +130,7 @@ public: const gfxFontStyle* aStyle); virtual gfxFontFamily* FindFamily(const nsAString& aFamily, - nsIAtom* aLanguage = nullptr, - bool aUseSystemFonts = false); + gfxFontStyle* aStyle = nullptr); gfxFontEntry* FindFontForFamily(const nsAString& aFamily, const gfxFontStyle* aStyle, bool& aNeedsBold); @@ -347,11 +346,6 @@ protected: // canonical family name ==> family entry (unique, one name per family entry) FontFamilyTable mFontFamilies; -#if defined(XP_MACOSX) - // hidden system fonts used within UI elements - FontFamilyTable mSystemFontFamilies; -#endif - // other family name ==> family entry (not unique, can have multiple names per // family entry, only names *other* than the canonical names are stored here) FontFamilyTable mOtherFamilyNames; diff --git a/gfx/thebes/gfxPlatformMac.cpp b/gfx/thebes/gfxPlatformMac.cpp index f1821aea8d7..ce357c54334 100644 --- a/gfx/thebes/gfxPlatformMac.cpp +++ b/gfx/thebes/gfxPlatformMac.cpp @@ -388,6 +388,17 @@ gfxPlatformMac::GetCommonFallbackFonts(uint32_t aCh, uint32_t aNextCh, aFontList.AppendElement(kFontArialUnicodeMS); } +/*static*/ void +gfxPlatformMac::LookupSystemFont(mozilla::LookAndFeel::FontID aSystemFontID, + nsAString& aSystemFontName, + gfxFontStyle& aFontStyle, + float aDevPixPerCSSPixel) +{ + gfxMacPlatformFontList* pfl = gfxMacPlatformFontList::PlatformFontList(); + return pfl->LookupSystemFont(aSystemFontID, aSystemFontName, aFontStyle, + aDevPixPerCSSPixel); +} + uint32_t gfxPlatformMac::ReadAntiAliasingThreshold() { diff --git a/gfx/thebes/gfxPlatformMac.h b/gfx/thebes/gfxPlatformMac.h index 4c28df91b60..a4046e6933a 100644 --- a/gfx/thebes/gfxPlatformMac.h +++ b/gfx/thebes/gfxPlatformMac.h @@ -8,6 +8,7 @@ #include "nsTArrayForwardDeclare.h" #include "gfxPlatform.h" +#include "mozilla/LookAndFeel.h" namespace mozilla { namespace gfx { @@ -65,6 +66,14 @@ public: int32_t aRunScript, nsTArray& aFontList) override; + // lookup the system font for a particular system font type and set + // the name and style characteristics + static void + LookupSystemFont(mozilla::LookAndFeel::FontID aSystemFontID, + nsAString& aSystemFontName, + gfxFontStyle &aFontStyle, + float aDevPixPerCSSPixel); + virtual bool CanRenderContentToDataSurface() const override { return true; } diff --git a/gfx/thebes/gfxTextRun.cpp b/gfx/thebes/gfxTextRun.cpp index ebb7b339da7..d2610e6b0d1 100644 --- a/gfx/thebes/gfxTextRun.cpp +++ b/gfx/thebes/gfxTextRun.cpp @@ -1623,7 +1623,7 @@ gfxFontGroup::AddPlatformFont(const nsAString& aName, // Not known in the user font set ==> check system fonts if (!family) { gfxPlatformFontList* fontList = gfxPlatformFontList::PlatformFontList(); - family = fontList->FindFamily(aName, mStyle.language, mStyle.systemFont); + family = fontList->FindFamily(aName, &mStyle); } if (family) { @@ -3023,28 +3023,6 @@ gfxFontGroup::ContainsUserFont(const gfxUserFontEntry* aUserFont) return false; } -struct PrefFontCallbackData { - explicit PrefFontCallbackData(nsTArray >& aFamiliesArray) - : mPrefFamilies(aFamiliesArray) - {} - - nsTArray >& mPrefFamilies; - - static bool AddFontFamilyEntry(eFontPrefLang aLang, const nsAString& aName, void *aClosure) - { - PrefFontCallbackData *prefFontData = static_cast(aClosure); - - // map pref lang to langGroup for language-sensitive lookups - nsIAtom* lang = gfxPlatformFontList::GetLangGroupForPrefLang(aLang); - gfxFontFamily *family = - gfxPlatformFontList::PlatformFontList()->FindFamily(aName, lang); - if (family) { - prefFontData->mPrefFamilies.AppendElement(family); - } - return true; - } -}; - already_AddRefed gfxFontGroup::WhichPrefFontSupportsChar(uint32_t aCh) { diff --git a/widget/cocoa/nsLookAndFeel.mm b/widget/cocoa/nsLookAndFeel.mm index 463496bd880..719190f0552 100644 --- a/widget/cocoa/nsLookAndFeel.mm +++ b/widget/cocoa/nsLookAndFeel.mm @@ -11,6 +11,7 @@ #include "nsCocoaFeatures.h" #include "gfxFont.h" #include "gfxFontConstants.h" +#include "gfxPlatformMac.h" #include "mozilla/gfx/2D.h" #include "mozilla/widget/WidgetMessageUtils.h" @@ -527,14 +528,6 @@ bool nsLookAndFeel::AllowOverlayScrollbarsOverlap() return (UseOverlayScrollbars() && nsCocoaFeatures::OnMountainLionOrLater()); } -// copied from gfxQuartzFontCache.mm, maybe should go in a Cocoa utils -// file somewhere -static void GetStringForNSString(const NSString *aSrc, nsAString& aDest) -{ - aDest.SetLength([aSrc length]); - [aSrc getCharacters:reinterpret_cast(aDest.BeginWriting())]; -} - bool nsLookAndFeel::GetFontImpl(FontID aID, nsString &aFontName, gfxFontStyle &aFontStyle, @@ -554,101 +547,9 @@ nsLookAndFeel::GetFontImpl(FontID aID, nsString &aFontName, return true; } -/* possibilities, see NSFont Class Reference: - [NSFont boldSystemFontOfSize: 0.0] - [NSFont controlContentFontOfSize: 0.0] - [NSFont labelFontOfSize: 0.0] - [NSFont menuBarFontOfSize: 0.0] - [NSFont menuFontOfSize: 0.0] - [NSFont messageFontOfSize: 0.0] - [NSFont paletteFontOfSize: 0.0] - [NSFont systemFontOfSize: 0.0] - [NSFont titleBarFontOfSize: 0.0] - [NSFont toolTipsFontOfSize: 0.0] - [NSFont userFixedPitchFontOfSize: 0.0] - [NSFont userFontOfSize: 0.0] - [NSFont systemFontOfSize: [NSFont smallSystemFontSize]] - [NSFont boldSystemFontOfSize: [NSFont smallSystemFontSize]] -*/ + gfxPlatformMac::LookupSystemFont(aID, aFontName, aFontStyle, + aDevPixPerCSSPixel); - NSFont *font = nullptr; - switch (aID) { - // css2 - case eFont_Caption: - font = [NSFont systemFontOfSize:0.0]; - break; - case eFont_Icon: // used in urlbar; tried labelFont, but too small - font = [NSFont controlContentFontOfSize:0.0]; - break; - case eFont_Menu: - font = [NSFont systemFontOfSize:0.0]; - break; - case eFont_MessageBox: - font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; - break; - case eFont_SmallCaption: - font = [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]]; - break; - case eFont_StatusBar: - font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; - break; - // css3 - //case eFont_Window: = 'sans-serif' - //case eFont_Document: = 'sans-serif' - case eFont_Workspace: - font = [NSFont controlContentFontOfSize:0.0]; - break; - case eFont_Desktop: - font = [NSFont controlContentFontOfSize:0.0]; - break; - case eFont_Info: - font = [NSFont controlContentFontOfSize:0.0]; - break; - case eFont_Dialog: - font = [NSFont systemFontOfSize:0.0]; - break; - case eFont_Button: - font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; - break; - case eFont_PullDownMenu: - font = [NSFont menuBarFontOfSize:0.0]; - break; - case eFont_List: - font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; - break; - case eFont_Field: - font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; - break; - // moz - case eFont_Tooltips: - font = [NSFont toolTipsFontOfSize:0.0]; - break; - case eFont_Widget: - font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; - break; - default: - break; - } - - if (!font) { - NS_WARNING("failed to find a system font!"); - return false; - } - - NSFontSymbolicTraits traits = [[font fontDescriptor] symbolicTraits]; - aFontStyle.style = - (traits & NSFontItalicTrait) ? NS_FONT_STYLE_ITALIC : NS_FONT_STYLE_NORMAL; - aFontStyle.weight = - (traits & NSFontBoldTrait) ? NS_FONT_WEIGHT_BOLD : NS_FONT_WEIGHT_NORMAL; - aFontStyle.stretch = - (traits & NSFontExpandedTrait) ? - NS_FONT_STRETCH_EXPANDED : (traits & NSFontCondensedTrait) ? - NS_FONT_STRETCH_CONDENSED : NS_FONT_STRETCH_NORMAL; - // convert size from css pixels to device pixels - aFontStyle.size = [font pointSize] * aDevPixPerCSSPixel; - aFontStyle.systemFont = true; - - GetStringForNSString([font familyName], aFontName); return true; NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);