Bug 1244017 - remove system font cascade for OSX. r=m_kato
authorJohn Daggett <jd.bugzilla@gmail.com>
Mon, 08 Feb 2016 15:26:50 +0900
changeset 283431 149dc37ee4c71fe51780f0864b201755fb1658e0
parent 283430 a674340dc97ef303e1959eb9efc2d9cf49755bde
child 283432 ac338559876df7b2e81388f2aac28d2e95ceb5ff
push id29982
push usercbook@mozilla.com
push dateMon, 08 Feb 2016 10:57:27 +0000
treeherdermozilla-central@ac338559876d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1244017
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1244017 - remove system font cascade for OSX. r=m_kato
gfx/thebes/gfxFontEntry.h
gfx/thebes/gfxMacPlatformFontList.h
gfx/thebes/gfxMacPlatformFontList.mm
gfx/thebes/gfxPlatformFontList.h
gfx/thebes/gfxTextRun.cpp
--- a/gfx/thebes/gfxFontEntry.h
+++ b/gfx/thebes/gfxFontEntry.h
@@ -662,18 +662,17 @@ public:
         mOtherFamilyNamesInitialized(false),
         mHasOtherFamilyNames(false),
         mFaceNamesInitialized(false),
         mHasStyles(false),
         mIsSimpleFamily(false),
         mIsBadUnderlineFamily(false),
         mFamilyCharacterMapInitialized(false),
         mSkipDefaultFeatureSpaceCheck(false),
-        mCheckForFallbackFaces(false),
-        mLinkedSystemFamily(false)
+        mCheckForFallbackFaces(false)
         { }
 
     const nsString& Name() { return mName; }
 
     virtual void LocalizedName(nsAString& aLocalizedName);
     virtual bool HasOtherFamilyNames();
     
     nsTArray<RefPtr<gfxFontEntry> >& GetFontList() { return mAvailableFonts; }
@@ -792,19 +791,16 @@ public:
     // Only used for debugging checks - does a linear search
     bool ContainsFace(gfxFontEntry* aFontEntry);
 #endif
 
     void SetSkipSpaceFeatureCheck(bool aSkipCheck) {
         mSkipDefaultFeatureSpaceCheck = aSkipCheck;
     }
 
-    bool LinkedSystemFamily() const { return mLinkedSystemFamily; }
-    void SetLinkedSystemFamily() { mLinkedSystemFamily = true; }
-
 protected:
     // Protected destructor, to discourage deletion outside of Release():
     virtual ~gfxFontFamily()
     {
     }
 
     bool ReadOtherFamilyNamesForFace(gfxPlatformFontList *aPlatformFontList,
                                      hb_blob_t           *aNameTable,
@@ -827,17 +823,16 @@ protected:
     bool mHasOtherFamilyNames : 1;
     bool mFaceNamesInitialized : 1;
     bool mHasStyles : 1;
     bool mIsSimpleFamily : 1;
     bool mIsBadUnderlineFamily : 1;
     bool mFamilyCharacterMapInitialized : 1;
     bool mSkipDefaultFeatureSpaceCheck : 1;
     bool mCheckForFallbackFaces : 1;  // check other faces for character
-    bool mLinkedSystemFamily : 1;  // system fonts linked to other families
 
     enum {
         // for "simple" families, the faces are stored in mAvailableFonts
         // with fixed positions:
         kRegularFaceIndex    = 0,
         kBoldFaceIndex       = 1,
         kItalicFaceIndex     = 2,
         kBoldItalicFaceIndex = 3,
--- a/gfx/thebes/gfxMacPlatformFontList.h
+++ b/gfx/thebes/gfxMacPlatformFontList.h
@@ -101,39 +101,31 @@ public:
 
     // 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);
 
-    virtual void
-    AppendLinkedSystemFamilies(nsIAtom* aLanguage,
-                               nsTArray<gfxFontFamily*>& aFamilyList) override;
-
 private:
     friend class gfxPlatformMac;
 
     gfxMacPlatformFontList();
     virtual ~gfxMacPlatformFontList();
 
     // initialize font lists
     nsresult InitFontList() override;
 
     // special case font faces treated as font families (set via prefs)
     void InitSingleFaceList();
 
     // initialize system fonts
     void InitSystemFonts();
 
-    // helper function for looking up font cascades
-    void LookupFontCascadeForLang(const nsACString& aLang,
-                                  nsTArray<gfxFontFamily*>& aCascadeList);
-
     // 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,
                                                            const void *object,
                                                            CFDictionaryRef userInfo);
@@ -173,25 +165,11 @@ private:
 
     // 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;
     RefPtr<gfxFontFamily> mSystemTextFontFamily;
     RefPtr<gfxFontFamily> mSystemDisplayFontFamily; // only used on OSX 10.11
-
-    // system font cascade - under OSX, the system font is effectively
-    // not a single family but a fontlist with the Latin font at the end
-    // of the list (e.g. Lucida Grande, Helevetica Neue, San Francisco)
-
-    // most languages use a common default set of choices matching lang=en
-    PrefFontList mDefaultCascadeFamilies;
-
-    // for languages where the fontlist doesn't match the default list
-    // (e.g. zh-TW will prioritize the traditional Chinese font over the
-    // Japanese font)
-    nsBaseHashtable<nsCStringHashKey,
-                    nsAutoPtr<PrefFontList>,
-                    PrefFontList*> mNonDefaultCascadeFamilies;
 };
 
 #endif /* gfxMacPlatformFontList_H_ */
--- a/gfx/thebes/gfxMacPlatformFontList.mm
+++ b/gfx/thebes/gfxMacPlatformFontList.mm
@@ -618,20 +618,16 @@ gfxSingleFaceMacFontFamily::ReadOtherFam
 
     mHasOtherFamilyNames = ReadOtherFamilyNamesForFace(aPlatformFontList,
                                                        nameTable,
                                                        true);
 
     mOtherFamilyNamesInitialized = true;
 }
 
-typedef CFArrayRef (CTFontCopyDefaultCascadeListForLanguagesFunc)(CTFontRef font, CFArrayRef languagePrefList);
-static CTFontCopyDefaultCascadeListForLanguagesFunc*
-    CTFontCopyDefaultCascadeListForLanguagesPtr = nullptr;
-
 /* gfxMacPlatformFontList */
 #pragma mark-
 
 gfxMacPlatformFontList::gfxMacPlatformFontList() :
     gfxPlatformFontList(false),
     mDefaultFont(nullptr),
     mUseSizeSensitiveSystemFont(false)
 {
@@ -644,21 +640,16 @@ gfxMacPlatformFontList::gfxMacPlatformFo
                                       RegisteredFontsChangedNotificationCallback,
                                       kCTFontManagerRegisteredFontsChangedNotification,
                                       0,
                                       CFNotificationSuspensionBehaviorDeliverImmediately);
 
     // cache this in a static variable so that MacOSFontFamily objects
     // don't have to repeatedly look it up
     sFontManager = [NSFontManager sharedFontManager];
-
-    // available in 10.8 and above
-    CTFontCopyDefaultCascadeListForLanguagesPtr =
-        (CTFontCopyDefaultCascadeListForLanguagesFunc*)
-            dlsym(RTLD_DEFAULT, "CTFontCopyDefaultCascadeListForLanguages");
 }
 
 gfxMacPlatformFontList::~gfxMacPlatformFontList()
 {
     if (mDefaultFont) {
         ::CFRelease(mDefaultFont);
     }
 }
@@ -787,97 +778,38 @@ static NSString* GetRealFamilyName(NSFon
 // 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::LookupFontCascadeForLang(const nsACString& aLang,
-                                                 nsTArray<gfxFontFamily*>& aCascadeList)
-{
-    // if cascade not available just return empty list
-    if (!CTFontCopyDefaultCascadeListForLanguagesPtr) {
-        return;
-    }
-
-    // get the system font (note: the lang parameter doesn't affect the result)
-    CTFontRef systemFont =
-        CTFontCreateUIFontForLanguage(kCTFontSystemFontType, 12.0,
-                                      CFSTR("en-US"));
-
-    // fetch cascade list
-    CFStringRef langStr =
-        CFStringCreateWithCString(kCFAllocatorDefault,
-                                  PromiseFlatCString(aLang).get(),
-                                  kCFStringEncodingUTF8);
-    CFStringRef languages[1] = { langStr };
-    CFArrayRef langList = CFArrayCreate(kCFAllocatorDefault,
-                                        (const void **) languages, 1,
-                                        &kCFTypeArrayCallBacks);
-    CFRelease(langStr);
-    CFArrayRef cascade =
-        CTFontCopyDefaultCascadeListForLanguagesPtr(systemFont, langList);
-    CFRelease(systemFont);
-    CFRelease(langList);
-
-    // iterate over font descriptors in cascade array
-    for (NSFontDescriptor* fontDesc in (NSArray*) cascade) {
-        // First, determine the font family name. Since font cascades
-        // sometimes include weird "meta" names, need to determine the
-        // family name using the CGFont object
-        CTFontDescriptorRef fd = (CTFontDescriptorRef) fontDesc;
-        CTFontRef fontRef = CTFontCreateWithFontDescriptor(fd, 0.0, 0);
-        CFRelease(fd);
-        CGFontRef cgFontRef = CTFontCopyGraphicsFont(fontRef, NULL);
-        CFRelease(fontRef);
-        CFStringRef psname = CGFontCopyPostScriptName(cgFontRef);
-        CFRelease(cgFontRef);
-        fontRef = CTFontCreateWithName(psname, 0.0, NULL);
-        CFRelease(psname);
-        CFStringRef name = CTFontCopyFamilyName(fontRef);
-        CFRelease(fontRef);
-
-        // lookup the family and append it to the list
-        nsAutoString familyStr;
-        GetStringForNSString((NSString*) name, familyStr);
-        CFRelease(name);
-        gfxFontFamily* family = FindFamily(familyStr);
-        if (family) {
-            aCascadeList.AppendElement(family);
-        }
-    }
-}
-
-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");
-    mSystemTextFontFamily->SetLinkedSystemFamily();
 
     // display font family, if on OSX 10.11
     if (mUseSizeSensitiveSystemFont) {
         NSFont* displaySys = [NSFont systemFontOfSize: 128.0];
         NSString* displayFamilyName = GetRealFamilyName(displaySys);
         nsCocoaUtils::GetStringForNSString(displayFamilyName, familyName);
         mSystemDisplayFontFamily = FindSystemFontFamily(familyName);
         NS_ASSERTION(mSystemDisplayFontFamily, "null system display font family");
-        mSystemDisplayFontFamily->SetLinkedSystemFamily();
 
 #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)]);
@@ -895,21 +827,16 @@ gfxMacPlatformFontList::InitSystemFonts(
     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
-
-    nsAutoCString en("en");
-    AutoTArray<gfxFontFamily*,10> list;
-    LookupFontCascadeForLang(en, list);
-    mDefaultCascadeFamilies.AppendElements(list);
 }
 
 gfxFontFamily*
 gfxMacPlatformFontList::FindSystemFontFamily(const nsAString& aFamily)
 {
     nsAutoString key;
     GenerateFontListKey(aFamily, key);
 
@@ -1247,76 +1174,16 @@ gfxMacPlatformFontList::LookupSystemFont
         (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;
 }
 
-void
-gfxMacPlatformFontList::AppendLinkedSystemFamilies(nsIAtom* aLanguage,
-                                                   nsTArray<gfxFontFamily*>& aFamilyList)
-{
-    // map lang atom to lang string
-    nsAutoCString lang;
-    GetSampleLangForGroup(aLanguage, lang, false);
-    ToLowerCase(lang);
-
-    // quick exit for older versions of OSX
-    if (mDefaultCascadeFamilies.IsEmpty()) {
-        return;
-    }
-
-    // assume default cascade except for CJK locales
-    bool defaultCascade = true;
-    if (lang.Length() >= 2) {
-        const nsACString& langTag = Substring(lang, 0, 2);
-        if (langTag.EqualsLiteral("zh")) {
-            defaultCascade = false;
-            // the font cascade code is fussy about the hyphen/underbar before
-            // the region code, so zh_TW is recognized, zh-TW is ignored
-            if (lang.EqualsLiteral("zh-tw")) {
-                lang.AssignLiteral("zh_tw");
-            } else if (lang.EqualsLiteral("zh-cn")) {
-                lang.AssignLiteral("zh_cn");
-            } else if (lang.EqualsLiteral("zh-hk")) {
-                lang.AssignLiteral("zh_hk");
-            }
-        } else if (langTag.EqualsLiteral("ja") ||
-                   langTag.EqualsLiteral("ko")) {
-            defaultCascade = false;
-        }
-    }
-
-    if (defaultCascade) {
-        aFamilyList.AppendElements(mDefaultCascadeFamilies);
-        return;
-    }
-
-    // check to see if cached already
-    PrefFontList* fontsForLang = mNonDefaultCascadeFamilies.Get(lang);
-    if (fontsForLang) {
-        aFamilyList.AppendElements(*fontsForLang);
-        return;
-    }
-
-    // lookup the cascade fonts
-    AutoTArray<gfxFontFamily*,30> list;
-    LookupFontCascadeForLang(lang, list);
-
-    // add cascade to cascade cache
-    fontsForLang = new PrefFontList;
-    fontsForLang->AppendElements(list);
-    mNonDefaultCascadeFamilies.Put(lang, fontsForLang);
-
-    // use the new list
-    aFamilyList.AppendElements(list);
-}
-
 // used to load system-wide font info on off-main thread
 class MacFontInfo : public FontInfoData {
 public:
     MacFontInfo(bool aLoadOtherNames,
                 bool aLoadFaceNames,
                 bool aLoadCmaps) :
         FontInfoData(aLoadOtherNames, aLoadFaceNames, aLoadCmaps)
     {}
--- a/gfx/thebes/gfxPlatformFontList.h
+++ b/gfx/thebes/gfxPlatformFontList.h
@@ -195,20 +195,16 @@ public:
 
     static const gfxFontEntry::ScriptRange sComplexScriptRanges[];
 
     void GetFontlistInitInfo(uint32_t& aNumInits, uint32_t& aLoaderState) {
         aNumInits = mFontlistInitCount;
         aLoaderState = (uint32_t) mState;
     }
 
-    // for platforms that use linked system fontlists, append these
-    virtual void
-    AppendLinkedSystemFamilies(nsIAtom* aLanguage,
-                               nsTArray<gfxFontFamily*>& aFamilyList) {}
     virtual void
     AddGenericFonts(mozilla::FontFamilyType aGenericType,
                     nsIAtom* aLanguage,
                     nsTArray<gfxFontFamily*>& aFamilyList);
 
     nsTArray<RefPtr<gfxFontFamily>>*
     GetPrefFontsLangGroup(mozilla::FontFamilyType aGenericType,
                           eFontPrefLang aPrefLang);
--- a/gfx/thebes/gfxTextRun.cpp
+++ b/gfx/thebes/gfxTextRun.cpp
@@ -1664,22 +1664,16 @@ gfxFontGroup::AddPlatformFont(const nsAS
     // Not known in the user font set ==> check system fonts
     gfxPlatformFontList* fontList = gfxPlatformFontList::PlatformFontList();
     if (!family) {
         family = fontList->FindFamily(aName, &mStyle, mDevToCssSize);
     }
 
     if (family) {
         aFamilyList.AppendElement(family);
-        // In some cases, system generic fonts are linked to a set of
-        // families, so include these if that's the case
-        if (family->LinkedSystemFamily()) {
-            fontList->AppendLinkedSystemFamilies(mStyle.language,
-                                                 aFamilyList);
-        }
     }
 }
 
 void
 gfxFontGroup::AddFamilyToFontList(gfxFontFamily* aFamily)
 {
     NS_ASSERTION(aFamily, "trying to add a null font family to fontlist");
     AutoTArray<gfxFontEntry*,4> fontEntryList;