1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Fraction/Stack parameters (fallback)</title>
<link rel="help" href="https://w3c.github.io/mathml-core/#fractions-mfrac">
<meta name="assert" content="Element mfrac correctly uses the fraction fallback parameters.">
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/feature-detection.js"></script>
<script src="/mathml/support/fonts.js"></script>
<style>
/* Testing fallback values is tricky as we don't have a lot of flexibility to
make sure one parameter is not shadowed by another one. We also use the
Ahem font here, so can't really play with the fallback values involved. */
math, mspace {
font-size: 200px; /* Large value because underlineThickness is small */
}
math {
/* OS/2.sxHeight = 800 */
/* post.underlineThickness == 20 */
font-family: Ahem;
}
</style>
<script>
const emToPx = 200 / 1000; // font-size: 200px, font.em = 1000
const epsilon = 1;
const xHeight = 800;
const underlineThickness = 20;
// NB: This test assumes the fallback shifts are all equal to zero.
const axisHeight = xHeight / 2;
const fractionRuleThickness = underlineThickness;
const fractionNumeratorGapMin = underlineThickness;
const fractionDenominatorGapMin = underlineThickness;
const fractionNumeratorDisplayStyleGapMin = 3 * underlineThickness;
const fractionDenominatorDisplayStyleGapMin = 3 * underlineThickness;
const stackGapMin = 3 * underlineThickness;
const stackDisplayStyleGapMin = 7 * underlineThickness;
function getBox(aId) {
return document.getElementById(aId).getBoundingClientRect();
}
setup({ explicit_done: true });
window.addEventListener("load", () => { loadAllFonts().then(runTests); });
function runTests() {
test(function() {
assert_true(MathMLFeatureDetection.has_mspace());
assert_approx_equals(axisHeight * emToPx,
(getBox("ref0001").top -
getBox("num0001").bottom) -
(fractionRuleThickness/2 +
fractionNumeratorGapMin) * emToPx,
epsilon);
assert_approx_equals((getBox("den0002").top -
getBox("num0002").bottom),
(fractionNumeratorGapMin +
fractionRuleThickness +
fractionDenominatorGapMin) * emToPx,
epsilon);
}, "nonzero linethickness, displaystyle=false");
test(function() {
assert_true(MathMLFeatureDetection.has_mspace());
assert_approx_equals(axisHeight * emToPx,
(getBox("ref0003").top -
getBox("num0003").bottom) -
(fractionRuleThickness/2 +
fractionNumeratorDisplayStyleGapMin) * emToPx,
epsilon, "mfrac: thickness, axis height");
assert_approx_equals((getBox("den0004").top -
getBox("num0004").bottom),
(fractionNumeratorDisplayStyleGapMin +
fractionRuleThickness +
fractionDenominatorDisplayStyleGapMin) * emToPx,
epsilon);
}, "nonzero linethickness, displaystyle=true");
test(function() {
assert_true(MathMLFeatureDetection.has_mspace());
assert_approx_equals((getBox("ref1001").top -
getBox("num1001").bottom),
stackGapMin/2 * emToPx,
epsilon);
assert_approx_equals((getBox("den1001").top) -
getBox("ref1001").top,
stackGapMin/2 * emToPx,
epsilon);
}, "linethickness=0, displaystyle=false");
test(function() {
assert_true(MathMLFeatureDetection.has_mspace());
assert_approx_equals((getBox("ref1002").top -
getBox("num1002").bottom),
stackDisplayStyleGapMin/2 * emToPx,
epsilon);
assert_approx_equals((getBox("den1002").top) -
getBox("ref1002").top,
stackDisplayStyleGapMin/2 * emToPx,
epsilon);
}, "linethickness=0, displaystyle=true");
done();
}
</script>
</head>
<body>
<div id="log"></div>
<p>
<math>
<mspace id="ref0001" height="0em" depth="1em" width="1em" style="background: green"/>
<mfrac>
<mspace width="1em" height="2em" depth="0em" id="num0001" style="background: blue"/>
<mspace width="1em" height="0em" depth="2em" id="den0001" style="background: purple"/>
</mfrac>
</math>
</p>
<p>
<math>
<mfrac>
<mspace width="1em" height="2em" depth="4em" id="num0002" style="background: blue"/>
<mspace width="1em" height="4em" depth="2em" id="den0002" style="background: purple"/>
</mfrac>
</math>
</p>
<hr/>
<p>
<math displaystyle="true">
<mspace id="ref0003" height="0em" depth="1em" width="1em" style="background: green"/>
<mfrac>
<mspace width="1em" height="2em" depth="0em" id="num0003" style="background: blue"/>
<mspace width="1em" height="0em" depth="2em" id="den0003" style="background: purple"/>
</mfrac>
</math>
</p>
<p>
<math displaystyle="true">
<mfrac>
<mspace width="1em" height="2em" depth="4em" id="num0004" style="background: blue"/>
<mspace width="1em" height="4em" depth="2em" id="den0004" style="background: purple"/>
</mfrac>
</math>
</p>
<hr/>
<p>
<math>
<mspace id="ref1001" height="0em" depth="1em" width="1em" style="background: green"/>
<mfrac linethickness="0">
<mspace width="1em" height="2em" depth="0em" id="num1001" style="background: blue"/>
<mspace width="1em" height="0em" depth="2em" id="den1001" style="background: purple"/>
</mfrac>
</math>
</p>
<hr/>
<p>
<math displaystyle="true">
<mspace id="ref1002" height="0em" depth="1em" width="1em" style="background: green"/>
<mfrac linethickness="0">
<mspace width="1em" height="2em" depth="0em" id="num1002" style="background: blue"/>
<mspace width="1em" height="0em" depth="2em" id="den1002" style="background: purple"/>
</mfrac>
</math>
</p>
</body>
</html>
|