Bug 1056479 p1a - use lang as part of pref font fallback. r=karlt
☠☠ backed out by 6127b1d28cb5 ☠ ☠
authorJohn Daggett <jdaggett@mozilla.com>
Tue, 12 May 2015 14:51:17 +0900
changeset 243456 408e078cc18d02c55a2b0a0190ec8f60d6d4ba06
parent 243455 a651c240979dff66780875ad0752ec89c8d8312d
child 243457 130bea3f862320d01eea4b4b9f308133851f8eea
push id28738
push usercbook@mozilla.com
push dateTue, 12 May 2015 14:11:31 +0000
treeherdermozilla-central@bedce1b405a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1056479
milestone40.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 1056479 p1a - use lang as part of pref font fallback. r=karlt
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxTextRun.cpp
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -377,16 +377,49 @@ static const char *gPrefLangNames[] = {
     "x-orya",
     "x-telu",
     "x-knda",
     "x-sinh",
     "x-tibt",
     "x-unicode",
 };
 
+// this needs to match the list of pref font.default.xx entries listed in all.js!
+// the order *must* match the order in eFontPrefLang
+static nsIAtom* gPrefLangToLangGroups[] = {
+    nsGkAtoms::x_western,
+    nsGkAtoms::Japanese,
+    nsGkAtoms::Taiwanese,
+    nsGkAtoms::Chinese,
+    nsGkAtoms::HongKongChinese,
+    nsGkAtoms::ko,
+    nsGkAtoms::x_cyrillic,
+    nsGkAtoms::el,
+    nsGkAtoms::th,
+    nsGkAtoms::he,
+    nsGkAtoms::ar,
+    nsGkAtoms::x_devanagari,
+    nsGkAtoms::x_tamil,
+    nsGkAtoms::x_armn,
+    nsGkAtoms::x_beng,
+    nsGkAtoms::x_cans,
+    nsGkAtoms::x_ethi,
+    nsGkAtoms::x_geor,
+    nsGkAtoms::x_gujr,
+    nsGkAtoms::x_guru,
+    nsGkAtoms::x_khmr,
+    nsGkAtoms::x_mlym,
+    nsGkAtoms::x_orya,
+    nsGkAtoms::x_telu,
+    nsGkAtoms::x_knda,
+    nsGkAtoms::x_sinh,
+    nsGkAtoms::x_tibt,
+    nsGkAtoms::Unicode
+};
+
 gfxPlatform::gfxPlatform()
   : mTileWidth(-1)
   , mTileHeight(-1)
   , mAzureCanvasBackendCollector(this, &gfxPlatform::GetAzureBackendInfo)
   , mApzSupportCollector(this, &gfxPlatform::GetApzSupportInfo)
 {
     mAllowDownloadableFonts = UNINITIALIZED_VALUE;
     mFallbackUsesCmaps = UNINITIALIZED_VALUE;
@@ -1469,16 +1502,29 @@ gfxPlatform::GetFontPrefLangFor(nsIAtom 
 {
     if (!aLang)
         return eFontPrefLang_Others;
     nsAutoCString lang;
     aLang->ToUTF8String(lang);
     return GetFontPrefLangFor(lang.get());
 }
 
+nsIAtom*
+gfxPlatform::GetLangGroupForPrefLang(eFontPrefLang aLang)
+{
+    // the special CJK set pref lang should be resolved into separate
+    // calls to individual CJK pref langs before getting here
+    NS_ASSERTION(aLang != eFontPrefLang_CJKSet, "unresolved CJK set pref lang");
+
+    if (uint32_t(aLang) < ArrayLength(gPrefLangToLangGroups)) {
+        return gPrefLangToLangGroups[uint32_t(aLang)];
+    }
+    return nsGkAtoms::Unicode;
+}
+
 const char*
 gfxPlatform::GetPrefLangName(eFontPrefLang aLang)
 {
     if (uint32_t(aLang) < ArrayLength(gPrefLangNames)) {
         return gPrefLangNames[uint32_t(aLang)];
     }
     return nullptr;
 }
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -465,16 +465,19 @@ public:
                                   void *aClosure);
 
     // convert a lang group to enum constant (i.e. "zh-TW" ==> eFontPrefLang_ChineseTW)
     static eFontPrefLang GetFontPrefLangFor(const char* aLang);
 
     // convert a lang group atom to enum constant
     static eFontPrefLang GetFontPrefLangFor(nsIAtom *aLang);
 
+    // convert an enum constant to a lang group atom
+    static nsIAtom* GetLangGroupForPrefLang(eFontPrefLang aLang);
+
     // convert a enum constant to lang group string (i.e. eFontPrefLang_ChineseTW ==> "zh-TW")
     static const char* GetPrefLangName(eFontPrefLang aLang);
    
     // map a Unicode range (based on char code) to a font language for Preferences
     static eFontPrefLang GetFontPrefLangFor(uint8_t aUnicodeRange);
 
     // returns true if a pref lang is CJK
     static bool IsLangCJK(eFontPrefLang aLang);
--- a/gfx/thebes/gfxTextRun.cpp
+++ b/gfx/thebes/gfxTextRun.cpp
@@ -3077,17 +3077,20 @@ struct PrefFontCallbackData {
     {}
 
     nsTArray<nsRefPtr<gfxFontFamily> >& mPrefFamilies;
 
     static bool AddFontFamilyEntry(eFontPrefLang aLang, const nsAString& aName, void *aClosure)
     {
         PrefFontCallbackData *prefFontData = static_cast<PrefFontCallbackData*>(aClosure);
 
-        gfxFontFamily *family = gfxPlatformFontList::PlatformFontList()->FindFamily(aName);
+        // map pref lang to langGroup for language-sensitive lookups
+        nsIAtom* lang = gfxPlatform::GetLangGroupForPrefLang(aLang);
+        gfxFontFamily *family =
+            gfxPlatformFontList::PlatformFontList()->FindFamily(aName, lang);
         if (family) {
             prefFontData->mPrefFamilies.AppendElement(family);
         }
         return true;
     }
 };
 
 already_AddRefed<gfxFont>