зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1352977 - Factor out helpers to construct the names for generic- and language-dependent font/font-list preferences. r=masayuki
This commit is contained in:
Родитель
6f0d451756
Коммит
21b1570eb8
|
@ -1627,9 +1627,6 @@ gfxFcPlatformFontList::GetStandardFamilyName(const nsAString& aFontName,
|
|||
return true;
|
||||
}
|
||||
|
||||
static const char kFontNamePrefix[] = "font.name.";
|
||||
static const char kFontNameListPrefix[] = "font.name-list.";
|
||||
|
||||
void
|
||||
gfxFcPlatformFontList::AddGenericFonts(mozilla::FontFamilyType aGenericType,
|
||||
nsIAtom* aLanguage,
|
||||
|
@ -1655,25 +1652,15 @@ gfxFcPlatformFontList::AddGenericFonts(mozilla::FontFamilyType aGenericType,
|
|||
if ((!mAlwaysUseFontconfigGenerics && aLanguage) ||
|
||||
aLanguage == nsGkAtoms::x_math) {
|
||||
nsIAtom* langGroup = GetLangGroup(aLanguage);
|
||||
nsAutoCString langGroupStr;
|
||||
if (langGroup) {
|
||||
langGroup->ToUTF8String(langGroupStr);
|
||||
}
|
||||
nsAutoCString prefFontName(kFontNamePrefix);
|
||||
prefFontName.Append(generic);
|
||||
prefFontName.Append('.');
|
||||
prefFontName.Append(langGroupStr);
|
||||
nsAdoptingString fontlistValue = Preferences::GetString(prefFontName.get());
|
||||
nsAdoptingString fontlistValue =
|
||||
Preferences::GetString(NamePref(generic, langGroup).get());
|
||||
if (fontlistValue.IsEmpty()) {
|
||||
nsAutoCString prefFontNameListName(kFontNameListPrefix);
|
||||
prefFontNameListName.Append(generic);
|
||||
prefFontNameListName.Append('.');
|
||||
prefFontNameListName.Append(langGroupStr);
|
||||
// The font name list may have two or more family names as comma
|
||||
// separated list. In such case, not matching with generic font
|
||||
// name is fine because if the list prefers specific font, we
|
||||
// should try to use the pref with complicated path.
|
||||
fontlistValue = Preferences::GetString(prefFontNameListName.get());
|
||||
fontlistValue =
|
||||
Preferences::GetString(NameListPref(generic, langGroup).get());
|
||||
}
|
||||
if (fontlistValue) {
|
||||
if (!fontlistValue.EqualsLiteral("serif") &&
|
||||
|
@ -1840,6 +1827,8 @@ gfxFcPlatformFontList::FindGenericFamilies(const nsAString& aGeneric,
|
|||
bool
|
||||
gfxFcPlatformFontList::PrefFontListsUseOnlyGenerics()
|
||||
{
|
||||
static const char kFontNamePrefix[] = "font.name.";
|
||||
|
||||
bool prefFontsUseOnlyGenerics = true;
|
||||
uint32_t count;
|
||||
char** names;
|
||||
|
@ -1865,15 +1854,13 @@ gfxFcPlatformFontList::PrefFontListsUseOnlyGenerics()
|
|||
const nsDependentCSubstring& langGroup = tokenizer.nextToken();
|
||||
nsAdoptingCString fontPrefValue = Preferences::GetCString(names[i]);
|
||||
if (fontPrefValue.IsEmpty()) {
|
||||
nsAutoCString nameListPrefName(kFontNameListPrefix);
|
||||
nameListPrefName.Append(generic);
|
||||
nameListPrefName.Append('.');
|
||||
nameListPrefName.Append(langGroup);
|
||||
// The font name list may have two or more family names as comma
|
||||
// separated list. In such case, not matching with generic font
|
||||
// name is fine because if the list prefers specific font, this
|
||||
// should return false.
|
||||
fontPrefValue = Preferences::GetCString(nameListPrefName.get());
|
||||
fontPrefValue =
|
||||
Preferences::GetCString(NameListPref(generic,
|
||||
langGroup).get());
|
||||
}
|
||||
|
||||
if (!langGroup.EqualsLiteral("x-math") &&
|
||||
|
|
|
@ -803,11 +803,8 @@ gfxPlatformFontList::GetDefaultFontFamily(const nsACString& aLangGroup,
|
|||
}
|
||||
|
||||
AutoTArray<nsString,4> names;
|
||||
nsAutoCString prefName("font.name-list.");
|
||||
prefName.Append(aGenericFamily);
|
||||
prefName.Append('.');
|
||||
prefName.Append(aLangGroup);
|
||||
gfxFontUtils::AppendPrefsFontList(prefName.get(), names);
|
||||
gfxFontUtils::AppendPrefsFontList(
|
||||
NameListPref(aGenericFamily, aLangGroup).get(), names);
|
||||
|
||||
for (nsString& name : names) {
|
||||
gfxFontFamily* fontFamily = FindFamily(name);
|
||||
|
@ -869,18 +866,12 @@ gfxPlatformFontList::ResolveGenericFontNames(
|
|||
AutoTArray<nsString,4> genericFamilies;
|
||||
|
||||
// load family for "font.name.generic.lang"
|
||||
nsAutoCString prefFontName("font.name.");
|
||||
prefFontName.Append(generic);
|
||||
prefFontName.Append('.');
|
||||
prefFontName.Append(langGroupStr);
|
||||
gfxFontUtils::AppendPrefsFontList(prefFontName.get(), genericFamilies);
|
||||
gfxFontUtils::AppendPrefsFontList(
|
||||
NamePref(generic, langGroupStr).get(), genericFamilies);
|
||||
|
||||
// load fonts for "font.name-list.generic.lang"
|
||||
nsAutoCString prefFontListName("font.name-list.");
|
||||
prefFontListName.Append(generic);
|
||||
prefFontListName.Append('.');
|
||||
prefFontListName.Append(langGroupStr);
|
||||
gfxFontUtils::AppendPrefsFontList(prefFontListName.get(), genericFamilies);
|
||||
gfxFontUtils::AppendPrefsFontList(
|
||||
NameListPref(generic, langGroupStr).get(), genericFamilies);
|
||||
|
||||
nsIAtom* langGroup = GetLangGroupForPrefLang(aPrefLang);
|
||||
NS_ASSERTION(langGroup, "null lang group for pref lang");
|
||||
|
|
|
@ -273,6 +273,47 @@ protected:
|
|||
NS_DECL_NSIMEMORYREPORTER
|
||||
};
|
||||
|
||||
template<bool ForNameList>
|
||||
class PrefNameMaker final : public nsAutoCString
|
||||
{
|
||||
void Init(const nsACString& aGeneric, const nsACString& aLangGroup)
|
||||
{
|
||||
Assign(ForNameList ? NS_LITERAL_CSTRING("font.name-list.")
|
||||
: NS_LITERAL_CSTRING("font.name."));
|
||||
Append(aGeneric);
|
||||
if (!aLangGroup.IsEmpty()) {
|
||||
Append('.');
|
||||
Append(aLangGroup);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
PrefNameMaker(const nsACString& aGeneric,
|
||||
const nsACString& aLangGroup)
|
||||
{
|
||||
Init(aGeneric, aLangGroup);
|
||||
}
|
||||
|
||||
PrefNameMaker(const char* aGeneric,
|
||||
const char* aLangGroup)
|
||||
{
|
||||
Init(nsDependentCString(aGeneric), nsDependentCString(aLangGroup));
|
||||
}
|
||||
|
||||
PrefNameMaker(const char* aGeneric,
|
||||
nsIAtom* aLangGroup)
|
||||
{
|
||||
if (aLangGroup) {
|
||||
Init(nsDependentCString(aGeneric), nsAtomCString(aLangGroup));
|
||||
} else {
|
||||
Init(nsDependentCString(aGeneric), nsAutoCString());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
typedef PrefNameMaker<false> NamePref;
|
||||
typedef PrefNameMaker<true> NameListPref;
|
||||
|
||||
explicit gfxPlatformFontList(bool aNeedFullnamePostscriptNames = true);
|
||||
|
||||
static gfxPlatformFontList *sPlatformFontList;
|
||||
|
|
Загрузка…
Ссылка в новой задаче