Bug 602792. Rework code for doing localized font family name lookups. r=jkew, a=blocker

This commit is contained in:
John Daggett 2011-01-07 21:29:49 +09:00
Родитель 324dd7dfc7
Коммит 0471ac96b4
4 изменённых файлов: 80 добавлений и 16 удалений

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

@ -512,7 +512,7 @@ gfxDWriteFontList::InitFontList()
englishIdx = 0;
}
nsAutoTArray<WCHAR, 32> famName;
nsAutoTArray<WCHAR, 32> enName;
UINT32 length;
hr = names->GetStringLength(englishIdx, &length);
@ -520,30 +520,78 @@ gfxDWriteFontList::InitFontList()
continue;
}
if (!famName.SetLength(length + 1)) {
if (!enName.SetLength(length + 1)) {
// Eeep - running out of memory. Unlikely to end well.
continue;
}
hr = names->GetString(englishIdx, famName.Elements(), length + 1);
hr = names->GetString(englishIdx, enName.Elements(), length + 1);
if (FAILED(hr)) {
continue;
}
nsAutoString name(famName.Elements());
nsAutoString name(enName.Elements());
BuildKeyNameFromFontName(name);
if (!mFontFamilies.GetWeak(name)) {
nsRefPtr<gfxFontFamily> fam =
new gfxDWriteFontFamily(nsDependentString(famName.Elements()),
family);
if (mBadUnderlineFamilyNames.Contains(name)) {
fam->SetBadUnderlineFamily();
}
mFontFamilies.Put(name, fam);
nsRefPtr<gfxFontFamily> fam;
if (mFontFamilies.GetWeak(name)) {
continue;
}
nsDependentString familyName(enName.Elements());
fam = new gfxDWriteFontFamily(familyName, family);
if (!fam) {
continue;
}
if (mBadUnderlineFamilyNames.Contains(name)) {
fam->SetBadUnderlineFamily();
}
mFontFamilies.Put(name, fam);
// now add other family name localizations, if present
PRUint32 nameCount = names->GetCount();
PRUint32 nameIndex;
for (nameIndex = 0; nameIndex < nameCount; nameIndex++) {
UINT32 nameLen;
nsAutoTArray<WCHAR, 32> localizedName;
// only add other names
if (nameIndex == englishIdx) {
continue;
}
hr = names->GetStringLength(nameIndex, &nameLen);
if (FAILED(hr)) {
continue;
}
if (!localizedName.SetLength(nameLen + 1)) {
continue;
}
hr = names->GetString(nameIndex, localizedName.Elements(),
nameLen + 1);
if (FAILED(hr)) {
continue;
}
nsDependentString locName(localizedName.Elements());
if (!familyName.Equals(locName)) {
AddOtherFamilyName(fam, locName);
}
}
// at this point, all family names have been read in
fam->SetOtherFamilyNamesInitialized();
}
mOtherFamilyNamesInitialized = PR_TRUE;
GetFontSubstitutes();
StartLoader(kDelayBeforeLoadingFonts, kIntervalBetweenLoadingFonts);

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

@ -513,6 +513,11 @@ public:
// read in other family names, if any, and use functor to add each into cache
virtual void ReadOtherFamilyNames(gfxPlatformFontList *aPlatformFontList);
// set when other family names have been read in
void SetOtherFamilyNamesInitialized() {
mOtherFamilyNamesInitialized = PR_TRUE;
}
// read in other localized family names, fullnames and Postscript names
// for all faces and append to lookup tables
virtual void ReadFaceNames(gfxPlatformFontList *aPlatformFontList,

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

@ -690,6 +690,15 @@ gfxGDIFontList::EnumFontFamExProc(ENUMLOGFONTEXW *lpelfe,
nsDependentString faceName(lf.lfFaceName);
nsRefPtr<gfxFontFamily> family = new GDIFontFamily(faceName);
fontList->mFontFamilies.Put(name, family);
// if locale is such that CJK font names are the default coming from
// GDI, then if a family name is non-ASCII immediately read in other
// family names. This assures that MS Gothic, MS Mincho are all found
// before lookups begin.
if (!IsASCII(faceName)) {
family->ReadOtherFamilyNames(gfxPlatformFontList::PlatformFontList());
}
if (fontList->mBadUnderlineFamilyNames.Contains(name))
family->SetBadUnderlineFamily();
}

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

@ -418,16 +418,18 @@ gfxPlatformFontList::FindFamily(const nsAString& aFamily)
}
// lookup in other family names list (mostly localized names)
if ((familyEntry = mOtherFamilyNames.GetWeak(key, &found))) {
if ((familyEntry = mOtherFamilyNames.GetWeak(key, &found)) != nsnull) {
return familyEntry;
}
// name not found and other family names not yet fully initialized so
// initialize the rest of the list and try again. this is done lazily
// since reading name table entries is expensive
if (!mOtherFamilyNamesInitialized) {
// since reading name table entries is expensive.
// although ASCII localized family names are possible they don't occur
// in practice so avoid pulling in names at startup
if (!mOtherFamilyNamesInitialized && !IsASCII(aFamily)) {
InitOtherFamilyNames();
if ((familyEntry = mOtherFamilyNames.GetWeak(key, &found))) {
if ((familyEntry = mOtherFamilyNames.GetWeak(key, &found)) != nsnull) {
return familyEntry;
}
}