From 14ad02c6931d7a46585e118f25e491c392a84947 Mon Sep 17 00:00:00 2001 From: John Daggett Date: Tue, 12 May 2015 17:44:13 +0900 Subject: [PATCH] Bug 1056479 p1a - use lang as part of pref font fallback. r=karlt --- gfx/thebes/gfxPlatform.cpp | 46 ++++++++++++++++++++++++++++++++++++++ gfx/thebes/gfxPlatform.h | 3 +++ gfx/thebes/gfxTextRun.cpp | 5 ++++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index fbed4f16562..554b4d2c3c7 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -382,6 +382,39 @@ static const char *gPrefLangNames[] = { "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) @@ -1474,6 +1507,19 @@ gfxPlatform::GetFontPrefLangFor(nsIAtom *aLang) 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) { diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index 5068999b188..6e262c9f62c 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -470,6 +470,9 @@ public: // 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); diff --git a/gfx/thebes/gfxTextRun.cpp b/gfx/thebes/gfxTextRun.cpp index 48c5510466c..62ffa1d58d9 100644 --- a/gfx/thebes/gfxTextRun.cpp +++ b/gfx/thebes/gfxTextRun.cpp @@ -3082,7 +3082,10 @@ struct PrefFontCallbackData { { PrefFontCallbackData *prefFontData = static_cast(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); }