mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 12:55:46 +00:00
Bug 602792. Rework code for doing localized font family name lookups. r=jkew, a=blocker
This commit is contained in:
parent
324dd7dfc7
commit
0471ac96b4
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user