Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Subscripts and Superscripts metrics</title>
<meta name="assert" content="Verify metrics of scripted elements with tall scripts.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/feature-detection.js"></script>
<style>
math, mspace {
font-size: 10px;
}
</style>
<script>
/* This test does not use any specific fonts and so the exact rules are not
specified precisely. We assume reasonable values for script shifts and
spacing. */
function getBox(aId) {
var box = document.getElementById(aId).getBoundingClientRect();
box.middle = (box.bottom + box.top) / 2;
return box;
}
setup({ explicit_done: true });
window.addEventListener("load", runTests);
var sizeArray = [50, 75, 100];
function runTests() {
test(function() {
assert_true(MathMLFeatureDetection.has_mspace());
var e = 1;
assert_approx_equals(getBox("msubbase").middle, getBox("baseline").bottom, e, "msub base is placed on the baseline");
assert_approx_equals(getBox("msupbase").middle, getBox("baseline").bottom, e, "msup base is placed on the baseline");
assert_approx_equals(getBox("msubsupbase").middle, getBox("baseline").bottom, e, "msubsup base is placed on the baseline");
assert_approx_equals(getBox("multibase").middle, getBox("baseline").bottom, e, "mmultiscripts baseis placed on the baseline");
}, "Alignment on the baseline with different and large script heights");
test(function() {
assert_true(MathMLFeatureDetection.has_mspace());
assert_greater_than(getBox("msubsub").top, getBox("msubbase").top, "msub: subscript is below the top of the base");
assert_less_than(getBox("msupsup").bottom, getBox("msupbase").bottom, "msup: supscript is above the bottom of the base");
assert_greater_than(getBox("msubsupsub").top, getBox("msubsupbase").top, "msubsup: subscript is below the top of the base");
assert_less_than(getBox("msubsupsup").bottom, getBox("msubsupbase").bottom, "msubsup: supscript is above the bottom of the base");
assert_greater_than(getBox("multipostsub").top, getBox("multibase").top, "mmultiscripts: postsubscript is below the top of the base");
assert_less_than(getBox("multipostsup").bottom, getBox("multibase").bottom, "mmultiscripts: postsupscript is above the bottom of the base");
assert_greater_than(getBox("multipresub").top, getBox("multibase").top, "mmultiscripts: presubscript is below the top of the base");
assert_less_than(getBox("multipresup").bottom, getBox("multibase").bottom, "mmultiscripts: presupscript is above the bottom of the base");
}, "Tall subscripts/superscripts are not placed too high/low");
test(function() {
assert_true(MathMLFeatureDetection.has_mspace());
assert_greater_than(getBox("msubsupsub").top, getBox("msubsupsup").bottom, "msubsup: subscript is below the superscript");
assert_greater_than(getBox("multipresub").top, getBox("multipresup").bottom, "mmultiscripts: presubscript is below the presuperscript");
assert_greater_than(getBox("multipostsub").top, getBox("multipostsup").bottom, "mmultiscripts: postsubscript is below the postsuperscript");
}, "No collisions for tall subscripts and superscripts");
done();
}
</script>
</head>
<body>
<div id="log"></div>
<p>
<math>
<mspace id="baseline" width="30px" height="2px" depth="0px" style="background: blue"/>
<msub id="msub">
<mspace id="msubbase" width="30px" height="15px" depth="15px" style="background: black"/>
<mspace id="msubsub" width="10px" height="50px" depth="50px" style="background: black"/>
</msub>
<msup id="msup">
<mspace id="msupbase" width="30px" height="15px" depth="15px" style="background: black"/>
<mspace id="msupsup" width="10px" height="75px" depth="75px" style="background: black"/>
</msup>
<msubsup id="msubsup">
<mspace id="msubsupbase" width="30px" height="15px" depth="15px" style="background: black"/>
<mspace id="msubsupsub" width="10px" height="50px" depth="50px" style="background: black"/>
<mspace id="msubsupsup" width="10px" height="75px" depth="75px" style="background: black"/>
</msubsup>
<mmultiscripts id="multi">
<mspace id="multibase" width="30px" height="15px" depth="15px" style="background: black"/>
<mspace id="multipostsub" width="10px" height="50px" depth="50px" style="background: black"/>
<mspace id="multipostsup" width="10px" height="75px" depth="75px" style="background: black"/>
<mprescripts/>
<mspace id="multipresub" width="10px" height="50px" depth="50px" style="background: black"/>
<mspace id="multipresup" width="10px" height="75px" depth="75px" style="background: black"/>
</mmultiscripts>
</math>
</p>
</body>
</html>