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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Subscripts and Superscripts metrics</title>
<link rel="help" href="https://w3c.github.io/mathml-core/#subscripts-and-superscripts-msub-msup-msubsup">
<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>
|