subsup-3.html (10974B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Subscripts and Superscripts metrics</title> 6 <link rel="help" href="https://w3c.github.io/mathml-core/#subscripts-and-superscripts-msub-msup-msubsup"> 7 <meta name="assert" content="Basic metrics for the mmultiscript element with many scripts."> 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 { 15 font: 25px/1 Ahem; 16 } 17 </style> 18 <script> 19 /* This test does not use a font with a MATH table and does not verify layout 20 rules in a very strict way. */ 21 22 function getBox(aId) { 23 var box = document.getElementById(aId).getBoundingClientRect(); 24 box.middle = (box.bottom + box.top) / 2; 25 return box; 26 } 27 28 setup({ explicit_done: true }); 29 window.addEventListener("load", () => { loadAllFonts().then(runTests); }); 30 31 function runTests() { 32 test(function() { 33 assert_true(MathMLFeatureDetection.has_mspace()); 34 35 var e = 1; 36 for (var i = 0; i < 5; i++) 37 assert_approx_equals(getBox("multi" + i + "base").middle, getBox("baseline").bottom, e, "base " + i + "is placed on the baseline"); 38 }, "Alignment of the base on the baseline"); 39 40 test(function() { 41 assert_true(MathMLFeatureDetection.has_mspace()); 42 43 var e = 5; 44 assert_approx_equals(getBox("multi0").width, 30, e, "width of multi0"); 45 assert_approx_equals(getBox("multi0").height, 30, e, "height of multi0"); 46 assert_approx_equals(getBox("multi1").width, 30, e, "width of multi1"); 47 assert_approx_equals(getBox("multi1").height, 30, e, "height of multi1"); 48 for (i = 2; i <= 4; i++) { 49 var scriptedBox = getBox("multi" + i); 50 var lastPostScript = getBox("multi" + i + "postsup" + (i - 1)); 51 var firstPreScript = getBox("multi" + i + "presub1"); 52 assert_approx_equals(scriptedBox.height, firstPreScript.bottom - lastPostScript.top, e, "height of multiscript" + i); 53 assert_approx_equals(scriptedBox.width, lastPostScript.right - firstPreScript.left, e, "width of multiscript" + i); 54 } 55 }, "Dimensions of the scripted elements"); 56 57 test(function() { 58 assert_true(MathMLFeatureDetection.has_mspace()); 59 60 var e = 3; 61 for (var i = 2; i <= 4; i++) { 62 var base = getBox("multi" + i + "base"); 63 for (var j = 1; j < i; j++) { 64 var presup = getBox("multi" + i + "presup" + j); 65 var postsup = getBox("multi" + i + "postsup" + j); 66 var presub = getBox("multi" + i + "presub" + j); 67 var postsub = getBox("multi" + i + "postsub" + j); 68 assert_approx_equals(base.top, presup.middle, e, "multi" + i + " " + j + " presup script"); 69 assert_approx_equals(base.top, postsup.middle, e, "multi" + i + " " + j + " postsup script"); 70 assert_approx_equals(base.bottom, presub.middle, e, "multi" + i + " " + j + " presub script"); 71 assert_approx_equals(base.bottom, postsub.middle, e, "multi" + i + " " + j + " postsub script"); 72 } 73 } 74 }, "Vertical positions of scripts"); 75 76 test(function() { 77 assert_true(MathMLFeatureDetection.has_mspace()); 78 79 var e = 1; 80 for (var i = 2; i <= 4; i++) { 81 var base = getBox("multi" + i + "base"); 82 for (var j = 1; j < i; j++) { 83 var presup = getBox("multi" + i + "presup" + j); 84 var postsup = getBox("multi" + i + "postsup" + j); 85 var presub = getBox("multi" + i + "presub" + j); 86 var postsub = getBox("multi" + i + "postsub" + j); 87 assert_approx_equals(presup.right, presub.right, e, "multi" + i + "pre"); 88 assert_approx_equals(postsup.left, postsub.left, e, "multi" + i + "post"); 89 } 90 } 91 }, "Horizontal alignment of scripts"); 92 93 test(function() { 94 assert_true(MathMLFeatureDetection.has_mspace()); 95 96 for (var i = 2; i <= 4; i++) { 97 var base = getBox("multi" + i + "base"); 98 var firstPostScript = getBox("multi" + i + "postsub1"); 99 var lastPreScript = getBox("multi" + i + "presup" + (i - 1)); 100 assert_less_than_equal(base.right, firstPostScript.left, 1, "postcripts are after base"); 101 assert_less_than_equal(lastPreScript.right, base.left, 1, "prescripts are before base"); 102 assert_approx_equals(base.right, firstPostScript.left, 5, "spacing after base is not too large"); 103 assert_approx_equals(lastPreScript.right, base.left, 5, "spacing before base is not too large"); 104 for (var j = 1; j < i - 1; j++) { 105 var post = getBox("multi" + i + "postsub" + j); 106 var postNext = getBox("multi" + i + "postsub" + (j + 1)); 107 var pre = getBox("multi" + i + "presup" + j); 108 var preNext = getBox("multi" + i + "presup" + (j + 1)); 109 assert_less_than_equal(post.right, postNext.left, 1, "multi" + i + "order post" + j + " is before its successor"); 110 assert_less_than_equal(pre.right, preNext.left, 1, "multi" + i + "order pre" + j + " is before its successor"); 111 assert_approx_equals(post.right, postNext.left, 5, "multi" + i + "space after post" + j + " is not too large"); 112 assert_approx_equals(pre.right, preNext.left, 5, "multi" + i + "space after pre" + j + " is not too large"); 113 } 114 } 115 }, "Horizontal positions of scripts"); 116 117 done(); 118 } 119 </script> 120 </head> 121 <body> 122 <div id="log"></div> 123 <p> 124 <math> 125 <mspace id="baseline" width="30px" height="2px" depth="0px" style="background: blue"/> 126 <mmultiscripts id="multi0" style="background: green"> 127 <mspace id="multi0base" width="30px" height="15px" depth="15px" style="background: black"/> 128 </mmultiscripts> 129 <mmultiscripts id="multi1" style="background: green"> 130 <mspace id="multi1base" width="30px" height="15px" depth="15px" style="background: black"/> 131 <mprescripts/> 132 </mmultiscripts> 133 <mmultiscripts id="multi2" style="background: green"> 134 <mspace id="multi2base" width="30px" height="15px" depth="15px" style="background: black"/> 135 <mspace id="multi2postsub1" width="10px" height="5px" depth="5px" style="background: black"/> 136 <mspace id="multi2postsup1" width="10px" height="5px" depth="5px" style="background: black"/> 137 <mprescripts/> 138 <mspace id="multi2presub1" width="10px" height="5px" depth="5px" style="background: black"/> 139 <mspace id="multi2presup1" width="10px" height="5px" depth="5px" style="background: black"/> 140 </mmultiscripts> 141 <mmultiscripts id="multi3" style="background: green"> 142 <mspace id="multi3base" width="30px" height="15px" depth="15px" style="background: black"/> 143 <mspace id="multi3postsub1" width="10px" height="5px" depth="5px" style="background: black"/> 144 <mspace id="multi3postsup1" width="10px" height="5px" depth="5px" style="background: black"/> 145 <mspace id="multi3postsub2" width="10px" height="5px" depth="5px" style="background: black"/> 146 <mspace id="multi3postsup2" width="10px" height="5px" depth="5px" style="background: black"/> 147 <mprescripts/> 148 <mspace id="multi3presub1" width="10px" height="5px" depth="5px" style="background: black"/> 149 <mspace id="multi3presup1" width="10px" height="5px" depth="5px" style="background: black"/> 150 <mspace id="multi3presub2" width="10px" height="5px" depth="5px" style="background: black"/> 151 <mspace id="multi3presup2" width="10px" height="5px" depth="5px" style="background: black"/> 152 </mmultiscripts> 153 <mmultiscripts id="multi4" style="background: green"> 154 <mspace id="multi4base" width="30px" height="15px" depth="15px" style="background: black"/> 155 <mspace id="multi4postsub1" width="10px" height="5px" depth="5px" style="background: black"/> 156 <mspace id="multi4postsup1" width="10px" height="5px" depth="5px" style="background: black"/> 157 <mspace id="multi4postsub2" width="10px" height="5px" depth="5px" style="background: black"/> 158 <mspace id="multi4postsup2" width="10px" height="5px" depth="5px" style="background: black"/> 159 <mspace id="multi4postsub3" width="10px" height="5px" depth="5px" style="background: black"/> 160 <mspace id="multi4postsup3" width="10px" height="5px" depth="5px" style="background: black"/> 161 <mprescripts/> 162 <mspace id="multi4presub1" width="10px" height="5px" depth="5px" style="background: black"/> 163 <mspace id="multi4presup1" width="10px" height="5px" depth="5px" style="background: black"/> 164 <mspace id="multi4presub2" width="10px" height="5px" depth="5px" style="background: black"/> 165 <mspace id="multi4presup2" width="10px" height="5px" depth="5px" style="background: black"/> 166 <mspace id="multi4presub3" width="10px" height="5px" depth="5px" style="background: black"/> 167 <mspace id="multi4presup3" width="10px" height="5px" depth="5px" style="background: black"/> 168 </mmultiscripts> 169 <mmultiscripts id="multi5" style="background: green"> 170 <mspace id="multi5base" width="30px" height="15px" depth="15px" style="background: black"/> 171 <mspace id="multi5postsub1" width="10px" height="5px" depth="5px" style="background: black"/> 172 <mspace id="multi5postsup1" width="10px" height="5px" depth="5px" style="background: black"/> 173 <mspace id="multi5postsub2" width="10px" height="5px" depth="5px" style="background: black"/> 174 <mspace id="multi5postsup2" width="10px" height="5px" depth="5px" style="background: black"/> 175 <mspace id="multi5postsub3" width="10px" height="5px" depth="5px" style="background: black"/> 176 <mspace id="multi5postsup3" width="10px" height="5px" depth="5px" style="background: black"/> 177 <mspace id="multi5postsub4" width="10px" height="5px" depth="5px" style="background: black"/> 178 <mspace id="multi5postsup4" width="10px" height="5px" depth="5px" style="background: black"/> 179 <mprescripts/> 180 <mspace id="multi5presub1" width="10px" height="5px" depth="5px" style="background: black"/> 181 <mspace id="multi5presup1" width="10px" height="5px" depth="5px" style="background: black"/> 182 <mspace id="multi5presub2" width="10px" height="5px" depth="5px" style="background: black"/> 183 <mspace id="multi5presup2" width="10px" height="5px" depth="5px" style="background: black"/> 184 <mspace id="multi5presub3" width="10px" height="5px" depth="5px" style="background: black"/> 185 <mspace id="multi5presup3" width="10px" height="5px" depth="5px" style="background: black"/> 186 <mspace id="multi5presub4" width="10px" height="5px" depth="5px" style="background: black"/> 187 <mspace id="multi5presup4" width="10px" height="5px" depth="5px" style="background: black"/> 188 </mmultiscripts> 189 </math> 190 </p> 191 </body> 192 </html>