bug 393632. cache cjk resolved font list as well. r=elif

This commit is contained in:
pavlov@pavlov.net 2007-08-24 17:00:41 -07:00
Родитель 7d8fc083f7
Коммит 5b9e4642e7
2 изменённых файлов: 57 добавлений и 49 удалений

Просмотреть файл

@ -1344,6 +1344,7 @@ private:
return -1;
}
// this function appends to the array passed in.
void GetPrefFonts(const char *aLangGroup, nsTArray<nsRefPtr<FontEntry> >& 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<nsRefPtr<FontEntry> >& array) {
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs)
return;
gfxWindowsPlatform *platform = gfxWindowsPlatform::GetPlatform();
if (!platform->GetPrefFontEntries("x-internal-cjk", &array)) {
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefs)
return;
nsCOMPtr<nsIPrefBranch> prefBranch;
prefs->GetBranch(0, getter_AddRefs(prefBranch));
if (!prefBranch)
return;
nsCOMPtr<nsIPrefBranch> 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<gfxWindowsFont> > mFonts;
nsRefPtr<gfxWindowsFont> mCurrentFont;
PRPackedBool mFontSelected;

Просмотреть файл

@ -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<gfxWindowsPlatform *>(closure);
plat->mPrefFonts.Clear();
return 0;
@ -87,6 +89,7 @@ gfxWindowsPlatform::gfxWindowsPlatform()
nsCOMPtr<nsIPref> 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
}