Bug 1201318 - Factor out AddFamily. r=jdaggett, a=lizzard
authorMarkus Stange <mstange@themasta.com>
Thu, 03 Sep 2015 13:44:43 -0400
changeset 298467 b6f944763659e597660c4d48aea8782d28429543
parent 298466 5284eeaeb23e18e7848cee5551c4d3dd5b5a0894
child 298468 01ac7ddda781ed2e48967778020d2724da4651d2
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett, lizzard
bugs1201318
milestone43.0
Bug 1201318 - Factor out AddFamily. r=jdaggett, a=lizzard
gfx/thebes/gfxMacPlatformFontList.h
gfx/thebes/gfxMacPlatformFontList.mm
--- a/gfx/thebes/gfxMacPlatformFontList.h
+++ b/gfx/thebes/gfxMacPlatformFontList.h
@@ -118,16 +118,23 @@ private:
                                              const gfxFontStyle* aMatchStyle,
                                              uint32_t& aCmapCount,
                                              gfxFontFamily** aMatchedFamily);
 
     virtual bool UsesSystemFallback() { return true; }
 
     virtual already_AddRefed<FontInfoData> CreateFontInfoData();
 
+    // Add the specified family to mSystemFontFamilies or mFontFamilies.
+    // Ideally we'd use NSString* instead of CFStringRef here, but this header
+    // file is included in .cpp files, so we can't use objective C classes here.
+    // But CFStringRef and NSString* are the same thing anyway (they're
+    // toll-free bridged).
+    void AddFamily(CFStringRef aFamily);
+
 #ifdef MOZ_BUNDLED_FONTS
     void ActivateBundledFonts();
 #endif
 
     enum {
         kATSGenerationInitial = -1
     };
 
--- a/gfx/thebes/gfxMacPlatformFontList.mm
+++ b/gfx/thebes/gfxMacPlatformFontList.mm
@@ -649,74 +649,64 @@ gfxMacPlatformFontList::gfxMacPlatformFo
 
 gfxMacPlatformFontList::~gfxMacPlatformFontList()
 {
     if (mDefaultFont) {
         ::CFRelease(mDefaultFont);
     }
 }
 
+void
+gfxMacPlatformFontList::AddFamily(CFStringRef aFamily)
+{
+    NSString* family = (NSString*)aFamily;
+
+    // CTFontManager includes weird internal family names and
+    // LastResort, skip over those
+    if (!family || [family caseInsensitiveCompare:@"LastResort"] == NSOrderedSame) {
+        return;
+    }
+
+    bool hiddenSystemFont = [family hasPrefix:@"."];
+
+    FontFamilyTable& table =
+        hiddenSystemFont ? mSystemFontFamilies : mFontFamilies;
+
+    nsAutoString familyName;
+    nsCocoaUtils::GetStringForNSString(family, familyName);
+
+    nsAutoString key;
+    ToLowerCase(familyName, key);
+
+    gfxFontFamily* familyEntry = new gfxMacFontFamily(familyName);
+    table.Put(key, familyEntry);
+
+    // check the bad underline blacklist
+    if (mBadUnderlineFamilyNames.Contains(key)) {
+        familyEntry->SetBadUnderlineFamily();
+    }
+}
+
 nsresult
 gfxMacPlatformFontList::InitFontList()
 {
     nsAutoreleasePool localPool;
 
     Telemetry::AutoTimer<Telemetry::MAC_INITFONTLIST_TOTAL> timer;
 
     // reset font lists
     gfxPlatformFontList::InitFontList();
     mSystemFontFamilies.Clear();
     
     // iterate over available families
 
     CFArrayRef familyNames = CTFontManagerCopyAvailableFontFamilyNames();
 
-    // iterate over families
-    uint32_t i, numFamilies;
-
-    numFamilies = CFArrayGetCount(familyNames);
-    for (i = 0; i < numFamilies; i++) {
-        CFStringRef family = (CFStringRef)CFArrayGetValueAtIndex(familyNames, i);
-
-        // CTFontManager includes weird internal family names and
-        // LastResort, skip over those
-        if (!family ||
-            CFStringCompare(family, CFSTR("LastResort"),
-                            kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
-            continue;
-        }
-
-        bool hiddenSystemFont = false;
-        if (::CFStringHasPrefix(family, CFSTR("."))) {
-            hiddenSystemFont = true;
-        }
-
-        nsAutoTArray<UniChar, 1024> buffer;
-        CFIndex len = ::CFStringGetLength(family);
-        buffer.SetLength(len+1);
-        ::CFStringGetCharacters(family, ::CFRangeMake(0, len),
-                                buffer.Elements());
-        buffer[len] = 0;
-        nsAutoString familyName(reinterpret_cast<char16_t*>(buffer.Elements()), len);
-
-        // create a family entry
-        gfxFontFamily *familyEntry = new gfxMacFontFamily(familyName);
-        if (!familyEntry) break;
-
-        // add the family entry to the hash table
-        ToLowerCase(familyName);
-        if (!hiddenSystemFont) {
-            mFontFamilies.Put(familyName, familyEntry);
-        } else {
-            mSystemFontFamilies.Put(familyName, familyEntry);
-        }
-
-        // check the bad underline blacklist
-        if (mBadUnderlineFamilyNames.Contains(familyName))
-            familyEntry->SetBadUnderlineFamily();
+    for (NSString* familyName in (NSArray*)familyNames) {
+        AddFamily((CFStringRef)familyName);
     }
 
     CFRelease(familyNames);
 
     InitSingleFaceList();
 
     // 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