зеркало из https://github.com/mozilla/pjs.git
bug 388706. cache resolved fonts per language group. r=elif
This commit is contained in:
Родитель
e223940147
Коммит
6a141a8ebd
|
@ -84,6 +84,9 @@ public:
|
|||
/* Find a FontEntry object that represents a font on your system given a name */
|
||||
FontEntry *FindFontEntry(const nsAString& aName);
|
||||
|
||||
PRBool GetPrefFontEntries(const char *aLangGroup, nsTArray<nsRefPtr<FontEntry> > *array);
|
||||
void SetPrefFontEntries(const char *aLangGroup, nsTArray<nsRefPtr<FontEntry> >& array);
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
|
@ -109,10 +112,14 @@ private:
|
|||
|
||||
virtual cmsHPROFILE GetPlatformCMSOutputProfile();
|
||||
|
||||
static int PR_CALLBACK PrefChangedCallback(const char*, void*);
|
||||
|
||||
nsDataHashtable<nsStringHashKey, nsRefPtr<FontEntry> > mFonts;
|
||||
nsDataHashtable<nsStringHashKey, nsRefPtr<FontEntry> > mFontAliases;
|
||||
nsDataHashtable<nsStringHashKey, nsRefPtr<FontEntry> > mFontSubstitutes;
|
||||
nsStringArray mNonExistingFonts;
|
||||
|
||||
nsDataHashtable<nsCStringHashKey, nsTArray<nsRefPtr<FontEntry> > > mPrefFonts;
|
||||
};
|
||||
|
||||
#endif /* GFX_WINDOWS_PLATFORM_H */
|
||||
|
|
|
@ -1215,7 +1215,7 @@ public:
|
|||
if (langGroup) {
|
||||
PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s (%s)", langGroup, gScriptToText[primaryId].value));
|
||||
|
||||
nsTArray<nsRefPtr<FontEntry> > fonts;
|
||||
nsAutoTArray<nsRefPtr<FontEntry>, 5> fonts;
|
||||
this->GetPrefFonts(langGroup, fonts);
|
||||
selectedFont = WhichFontSupportsChar(fonts, ch);
|
||||
}
|
||||
|
@ -1227,7 +1227,7 @@ public:
|
|||
if (PR_LOG_TEST(gFontLog, PR_LOG_DEBUG))
|
||||
PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: CJK"));
|
||||
|
||||
nsTArray<nsRefPtr<FontEntry> > fonts;
|
||||
nsAutoTArray<nsRefPtr<FontEntry>, 15> fonts;
|
||||
this->GetCJKPrefFonts(fonts);
|
||||
selectedFont = WhichFontSupportsChar(fonts, ch);
|
||||
} else {
|
||||
|
@ -1235,7 +1235,7 @@ public:
|
|||
if (langGroup) {
|
||||
PR_LOG(gFontLog, PR_LOG_DEBUG, (" - Trying to find fonts for: %s", langGroup));
|
||||
|
||||
nsTArray<nsRefPtr<FontEntry> > fonts;
|
||||
nsAutoTArray<nsRefPtr<FontEntry>, 5> fonts;
|
||||
this->GetPrefFonts(langGroup, fonts);
|
||||
selectedFont = WhichFontSupportsChar(fonts, ch);
|
||||
}
|
||||
|
@ -1346,13 +1346,19 @@ private:
|
|||
|
||||
void GetPrefFonts(const char *aLangGroup, nsTArray<nsRefPtr<FontEntry> >& array) {
|
||||
NS_ASSERTION(aLangGroup, "aLangGroup is null");
|
||||
gfxPlatform *platform = gfxPlatform::GetPlatform();
|
||||
nsString fonts;
|
||||
platform->GetPrefFonts(aLangGroup, fonts);
|
||||
if (fonts.IsEmpty())
|
||||
return;
|
||||
gfxFontGroup::ForEachFont(fonts, nsDependentCString(aLangGroup),
|
||||
AddFontEntryToArray, &array);
|
||||
gfxWindowsPlatform *platform = gfxWindowsPlatform::GetPlatform();
|
||||
nsAutoTArray<nsRefPtr<FontEntry>, 5> fonts;
|
||||
if (!platform->GetPrefFontEntries(aLangGroup, &fonts)) {
|
||||
nsString fontString;
|
||||
platform->GetPrefFonts(aLangGroup, fontString);
|
||||
if (fontString.IsEmpty())
|
||||
return;
|
||||
gfxFontGroup::ForEachFont(fontString, nsDependentCString(aLangGroup),
|
||||
AddFontEntryToArray, &fonts);
|
||||
|
||||
platform->SetPrefFontEntries(aLangGroup, fonts);
|
||||
}
|
||||
array.AppendElements(fonts);
|
||||
}
|
||||
|
||||
void GetCJKPrefFonts(nsTArray<nsRefPtr<FontEntry> >& array) {
|
||||
|
|
|
@ -67,13 +67,27 @@
|
|||
*/
|
||||
//#define UPDATE_RANGES
|
||||
|
||||
int PR_CALLBACK
|
||||
gfxWindowsPlatform::PrefChangedCallback(const char *aPrefName, void *closure)
|
||||
{
|
||||
gfxWindowsPlatform *plat = static_cast<gfxWindowsPlatform *>(closure);
|
||||
plat->mPrefFonts.Clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
gfxWindowsPlatform::gfxWindowsPlatform()
|
||||
{
|
||||
mFonts.Init(200);
|
||||
mFontAliases.Init(20);
|
||||
mFontSubstitutes.Init(50);
|
||||
mPrefFonts.Init(10);
|
||||
|
||||
UpdateFontList();
|
||||
|
||||
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
|
||||
pref->RegisterCallback("font.", PrefChangedCallback, this);
|
||||
pref->RegisterCallback("font.name-list.", PrefChangedCallback, this);
|
||||
// don't bother unregistering. We'll get shutdown after the pref service
|
||||
}
|
||||
|
||||
gfxWindowsPlatform::~gfxWindowsPlatform()
|
||||
|
@ -485,6 +499,7 @@ gfxWindowsPlatform::UpdateFontList()
|
|||
mFontAliases.Clear();
|
||||
mNonExistingFonts.Clear();
|
||||
mFontSubstitutes.Clear();
|
||||
mPrefFonts.Clear();
|
||||
|
||||
LOGFONTW logFont;
|
||||
logFont.lfCharSet = DEFAULT_CHARSET;
|
||||
|
@ -765,3 +780,17 @@ gfxWindowsPlatform::GetPlatformCMSOutputProfile()
|
|||
#endif
|
||||
return profile;
|
||||
}
|
||||
|
||||
PRBool
|
||||
gfxWindowsPlatform::GetPrefFontEntries(const char *aLangGroup, nsTArray<nsRefPtr<FontEntry> > *array)
|
||||
{
|
||||
nsCAutoString keyName(aLangGroup);
|
||||
return mPrefFonts.Get(keyName, array);
|
||||
}
|
||||
|
||||
void
|
||||
gfxWindowsPlatform::SetPrefFontEntries(const char *aLangGroup, nsTArray<nsRefPtr<FontEntry> >& array)
|
||||
{
|
||||
nsCAutoString keyName(aLangGroup);
|
||||
mPrefFonts.Put(keyName, array);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче