Bug 1163491 - map local fontnames to fontconfig patterns. r=karlt
--- a/gfx/thebes/gfxFcPlatformFontList.cpp
+++ b/gfx/thebes/gfxFcPlatformFontList.cpp
@@ -817,40 +817,30 @@ gfxFontconfigFontEntry::CopyFontTable(ui
void
gfxFontconfigFontFamily::FindStyleVariations(FontInfoData *aFontInfoData)
{
if (mHasStyles) {
return;
}
// add font entries for each of the faces
- gfxPlatformFontList *fp = gfxPlatformFontList::PlatformFontList();
uint32_t numFonts = mFontPatterns.Length();
NS_ASSERTION(numFonts, "font family containing no faces!!");
for (uint32_t i = 0; i < numFonts; i++) {
FcPattern* face = mFontPatterns[i];
// figure out the psname/fullname and choose which to use as the facename
nsAutoString psname, fullname;
GetFaceNames(face, mName, psname, fullname);
const nsAutoString& faceName = !psname.IsEmpty() ? psname : fullname;
gfxFontconfigFontEntry *fontEntry =
new gfxFontconfigFontEntry(faceName, face);
AddFontEntry(fontEntry);
- // add entry to local name lists
- if (!psname.IsEmpty()) {
- fp->AddPostscriptName(fontEntry, psname);
- }
- NS_ASSERTION(!fullname.IsEmpty(), "empty font fullname");
- if (!fullname.IsEmpty()) {
- fp->AddFullname(fontEntry, fullname);
- }
-
if (LOG_FONTLIST_ENABLED()) {
LOG_FONTLIST(("(fontlist) added (%s) to family (%s)"
" with style: %s weight: %d stretch: %d"
" psname: %s fullname: %s",
NS_ConvertUTF16toUTF8(fontEntry->Name()).get(),
NS_ConvertUTF16toUTF8(Name()).get(),
fontEntry->IsItalic() ? "italic" : "normal",
fontEntry->Weight(), fontEntry->Stretch(),
@@ -1020,21 +1010,21 @@ gfxFcPlatformFontList::AddFontSetFamilie
static_cast<gfxFontconfigFontFamily*>(fontFamily);
fcFamily->AddFontPattern(font);
// map the psname, fullname ==> font family for local font lookups
nsAutoString psname, fullname;
GetFaceNames(font, familyName, psname, fullname);
if (!psname.IsEmpty()) {
ToLowerCase(psname);
- mLocalNames.Put(psname, fontFamily);
+ mLocalNames.Put(psname, font);
}
if (!fullname.IsEmpty()) {
ToLowerCase(fullname);
- mLocalNames.Put(fullname, fontFamily);
+ mLocalNames.Put(fullname, font);
}
}
}
nsresult
gfxFcPlatformFontList::InitFontList()
{
mLastConfig = FcConfigGetCurrent();
@@ -1159,47 +1149,27 @@ gfxFcPlatformFontList::GetDefaultFont(co
}
gfxFontEntry*
gfxFcPlatformFontList::LookupLocalFont(const nsAString& aFontName,
uint16_t aWeight,
int16_t aStretch,
bool aItalic)
{
- gfxFontEntry* lookup;
-
- // first, lookup in face name lists
- lookup = FindFaceName(aFontName);
- if (!lookup) {
- // if not found, check in global facename ==> family list
- nsAutoString keyName(aFontName);
- ToLowerCase(keyName);
- gfxFontFamily* fontFamily = mLocalNames.GetWeak(keyName);
+ nsAutoString keyName(aFontName);
+ ToLowerCase(keyName);
- // name is not in the global list, done
- if (!fontFamily) {
- return nullptr;
- }
-
- // name is in global list but family needs enumeration
- fontFamily->FindStyleVariations();
-
- // facename ==> font entry should now be in the list
- lookup = FindFaceName(aFontName);
- NS_ASSERTION(lookup, "facename to family mapping failure");
- if (!lookup) {
- return nullptr;
- }
+ // if name is not in the global list, done
+ FcPattern* fontPattern = mLocalNames.Get(keyName);
+ if (!fontPattern) {
+ return nullptr;
}
- gfxFontconfigFontEntry* fcFontEntry =
- static_cast<gfxFontconfigFontEntry*>(lookup);
-
- return new gfxFontconfigFontEntry(fcFontEntry->Name(),
- fcFontEntry->GetPattern(),
+ return new gfxFontconfigFontEntry(aFontName,
+ fontPattern,
aWeight, aStretch, aItalic);
}
gfxFontEntry*
gfxFcPlatformFontList::MakePlatformFont(const nsAString& aFontName,
uint16_t aWeight,
int16_t aStretch,
bool aItalic,
--- a/gfx/thebes/gfxFcPlatformFontList.h
+++ b/gfx/thebes/gfxFcPlatformFontList.h
@@ -244,17 +244,19 @@ protected:
#ifdef MOZ_BUNDLED_FONTS
void ActivateBundledFonts();
nsCString mBundledFontsPath;
bool mBundledFontsInitialized;
#endif
// to avoid enumerating all fonts, maintain a mapping of local font
// names to family
- nsRefPtrHashtable<nsStringHashKey, gfxFontFamily> mLocalNames;
+ nsBaseHashtable<nsStringHashKey,
+ nsCountedRef<FcPattern>,
+ FcPattern*> mLocalNames;
// caching generic/lang ==> font family
nsRefPtrHashtable<nsCStringHashKey, gfxFontFamily> mGenericMappings;
nsCOMPtr<nsITimer> mCheckFontUpdatesTimer;
nsCountedRef<FcConfig> mLastConfig;
static FT_Library sCairoFTLibrary;