Bug 1789197: [MathMLTextRunFactory] Do not reset font-weight/font-style when mathvariant is specified. r=emilio

This is a follow-up of 1788645, removing the font weight/style reset in
MathMLTextRunFactory when the mathvariant transform is not none. A WPT
test for mathvariant="double-struck" is added to exercise this case.

Differential Revision: https://phabricator.services.mozilla.com/D156400
This commit is contained in:
Frederic Wang 2022-09-05 08:47:07 +00:00
Родитель ba097d11d7
Коммит 6ed0e8a19f
3 изменённых файлов: 66 добавлений и 15 удалений

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

@ -598,21 +598,17 @@ void MathMLTextRunFactory::RebuildTextRun(
RefPtr<gfxTextRun> cachedChild;
gfxTextRun* child;
if (mathVar == StyleMathVariant::Bold && doMathvariantStyling) {
font.style = FontSlantStyle::NORMAL;
font.weight = FontWeight::BOLD;
} else if (mathVar == StyleMathVariant::Italic && doMathvariantStyling) {
font.style = FontSlantStyle::ITALIC;
font.weight = FontWeight::NORMAL;
} else if (mathVar == StyleMathVariant::BoldItalic && doMathvariantStyling) {
font.style = FontSlantStyle::ITALIC;
font.weight = FontWeight::BOLD;
} else if (mathVar != StyleMathVariant::None) {
// Mathvariant overrides fontstyle and fontweight
// Need to check to see if mathvariant is actually applied as this function
// is used for other purposes.
font.style = FontSlantStyle::NORMAL;
font.weight = FontWeight::NORMAL;
if (doMathvariantStyling) {
if (mathVar == StyleMathVariant::Bold) {
font.style = FontSlantStyle::NORMAL;
font.weight = FontWeight::BOLD;
} else if (mathVar == StyleMathVariant::Italic) {
font.style = FontSlantStyle::ITALIC;
font.weight = FontWeight::NORMAL;
} else if (mathVar == StyleMathVariant::BoldItalic) {
font.style = FontSlantStyle::ITALIC;
font.weight = FontWeight::BOLD;
}
}
gfxFontGroup* newFontGroup = nullptr;

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

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>mathvariant="double-struck" and font-style/font-weight (reference)</title>
<style>
@font-face {
font-family: TestFont;
src: url("/fonts/math/mathvariant-double-struck.woff");
}
.testfont {
font-family: TestFont;
font-size: 32px;
}
.italic { font-style: italic; }
.bold { font-weight: bold; }
</style>
</head>
<body>
<p>Test passes if you see three lines with text <span class="testfont">&#x1EEA1;</span> respectively rendered with italic, bold and bold-italic style:</p>
<p><math class="testfont"><mtext class="italic">&#x1EEA1;</mtext></math></p>
<p><math class="testfont"><mtext class="bold">&#x1EEA1;</mtext></math></p>
<p><math class="testfont"><mtext class="bold italic">&#x1EEA1;</mtext></math></p>
</body>
</html>

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

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>mathvariant="double-struck" and font-style/font-weight</title>
<link rel="help" href="https://w3c.github.io/mathml-core/#css-styling">
<link rel="help" href="https://w3c.github.io/mathml-core/#the-mathvariant-attribute">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1789081">
<link rel="match" href="mathvariant-double-struck-font-style-font-weight-ref.html"/>
<meta name="assert" content="Verify that mathvariant='double-struck' don't reset the font-style/font-weight properties.">
<style>
@font-face {
font-family: TestFont;
src: url("/fonts/math/mathvariant-double-struck.woff");
}
.testfont {
font-family: TestFont;
font-size: 32px;
}
.italic { font-style: italic; }
.bold { font-weight: bold; }
</style>
</head>
<body>
<p>Test passes if you see three lines with text <span class="testfont">&#x1EEA1;</span> respectively rendered with italic, bold and bold-italic style:</p>
<p><math class="testfont"><mtext mathvariant="double-struck" class="italic">&#x628;</mtext></math></p>
<p><math class="testfont"><mtext mathvariant="double-struck" class="bold">&#x628;</mtext></math></p>
<p><math class="testfont"><mtext mathvariant="double-struck" class="bold italic">&#x628;</mtext></math></p>
</body>
</html>