Bug 1182361 p1 - move old generic lookup methods into gfxPangoFontGroup. r=heycam

This commit is contained in:
John Daggett 2015-09-29 10:51:28 +09:00
Родитель 9396c59cd0
Коммит c84b59dee7
4 изменённых файлов: 170 добавлений и 25 удалений

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

@ -25,6 +25,9 @@
#include "gfxFontconfigUtils.h"
#include "gfxUserFontSet.h"
#include "gfxFontConstants.h"
#include "nsGkAtoms.h"
#include "nsILanguageAtomService.h"
#include "nsServiceManagerUtils.h"
#include <cairo.h>
#include <cairo-ft.h>
@ -1281,9 +1284,140 @@ gfxPangoFontGroup::Copy(const gfxFontStyle *aStyle)
}
void
gfxPangoFontGroup::FindPlatformFont(const nsAString& fontName,
bool aUseFontSet,
void *aClosure)
gfxPangoFontGroup::FindGenericFontsPFG(FontFamilyType aGenericType,
nsIAtom *aLanguage,
void *aClosure)
{
nsAutoTArray<nsString, 5> resolvedGenerics;
ResolveGenericFontNamesPFG(aGenericType, aLanguage, resolvedGenerics);
uint32_t g = 0, numGenerics = resolvedGenerics.Length();
for (g = 0; g < numGenerics; g++) {
FindPlatformFontPFG(resolvedGenerics[g], false, aClosure);
}
}
/* static */ void
gfxPangoFontGroup::ResolveGenericFontNamesPFG(FontFamilyType aGenericType,
nsIAtom *aLanguage,
nsTArray<nsString>& aGenericFamilies)
{
static const char kGeneric_serif[] = "serif";
static const char kGeneric_sans_serif[] = "sans-serif";
static const char kGeneric_monospace[] = "monospace";
static const char kGeneric_cursive[] = "cursive";
static const char kGeneric_fantasy[] = "fantasy";
// treat -moz-fixed as monospace
if (aGenericType == eFamily_moz_fixed) {
aGenericType = eFamily_monospace;
}
// type should be standard generic type at this point
NS_ASSERTION(aGenericType >= eFamily_serif &&
aGenericType <= eFamily_fantasy,
"standard generic font family type required");
// create the lang string
nsIAtom *langGroupAtom = nullptr;
nsAutoCString langGroupString;
if (aLanguage) {
if (!gLangService) {
CallGetService(NS_LANGUAGEATOMSERVICE_CONTRACTID, &gLangService);
}
if (gLangService) {
nsresult rv;
langGroupAtom = gLangService->GetLanguageGroup(aLanguage, &rv);
}
}
if (!langGroupAtom) {
langGroupAtom = nsGkAtoms::Unicode;
}
langGroupAtom->ToUTF8String(langGroupString);
// map generic type to string
const char *generic = nullptr;
switch (aGenericType) {
case eFamily_serif:
generic = kGeneric_serif;
break;
case eFamily_sans_serif:
generic = kGeneric_sans_serif;
break;
case eFamily_monospace:
generic = kGeneric_monospace;
break;
case eFamily_cursive:
generic = kGeneric_cursive;
break;
case eFamily_fantasy:
generic = kGeneric_fantasy;
break;
default:
break;
}
if (!generic) {
return;
}
aGenericFamilies.Clear();
// load family for "font.name.generic.lang"
nsAutoCString prefFontName("font.name.");
prefFontName.Append(generic);
prefFontName.Append('.');
prefFontName.Append(langGroupString);
gfxFontUtils::AppendPrefsFontList(prefFontName.get(),
aGenericFamilies);
// if lang has pref fonts, also load fonts for "font.name-list.generic.lang"
if (!aGenericFamilies.IsEmpty()) {
nsAutoCString prefFontListName("font.name-list.");
prefFontListName.Append(generic);
prefFontListName.Append('.');
prefFontListName.Append(langGroupString);
gfxFontUtils::AppendPrefsFontList(prefFontListName.get(),
aGenericFamilies);
}
#if 0 // dump out generic mappings
printf("%s ===> ", prefFontName.get());
for (uint32_t k = 0; k < aGenericFamilies.Length(); k++) {
if (k > 0) printf(", ");
printf("%s", NS_ConvertUTF16toUTF8(aGenericFamilies[k]).get());
}
printf("\n");
#endif
}
void gfxPangoFontGroup::EnumerateFontListPFG(nsIAtom *aLanguage, void *aClosure)
{
// initialize fonts in the font family list
const nsTArray<FontFamilyName>& fontlist = mFamilyList.GetFontlist();
// lookup fonts in the fontlist
uint32_t i, numFonts = fontlist.Length();
for (i = 0; i < numFonts; i++) {
const FontFamilyName& name = fontlist[i];
if (name.IsNamed()) {
FindPlatformFontPFG(name.mName, true, aClosure);
} else {
FindGenericFontsPFG(name.mType, aLanguage, aClosure);
}
}
// if necessary, append default generic onto the end
if (mFamilyList.GetDefaultFontType() != eFamily_none &&
!mFamilyList.HasDefaultGeneric()) {
FindGenericFontsPFG(mFamilyList.GetDefaultFontType(),
aLanguage, aClosure);
}
}
void
gfxPangoFontGroup::FindPlatformFontPFG(const nsAString& fontName,
bool aUseFontSet,
void *aClosure)
{
nsTArray<nsString> *list = static_cast<nsTArray<nsString>*>(aClosure);
@ -1360,8 +1494,8 @@ gfxPangoFontGroup::MakeFontSet(PangoLanguage *aLang, gfxFloat aSizeAdjustFactor,
}
nsAutoTArray<nsString, 20> fcFamilyList;
EnumerateFontList(langGroup ? langGroup.get() : mStyle.language.get(),
&fcFamilyList);
EnumerateFontListPFG(langGroup ? langGroup.get() : mStyle.language.get(),
&fcFamilyList);
// To consider: A fontset cache here could be helpful.

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

@ -94,9 +94,27 @@ private:
return mSizeAdjustFactor;
}
virtual void FindPlatformFont(const nsAString& aName,
bool aUseFontSet,
void *aClosure);
// old helper methods from gfxFontGroup, moved here so that those methods
// can be revamped without affecting the legacy code here
// iterate over the fontlist, lookup names and expand generics
void EnumerateFontListPFG(nsIAtom *aLanguage, void *aClosure);
// expand a generic to a list of specific names based on prefs
void FindGenericFontsPFG(mozilla::FontFamilyType aGenericType,
nsIAtom *aLanguage,
void *aClosure);
// lookup and add a font with a given name (i.e. *not* a generic!)
void FindPlatformFontPFG(const nsAString& aName,
bool aUseFontSet,
void *aClosure);
static void
ResolveGenericFontNamesPFG(mozilla::FontFamilyType aGenericType,
nsIAtom *aLanguage,
nsTArray<nsString>& aGenericFamilies);
friend class gfxSystemFcFontEntry;
static FT_Library GetFTLibrary();

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

@ -1559,14 +1559,13 @@ gfxFontGroup::~gfxFontGroup()
void
gfxFontGroup::FindGenericFonts(FontFamilyType aGenericType,
nsIAtom *aLanguage,
void *aClosure)
nsIAtom *aLanguage)
{
nsAutoTArray<nsString, 5> resolvedGenerics;
ResolveGenericFontNames(aGenericType, aLanguage, resolvedGenerics);
uint32_t g = 0, numGenerics = resolvedGenerics.Length();
for (g = 0; g < numGenerics; g++) {
FindPlatformFont(resolvedGenerics[g], false, aClosure);
FindPlatformFont(resolvedGenerics[g], false);
}
}
@ -1664,7 +1663,7 @@ gfxFontGroup::ResolveGenericFontNames(FontFamilyType aGenericType,
#endif
}
void gfxFontGroup::EnumerateFontList(nsIAtom *aLanguage, void *aClosure)
void gfxFontGroup::EnumerateFontList(nsIAtom *aLanguage)
{
// initialize fonts in the font family list
const nsTArray<FontFamilyName>& fontlist = mFamilyList.GetFontlist();
@ -1674,9 +1673,9 @@ void gfxFontGroup::EnumerateFontList(nsIAtom *aLanguage, void *aClosure)
for (i = 0; i < numFonts; i++) {
const FontFamilyName& name = fontlist[i];
if (name.IsNamed()) {
FindPlatformFont(name.mName, true, aClosure);
FindPlatformFont(name.mName, true);
} else {
FindGenericFonts(name.mType, aLanguage, aClosure);
FindGenericFonts(name.mType, aLanguage);
}
}
@ -1684,8 +1683,7 @@ void gfxFontGroup::EnumerateFontList(nsIAtom *aLanguage, void *aClosure)
if (mFamilyList.GetDefaultFontType() != eFamily_none &&
!mFamilyList.HasDefaultGeneric()) {
FindGenericFonts(mFamilyList.GetDefaultFontType(),
aLanguage,
aClosure);
aLanguage);
}
}
@ -1706,9 +1704,7 @@ gfxFontGroup::BuildFontList()
}
void
gfxFontGroup::FindPlatformFont(const nsAString& aName,
bool aUseFontSet,
void *aClosure)
gfxFontGroup::FindPlatformFont(const nsAString& aName, bool aUseFontSet)
{
bool needsBold;
gfxFontFamily *family = nullptr;

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

@ -1118,17 +1118,14 @@ protected:
// helper methods for looking up fonts
// iterate over the fontlist, lookup names and expand generics
void EnumerateFontList(nsIAtom *aLanguage, void *aClosure = nullptr);
void EnumerateFontList(nsIAtom *aLanguage);
// expand a generic to a list of specific names based on prefs
void FindGenericFonts(mozilla::FontFamilyType aGenericType,
nsIAtom *aLanguage,
void *aClosure);
nsIAtom *aLanguage);
// lookup and add a font with a given name (i.e. *not* a generic!)
virtual void FindPlatformFont(const nsAString& aName,
bool aUseFontSet,
void *aClosure);
void FindPlatformFont(const nsAString& aName, bool aUseFontSet);
static nsILanguageAtomService* gLangService;
};