diff --git a/gfx/thebes/src/gfxWindowsFonts.cpp b/gfx/thebes/src/gfxWindowsFonts.cpp index 4fff9fce212..6ae5cbe6888 100644 --- a/gfx/thebes/src/gfxWindowsFonts.cpp +++ b/gfx/thebes/src/gfxWindowsFonts.cpp @@ -1344,6 +1344,7 @@ private: return -1; } + // this function appends to the array passed in. void GetPrefFonts(const char *aLangGroup, nsTArray >& array) { NS_ASSERTION(aLangGroup, "aLangGroup is null"); gfxWindowsPlatform *platform = gfxWindowsPlatform::GetPlatform(); @@ -1361,58 +1362,64 @@ private: array.AppendElements(fonts); } + // this function assigns to the array passed in. void GetCJKPrefFonts(nsTArray >& array) { - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (!prefs) - return; + gfxWindowsPlatform *platform = gfxWindowsPlatform::GetPlatform(); + if (!platform->GetPrefFontEntries("x-internal-cjk", &array)) { + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (!prefs) + return; - nsCOMPtr prefBranch; - prefs->GetBranch(0, getter_AddRefs(prefBranch)); - if (!prefBranch) - return; + nsCOMPtr prefBranch; + prefs->GetBranch(0, getter_AddRefs(prefBranch)); + if (!prefBranch) + return; - // Add by the order of accept languages. - nsXPIDLCString list; - nsresult rv = prefBranch->GetCharPref("intl.accept_languages", getter_Copies(list)); - if (NS_SUCCEEDED(rv) && !list.IsEmpty()) { - const char kComma = ','; - const char *p, *p_end; - list.BeginReading(p); - list.EndReading(p_end); - while (p < p_end) { - while (nsCRT::IsAsciiSpace(*p)) { - if (++p == p_end) - break; - } - if (p == p_end) - break; - const char *start = p; - while (++p != p_end && *p != kComma) - /* nothing */ ; - nsCAutoString lang(Substring(start, p)); - lang.CompressWhitespace(PR_FALSE, PR_TRUE); - PRInt32 index = GetCJKLangGroupIndex(lang.get()); - if (index >= 0) - GetPrefFonts(sCJKLangGroup[index], array); - p++; - } - } + // Add by the order of accept languages. + nsXPIDLCString list; + nsresult rv = prefBranch->GetCharPref("intl.accept_languages", getter_Copies(list)); + if (NS_SUCCEEDED(rv) && !list.IsEmpty()) { + const char kComma = ','; + const char *p, *p_end; + list.BeginReading(p); + list.EndReading(p_end); + while (p < p_end) { + while (nsCRT::IsAsciiSpace(*p)) { + if (++p == p_end) + break; + } + if (p == p_end) + break; + const char *start = p; + while (++p != p_end && *p != kComma) + /* nothing */ ; + nsCAutoString lang(Substring(start, p)); + lang.CompressWhitespace(PR_FALSE, PR_TRUE); + PRInt32 index = GetCJKLangGroupIndex(lang.get()); + if (index >= 0) + GetPrefFonts(sCJKLangGroup[index], array); + p++; + } + } - // Add the system locale - switch (::GetACP()) { - case 932: GetPrefFonts(CJK_LANG_JA, array); break; - case 936: GetPrefFonts(CJK_LANG_ZH_CN, array); break; - case 949: GetPrefFonts(CJK_LANG_KO, array); break; - // XXX Don't we need to append CJK_LANG_ZH_HK if the codepage is 950? - case 950: GetPrefFonts(CJK_LANG_ZH_TW, array); break; - } + // Add the system locale + switch (::GetACP()) { + case 932: GetPrefFonts(CJK_LANG_JA, array); break; + case 936: GetPrefFonts(CJK_LANG_ZH_CN, array); break; + case 949: GetPrefFonts(CJK_LANG_KO, array); break; + // XXX Don't we need to append CJK_LANG_ZH_HK if the codepage is 950? + case 950: GetPrefFonts(CJK_LANG_ZH_TW, array); break; + } - // last resort... - GetPrefFonts(CJK_LANG_JA, array); - GetPrefFonts(CJK_LANG_KO, array); - GetPrefFonts(CJK_LANG_ZH_CN, array); - GetPrefFonts(CJK_LANG_ZH_HK, array); - GetPrefFonts(CJK_LANG_ZH_TW, array); + // last resort... + GetPrefFonts(CJK_LANG_JA, array); + GetPrefFonts(CJK_LANG_KO, array); + GetPrefFonts(CJK_LANG_ZH_CN, array); + GetPrefFonts(CJK_LANG_ZH_HK, array); + GetPrefFonts(CJK_LANG_ZH_TW, array); + + platform->SetPrefFontEntries("x-internal-cjk", array); + } } void GenerateAlternativeString() { @@ -1456,8 +1463,6 @@ private: GOFFSET *mOffsets; int *mAdvances; - nsTArray< nsRefPtr > mFonts; - nsRefPtr mCurrentFont; PRPackedBool mFontSelected; diff --git a/gfx/thebes/src/gfxWindowsPlatform.cpp b/gfx/thebes/src/gfxWindowsPlatform.cpp index e9e77e65860..1a683d5c340 100644 --- a/gfx/thebes/src/gfxWindowsPlatform.cpp +++ b/gfx/thebes/src/gfxWindowsPlatform.cpp @@ -70,6 +70,8 @@ int PR_CALLBACK gfxWindowsPlatform::PrefChangedCallback(const char *aPrefName, void *closure) { + // XXX this could be made to only clear out the cache for the prefs that were changed + // but it probably isn't that big a deal. gfxWindowsPlatform *plat = static_cast(closure); plat->mPrefFonts.Clear(); return 0; @@ -87,6 +89,7 @@ gfxWindowsPlatform::gfxWindowsPlatform() nsCOMPtr pref = do_GetService(NS_PREF_CONTRACTID); pref->RegisterCallback("font.", PrefChangedCallback, this); pref->RegisterCallback("font.name-list.", PrefChangedCallback, this); + pref->RegisterCallback("intl.accept_languages", PrefChangedCallback, this); // don't bother unregistering. We'll get shutdown after the pref service }