From 96dd93d2a6488dd619becf67dac655db097c4e40 Mon Sep 17 00:00:00 2001 From: John Daggett Date: Wed, 27 May 2015 16:19:19 +0900 Subject: [PATCH] Bug 1163491 - map local fontnames to fontconfig patterns. r=karlt --- gfx/thebes/gfxFcPlatformFontList.cpp | 50 ++++++---------------------- gfx/thebes/gfxFcPlatformFontList.h | 4 ++- 2 files changed, 13 insertions(+), 41 deletions(-) diff --git a/gfx/thebes/gfxFcPlatformFontList.cpp b/gfx/thebes/gfxFcPlatformFontList.cpp index 6e9cf9b66d28..ffd8b077b12b 100644 --- a/gfx/thebes/gfxFcPlatformFontList.cpp +++ b/gfx/thebes/gfxFcPlatformFontList.cpp @@ -822,7 +822,6 @@ gfxFontconfigFontFamily::FindStyleVariations(FontInfoData *aFontInfoData) } // 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++) { @@ -837,15 +836,6 @@ gfxFontconfigFontFamily::FindStyleVariations(FontInfoData *aFontInfoData) 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" @@ -1025,11 +1015,11 @@ gfxFcPlatformFontList::AddFontSetFamilies(FcFontSet* aFontSet) 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); } } } @@ -1164,37 +1154,17 @@ gfxFcPlatformFontList::LookupLocalFont(const nsAString& aFontName, int16_t aStretch, bool aItalic) { - gfxFontEntry* lookup; + nsAutoString keyName(aFontName); + ToLowerCase(keyName); - // 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); - - // 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(lookup); - - return new gfxFontconfigFontEntry(fcFontEntry->Name(), - fcFontEntry->GetPattern(), + return new gfxFontconfigFontEntry(aFontName, + fontPattern, aWeight, aStretch, aItalic); } diff --git a/gfx/thebes/gfxFcPlatformFontList.h b/gfx/thebes/gfxFcPlatformFontList.h index c30a2f6c9a19..45ced3bf01d6 100644 --- a/gfx/thebes/gfxFcPlatformFontList.h +++ b/gfx/thebes/gfxFcPlatformFontList.h @@ -249,7 +249,9 @@ protected: // to avoid enumerating all fonts, maintain a mapping of local font // names to family - nsRefPtrHashtable mLocalNames; + nsBaseHashtable, + FcPattern*> mLocalNames; // caching generic/lang ==> font family nsRefPtrHashtable mGenericMappings;