summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mathml/presentation-markup/scripts/subsup-4.html
blob: cdf6cbe20e27ee6a302c08c97d9b37dace44cafd (plain)
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
<!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 for bases of different heights.">
<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;
      sizeArray.forEach(function(size) {
         assert_approx_equals(getBox("msub" + size + "base").middle, getBox("baseline").bottom, e, "msub base " + size + "is placed on the baseline");
         assert_approx_equals(getBox("msup" + size + "base").middle, getBox("baseline").bottom, e, "msup base " + size + "is placed on the baseline");
         assert_approx_equals(getBox("msubsup" + size + "base").middle, getBox("baseline").bottom, e, "msubsup base " + size + "is placed on the baseline");
         assert_approx_equals(getBox("multi" + size + "base").middle, getBox("baseline").bottom, e, "mmultiscripts base " + size + "is placed on the baseline");
      });
    }, "Alignment on the baseline for bases of different heights");

    test(function() {
      assert_true(MathMLFeatureDetection.has_mspace());

      var e = 5;
      sizeArray.forEach(function(size) {
         assert_approx_equals(getBox("msub" + size + "sub").middle, getBox("msub" + size + "base").bottom, e, "msub script " + size + "is placed at the top of of the base");
      });
    }, "Vertical position of the scripts for bases of different heights");

    done();
  }
</script>
</head>
<body>
  <div id="log"></div>
  <p>
    <math>
      <mspace id="baseline" width="30px" height="2px" depth="0px" style="background: blue"/>
      <msub id="msub50">
        <mspace id="msub50base" width="30px" height="50px" depth="50px" style="background: black"/>
        <mspace id="msub50sub" width="10px" height="5px" depth="5px" style="background: black"/>
      </msub>
      <msup id="msup50">
        <mspace id="msup50base" width="30px" height="50px" depth="50px" style="background: black"/>
        <mspace id="msup50sup" width="10px" height="5px" depth="5px" style="background: black"/>
      </msup>
      <msubsup id="msubsup50">
        <mspace id="msubsup50base" width="30px" height="50px" depth="50px" style="background: black"/>
        <mspace id="msubsup50sub" width="10px" height="5px" depth="5px" style="background: black"/>
        <mspace id="msubsup50sup" width="10px" height="5px" depth="5px" style="background: black"/>
      </msubsup>
      <mmultiscripts id="multi50">
        <mspace id="multi50base" width="30px" height="50px" depth="50px" style="background: black"/>
        <mspace id="multi50postsub" width="10px" height="5px" depth="5px" style="background: black"/>
        <mspace id="multi50postsup" width="10px" height="5px" depth="5px" style="background: black"/>
        <mprescripts/>
        <mspace id="multi50presub" width="10px" height="5px" depth="5px" style="background: black"/>
        <mspace id="multi50presup" width="10px" height="5px" depth="5px" style="background: black"/>
      </mmultiscripts>
      <msub id="msub75">
        <mspace id="msub75base" width="30px" height="75px" depth="75px" style="background: black"/>
        <mspace id="msub75sub" width="10px" height="5px" depth="5px" style="background: black"/>
      </msub>
      <msup id="msup75">
        <mspace id="msup75base" width="30px" height="75px" depth="75px" style="background: black"/>
        <mspace id="msup75sup" width="10px" height="5px" depth="5px" style="background: black"/>
      </msup>
      <msubsup id="msubsup75">
        <mspace id="msubsup75base" width="30px" height="75px" depth="75px" style="background: black"/>
        <mspace id="msubsup75sub" width="10px" height="5px" depth="5px" style="background: black"/>
        <mspace id="msubsup75sup" width="10px" height="5px" depth="5px" style="background: black"/>
      </msubsup>
      <mmultiscripts id="multi75">
        <mspace id="multi75base" width="30px" height="75px" depth="75px" style="background: black"/>
        <mspace id="multi75postsub" width="10px" height="5px" depth="5px" style="background: black"/>
        <mspace id="multi75postsup" width="10px" height="5px" depth="5px" style="background: black"/>
        <mprescripts/>
        <mspace id="multi75presub" width="10px" height="5px" depth="5px" style="background: black"/>
        <mspace id="multi75presub" width="10px" height="5px" depth="5px" style="background: black"/>
      </mmultiscripts>
      <msub id="msub100">
        <mspace id="msub100base" width="30px" height="100px" depth="100px" style="background: black"/>
        <mspace id="msub100sub" width="10px" height="5px" depth="5px" style="background: black"/>
      </msub>
      <msup id="msup100">
        <mspace id="msup100base" width="30px" height="100px" depth="100px" style="background: black"/>
        <mspace id="msup100sup" width="10px" height="5px" depth="5px" style="background: black"/>
      </msup>
      <msubsup id="msubsup100">
        <mspace id="msubsup100base" width="30px" height="100px" depth="100px" style="background: black"/>
        <mspace id="msubsup100sub" width="10px" height="5px" depth="5px" style="background: black"/>
        <mspace id="msubsup100sup" width="10px" height="5px" depth="5px" style="background: black"/>
      </msubsup>
      <mmultiscripts id="multi100">
        <mspace id="multi100base" width="30px" height="100px" depth="100px" style="background: black"/>
        <mspace id="multi100postsub" width="10px" height="5px" depth="5px" style="background: black"/>
        <mspace id="multi100postsup" width="10px" height="5px" depth="5px" style="background: black"/>
        <mprescripts/>
        <mspace id="multi100presub" width="10px" height="5px" depth="5px" style="background: black"/>
        <mspace id="multi100presup" width="10px" height="5px" depth="5px" style="background: black"/>
      </mmultiscripts>
    </math>
  </p>
</body>
</html>