underover-1.html (9891B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Underscripts and Overscripts parameters</title> 6 <link rel="help" href="https://w3c.github.io/mathml-core/#underscripts-and-overscripts-munder-mover-munderover"> 7 <meta name="assert" content="Elements munder, mover, munderover correctly ."> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/mathml/support/feature-detection.js"></script> 11 <script src="/mathml/support/fonts.js"></script> 12 <link rel="stylesheet" type="text/css" href="/fonts/ahem.css" /> 13 <style> 14 math, mspace, mo { 15 font-family: Ahem; 16 font-size: 10px; 17 } 18 </style> 19 <script> 20 /* This test does not use any specific fonts and so the exact rules are not 21 specified precisely. We assume reasonable values for script shifts and 22 spacing. */ 23 24 function getBox(aId) { 25 var box = document.getElementById(aId).getBoundingClientRect(); 26 box.middle = (box.bottom + box.top) / 2; 27 box.center = (box.left + box.right) / 2; 28 return box; 29 } 30 31 setup({ explicit_done: true }); 32 window.addEventListener("load", () => { loadAllFonts().then(runTests); }); 33 34 function runTests() { 35 test(function() { 36 assert_true(MathMLFeatureDetection.has_mspace()); 37 38 var e = 1; 39 for (var i = 0; i <= 3; i++) { 40 assert_approx_equals(getBox("under" + i + "base").middle, getBox("baseline").bottom, e, "munder " + i + ": base is placed on the baseline"); 41 assert_approx_equals(getBox("over" + i + "base").middle, getBox("baseline").bottom, e, "mover " + i + ": base is placed on the baseline"); 42 } 43 for (var i = 0; i <= 5; i++) { 44 assert_approx_equals(getBox("underover" + i + "base").middle, getBox("baseline").bottom, e, "munderover " + i + ": base is placed on the baseline"); 45 } 46 }, "Alignment of the base on the baseline"); 47 48 test(function() { 49 assert_true(MathMLFeatureDetection.has_mspace()); 50 51 var e = 1; 52 for (var i = 0; i <= 3; i++) { 53 assert_approx_equals(getBox("under" + i + "under").center, getBox("under" + i + "base").center, e, "munder " + i + ": base and script are horizontally centered"); 54 assert_approx_equals(getBox("over" + i + "over").center, getBox("over" + i + "base").center, e, "mover " + i + ": base and script are horizontally centered"); 55 } 56 for (var i = 0; i <= 5; i++) { 57 assert_approx_equals(getBox("underover" + i + "under").center, getBox("underover" + i + "base").center, e, "munderover " + i + ": base and underscript are horizontally centered"); 58 assert_approx_equals(getBox("underover" + i + "over").center, getBox("underover" + i + "base").center, e, "munderover " + i + ": base and overscript are horizontally centered"); 59 } 60 }, "Horizontal alignments of base and scripts"); 61 62 test(function() { 63 assert_true(MathMLFeatureDetection.has_mspace()); 64 65 for (var i = 0; i <= 3; i++) { 66 assert_greater_than_equal(getBox("under" + i + "under").top, getBox("under" + i + "base").bottom, "munder " + i + ": script is under base"); 67 assert_less_than_equal(getBox("over" + i + "over").bottom, getBox("over" + i + "base").top, "mover " + i + ": script is over base"); 68 } 69 for (var i = 0; i <= 5; i++) { 70 assert_greater_than_equal(getBox("underover" + i + "under").top, getBox("underover" + i + "base").bottom, "munderover " + i + ": underscript is under base"); 71 assert_less_than_equal(getBox("underover" + i + "over").bottom, getBox("underover" + i + "base").top, "munderover " + i + ": overscript is over base"); 72 } 73 }, "Relative vertical positions of base and scripts"); 74 75 test(function() { 76 assert_true(MathMLFeatureDetection.has_mspace()); 77 78 var e = 1; 79 for (var i = 0; i <= 3; i++) { 80 assert_approx_equals(getBox("under" + i).width, Math.max(getBox("under" + i + "base").width, getBox("under" + i + "under").width), e, "munder " + i + ": width is determined by the maximum of width of base and script"); 81 assert_approx_equals(getBox("over" + i).width, Math.max(getBox("over" + i + "base").width, getBox("over" + i + "over").width), e, "mover " + i + ": width is determined by the maximum of width of base and script"); 82 } 83 for (var i = 0; i <= 5; i++) { 84 assert_approx_equals(getBox("underover" + i).width, Math.max(getBox("underover" + i + "base").width, getBox("underover" + i + "under").width, getBox("underover" + i + "over").width), e, "munderover " + i + ": width is determined by the maximum of width of base and scripts"); 85 } 86 }, "Width of scripted elements"); 87 88 test(function() { 89 assert_true(MathMLFeatureDetection.has_mspace()); 90 91 var e = 4; 92 for (var i = 0; i <= 3; i++) { 93 assert_approx_equals(getBox("under" + i).height, getBox("under" + i + "base").height + getBox("under" + i + "under").height, e, "munder " + i + ": height is determined by the sum of heights of base and script plus some spacing."); 94 assert_approx_equals(getBox("over" + i).height, getBox("over" + i + "base").height + getBox("over" + i + "over").height, e, "mover " + i + ": height is determined by the sum of heights of base and script plus some spacing."); 95 } 96 for (var i = 0; i <= 5; i++) { 97 assert_approx_equals(getBox("underover" + i).height, getBox("underover" + i + "base").height + getBox("underover" + i + "under").height + getBox("underover" + i + "over").height, e, "munderover " + i + ": height is determined by the sum heights of base and scripts"); 98 } 99 }, "Height of scripted elements"); 100 101 done(); 102 } 103 </script> 104 </head> 105 <body> 106 <div id="log"></div> 107 <p> 108 <math> 109 <mspace id="baseline" width="30px" height="2px" depth="0px" style="background: blue"/> 110 <munder id="under0"> 111 <mspace id="under0base" width="30px" height="5px" depth="5px" style="background: black"/> 112 <mspace id="under0under" width="10px" height="5px" depth="5px" style="background: black"/> 113 </munder> 114 <munder id="under1"> 115 <mspace id="under1base" width="10px" height="5px" depth="5px" style="background: black"/> 116 <mspace id="under1under" width="30px" height="5px" depth="5px" style="background: black"/> 117 </munder> 118 <munder id="under2"> 119 <mspace id="under2base" width="10px" height="15px" depth="15px" style="background: black"/> 120 <mspace id="under2under" width="10px" height="5px" depth="5px" style="background: black"/> 121 </munder> 122 <munder id="under3"> 123 <mspace id="under3base" width="10px" height="5px" depth="5px" style="background: black"/> 124 <mspace id="under3under" width="10px" height="15px" depth="15px" style="background: black"/> 125 </munder> 126 <mover id="over0"> 127 <mspace id="over0base" width="30px" height="5px" depth="5px" style="background: black"/> 128 <mspace id="over0over" width="10px" height="5px" depth="5px" style="background: black"/> 129 </mover> 130 <mover id="over1"> 131 <mspace id="over1base" width="10px" height="5px" depth="5px" style="background: black"/> 132 <mspace id="over1over" width="30px" height="5px" depth="5px" style="background: black"/> 133 </mover> 134 <mover id="over2"> 135 <mspace id="over2base" width="10px" height="15px" depth="15px" style="background: black"/> 136 <mspace id="over2over" width="10px" height="5px" depth="5px" style="background: black"/> 137 </mover> 138 <mover id="over3"> 139 <mspace id="over3base" width="10px" height="5px" depth="5px" style="background: black"/> 140 <mspace id="over3over" width="10px" height="15px" depth="15px" style="background: black"/> 141 </mover> 142 <munderover id="underover0"> 143 <mspace id="underover0base" width="30px" height="5px" depth="5px" style="background: black"/> 144 <mspace id="underover0under" width="10px" height="5px" depth="5px" style="background: black"/> 145 <mspace id="underover0over" width="10px" height="5px" depth="5px" style="background: black"/> 146 </munderover> 147 <munderover id="underover1"> 148 <mspace id="underover1base" width="10px" height="5px" depth="5px" style="background: black"/> 149 <mspace id="underover1under" width="30px" height="5px" depth="5px" style="background: black"/> 150 <mspace id="underover1over" width="10px" height="5px" depth="5px" style="background: black"/> 151 </munderover> 152 <munderover id="underover2"> 153 <mspace id="underover2base" width="10px" height="5px" depth="5px" style="background: black"/> 154 <mspace id="underover2under" width="10px" height="5px" depth="5px" style="background: black"/> 155 <mspace id="underover2over" width="30px" height="5px" depth="5px" style="background: black"/> 156 </munderover> 157 <munderover id="underover3"> 158 <mspace id="underover3base" width="10px" height="15px" depth="15px" style="background: black"/> 159 <mspace id="underover3under" width="10px" height="5px" depth="5px" style="background: black"/> 160 <mspace id="underover3over" width="10px" height="5px" depth="5px" style="background: black"/> 161 </munderover> 162 <munderover id="underover4"> 163 <mspace id="underover4base" width="10px" height="5px" depth="5px" style="background: black"/> 164 <mspace id="underover4under" width="10px" height="15px" depth="15px" style="background: black"/> 165 <mspace id="underover4over" width="10px" height="5px" depth="5px" style="background: black"/> 166 </munderover> 167 <munderover id="underover5"> 168 <mspace id="underover5base" width="10px" height="5px" depth="5px" style="background: black"/> 169 <mspace id="underover5under" width="10px" height="5px" depth="5px" style="background: black"/> 170 <mspace id="underover5over" width="10px" height="15px" depth="15px" style="background: black"/> 171 </munderover> 172 </math> 173 </p> 174 </body> 175 </html>