Bug 1687426 - If a CSS generic font-family name is present, use this to determine which font prefs to look at during fallback. r=emk

Differential Revision: https://phabricator.services.mozilla.com/D103598
This commit is contained in:
Jonathan Kew 2021-01-31 22:27:45 +00:00
Родитель b274d0d387
Коммит 0b9ef71f7f
6 изменённых файлов: 46 добавлений и 4 удалений

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

@ -1784,7 +1784,8 @@ void gfxPlatformFontList::GetFontFamiliesFromGenericFamilies(
gfxPlatformFontList::PrefFontList* gfxPlatformFontList::GetPrefFontsLangGroup(
StyleGenericFontFamily aGenericType, eFontPrefLang aPrefLang) {
if (aGenericType == StyleGenericFontFamily::MozEmoji) {
if (aGenericType == StyleGenericFontFamily::MozEmoji ||
aPrefLang == eFontPrefLang_Emoji) {
// Emoji font has no lang
PrefFontList* prefFonts = mEmojiPrefFont.get();
if (MOZ_UNLIKELY(!prefFonts)) {

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

@ -1872,6 +1872,9 @@ void gfxFontGroup::BuildFontList() {
MOZ_ASSERT_UNREACHABLE("broken FontFamilyName, no atom!");
}
} else {
if (mFirstGeneric == StyleGenericFontFamily::None) {
mFirstGeneric = name.mGeneric;
}
pfl->AddGenericFonts(name.mGeneric, mLanguage, fonts);
if (mTextPerf) {
mTextPerf->current.genericLookups++;
@ -3672,9 +3675,15 @@ gfxFont* gfxFontGroup::WhichPrefFontSupportsChar(
for (i = 0; i < numLangs; i++) {
eFontPrefLang currentLang = prefLangs[i];
StyleGenericFontFamily defaultGeneric = pfl->GetDefaultGeneric(currentLang);
gfxPlatformFontList::PrefFontList* families =
pfl->GetPrefFontsLangGroup(defaultGeneric, currentLang);
gfxPlatformFontList::PrefFontList* families = nullptr;
if (mFirstGeneric != StyleGenericFontFamily::None) {
families = pfl->GetPrefFontsLangGroup(mFirstGeneric, currentLang);
}
if (!families) {
StyleGenericFontFamily defaultGeneric =
pfl->GetDefaultGeneric(currentLang);
families = pfl->GetPrefFontsLangGroup(defaultGeneric, currentLang);
}
NS_ASSERTION(families, "no pref font families found");
// find the first pref font that includes the character

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

@ -1412,6 +1412,11 @@ class gfxFontGroup final : public gfxTextRunFactory {
bool mExplicitLanguage; // Does mLanguage come from an explicit attribute?
// First CSS generic in the list, if any (used to select among font prefs
// during fallback)
mozilla::StyleGenericFontFamily mFirstGeneric =
mozilla::StyleGenericFontFamily::None;
uint32_t mFontListGeneration = 0; // platform font list generation for this
// fontgroup

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

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8">
<style>
.a { font: 32px serif; }
.b { font: 32px sans-serif; }
strut { font-size: 2em; }
</style>
<p>The first Chinese line should use the <tt>serif</tt> font setting from prefs;
the second should use the <tt>sans-serif</tt> font setting.</p>
<p class="a"><span lang="zh-CN">你好吗?</span><strut>&nbsp;</strut></p>
<p class="b"><span lang="zh-CN">你好吗?</span><strut>&nbsp;</strut></p>

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

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8">
<style>
.a { font: 32px serif; }
.b { font: 32px sans-serif; }
strut { font-size: 2em; } /* to force stable line height/baseline position */
</style>
<p>The first Chinese line should use the <tt>serif</tt> font setting from prefs;
the second should use the <tt>sans-serif</tt> font setting.</p>
<p class="a">你好吗?<strut>&nbsp;</strut></p>
<p class="b">你好吗?<strut>&nbsp;</strut></p>

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

@ -160,5 +160,8 @@ skip-if(!winWidget) == legacy-family-names-2.html legacy-family-names-2-ref.html
random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) == descriptor-ranges.html descriptor-ranges-ref.html # Bug 1392106
# Test that prefs font fallback respects the CSS generic from content (bug 1687426)
== fallback-respects-generic-1.html fallback-respects-generic-1-ref.html
# Reset default prefs.
defaults