Bug 1789083 - Remove doMathvariantStyling fallback from MathMLTextRunFactory. r=emilio

In order to perform basic mathvariant transforms (italic, bold, and
bold-italic) on systems that don't provide the proper characters from
the Mathematical Alphanumeric Symbols block, a fallback using font
italic/bold style was implemented in Gecko. Nowadays, several fonts
provide glyphs for these characters and are pre-installed on Desktop:

- Cambria Math (pre-installed on Windows Vista and higher)
- STIX General (pre-installed from OS X Lion to macOS Monterey)
- STIX Two Math (pre-installed on macOS Ventura and higher)
- DejaVu (pre-installed on the most popular Linux distributions)

This commit put the fallback under a preference that is disabled by
default on Desktop. It is still required on Android because the
default fonts are not enough.

Differential Revision: https://phabricator.services.mozilla.com/D156396
This commit is contained in:
Frederic Wang 2022-09-07 12:24:55 +00:00
Родитель 54e3830cb2
Коммит bf1dfd8446
7 изменённых файлов: 109 добавлений и 4 удалений

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

@ -10,6 +10,7 @@
#include "mozilla/BinarySearch.h"
#include "mozilla/ComputedStyle.h"
#include "mozilla/ComputedStyleInlines.h"
#include "mozilla/StaticPrefs_mathml.h"
#include "mozilla/intl/UnicodeScriptCodes.h"
#include "nsStyleConsts.h"
@ -533,9 +534,10 @@ void MathMLTextRunFactory::RebuildTextRun(
}
uint32_t ch2 = MathVariant(ch, mathVar);
if (mathVar == StyleMathVariant::Bold ||
mathVar == StyleMathVariant::BoldItalic ||
mathVar == StyleMathVariant::Italic) {
if (!StaticPrefs::mathml_mathvariant_styling_fallback_disabled() &&
(mathVar == StyleMathVariant::Bold ||
mathVar == StyleMathVariant::BoldItalic ||
mathVar == StyleMathVariant::Italic)) {
if (ch == ch2 && ch != 0x20 && ch != 0xA0) {
// Don't apply the CSS style if a character cannot be
// transformed. There is an exception for whitespace as it is both
@ -598,7 +600,8 @@ void MathMLTextRunFactory::RebuildTextRun(
RefPtr<gfxTextRun> cachedChild;
gfxTextRun* child;
if (doMathvariantStyling) {
if (!StaticPrefs::mathml_mathvariant_styling_fallback_disabled() &&
doMathvariantStyling) {
if (mathVar == StyleMathVariant::Bold) {
font.style = FontSlantStyle::NORMAL;
font.weight = FontWeight::BOLD;

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

@ -8743,6 +8743,18 @@
#endif
mirror: always
# Whether to disable fallback for mathvariant=italic/bold/bold-italic via
# styling when lacking proper fonts for Mathematical Alphanumeric Symbols.
# We expect all OSes to have relevant fonts, except Android, see bug 1789083.
- name: mathml.mathvariant_styling_fallback.disabled
type: bool
#if defined(ANDROID)
value: false
#else
value: true
#endif
mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "media."
#---------------------------------------------------------------------------

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

@ -0,0 +1,3 @@
[mathvariant-basic-transforms-with-default-font.html]
expected:
if os == "android": FAIL

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

@ -0,0 +1,13 @@
[basic-mathematical-alphanumeric-symbols-with-default-font.html]
[Bold mathematical alphanumeric symbol with the default font]
expected:
if os == "android": FAIL
[Italic mathematical alphanumeric symbol with the default font]
expected:
if os == "android": FAIL
[Bold-italic mathematical alphanumeric symbol with the default font]
expected:
if os == "android": FAIL

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

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Basic mathvariant transforms with the default font (reference)</title>
</head>
<body>
<p>Test passes if you see three lines of text rendered with corresponding
italic, bold, bold-italic characters from the
Mathematical Alphanumeric Symbols block:</p>
<p><math><mtext>𝐼𝑡𝑎𝑙𝑖𝑐</mtext></math></p>
<p><math><mtext>𝐁𝐨𝐥𝐝</mtext></math></p>
<p><math><mtext>𝑩𝒐𝒍𝒅𝑰𝒕𝒂𝒍𝒊𝒄</mtext></math></p>
</body>
</html>

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

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Basic mathvariant transforms with the default font</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=1789083">
<link rel="match" href="mathvariant-basic-transforms-with-default-font-ref.html"/>
<meta name="assert" content="Verify that the default font provides Mathematical Alphanumeric Symbols to perform basic mathvariant transforms (italic, bold, bold-italic), without requiring some kind of style fallback.">
</head>
<body>
<p>Test passes if you see three lines of text rendered with corresponding
italic, bold, bold-italic characters from the
Mathematical Alphanumeric Symbols block:</p>
<p><math><mtext mathvariant="italic">Italic</mtext></math></p>
<p><math><mtext mathvariant="bold">Bold</mtext></math></p>
<p><math><mtext mathvariant="bold-italic">BoldItalic</mtext></math></p>
</body>
</html>

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

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Basic mathematical alphanumeric symbols with default font</title>
<meta name="assert" content="Verify whether the default font contains italic/bold/bold-italic characters from the Mathematical Alphanumeric Symbols block.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
span[data-name] {
font-size: 100px;
background: lightblue;
display: inline-block;
}
</style>
</head>
<body>
<div id="log"></div>
<p><span id="frakturL" data-name="U+1D529 MATHEMATICAL FRAKTUR SMALL L">𝔩</span></p>
<p><span id="emSpace" data-name="U+2003 EM SPACE">&#x2003;</span></p>
<p><span data-test="Bold" data-name="U+1D416 MATHEMATICAL BOLD CAPITAL W">𝐖</span></p>
<p><span data-test="Italic" data-name="U+1D44A MATHEMATICAL ITALIC CAPITAL W">𝑊</span></p>
<p><span data-test="Bold-italic" data-name="U+1D47E MATHEMATICAL BOLD ITALIC CAPITAL">𝑾</span></p>
<script>
const frakturLWidth = document.getElementById("frakturL").getBoundingClientRect().width;
const emSpaceWidth = document.getElementById("emSpace").getBoundingClientRect().width;
Array.from(document.querySelectorAll('span[data-test]')).forEach(span => {
test(function() {
let spanWidth = span.getBoundingClientRect().width;
// This test expects the default font to provide a fraktur l than is much thiner than a bold/italic/bold-italic W.
// If the font lacks bold/italic/bold-italic W then a fortiori it is likely that its lacks fraktur l, so browsers
// will display "Tofu characters" for all of them (e.g. gray boxes or boxes containing the Unicode code points)
// with very similar widths, so the test is likely to fail.
assert_greater_than(spanWidth, frakturLWidth + emSpaceWidth / 4, `Width of '${span.dataset.name}' is much larger than '${frakturL.dataset.name}'`);
}, `${span.dataset.test} mathematical alphanumeric symbol with the default font`);
});
</script>
</body>
</html>