subsup-2.html (11795B)
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."> 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 assert_less_than_equal(getBox("msubBase").right, getBox("msubSub").left, e, "subscript is after base"); 37 assert_less_than_equal(getBox("msupBase").right, getBox("msupSup").left, e, "superscript is after base"); 38 assert_less_than_equal(getBox("msubsupBase").right, getBox("msubsupSub").left, e, "subscript is after base"); 39 assert_less_than_equal(getBox("msubsupBase").right, getBox("msubsupSup").left, e, "superscript is after base"); 40 41 assert_greater_than_equal(getBox("premsubBase").right, getBox("premsubSub").left, e, "subscript is before base"); 42 assert_greater_than_equal(getBox("premsupBase").right, getBox("premsupSup").left, e, "superscript is before base"); 43 assert_greater_than_equal(getBox("premsubsupBase").right, getBox("premsubsupSub").left, e, "subscript is before base"); 44 assert_greater_than_equal(getBox("premsubsupBase").right, getBox("premsubsupSup").left, e, "superscript is before base"); 45 46 e = 3; 47 assert_approx_equals(getBox("msubBase").right, getBox("msubSub").left, e, "msub: space between base and subscript is small"); 48 assert_approx_equals(getBox("msubBase").right, getBox("msubSub").left, e, "msub: subscript is after base"); 49 assert_approx_equals(getBox("msupBase").right, getBox("msupSup").left, e, "msup: superscript is after base"); 50 assert_approx_equals(getBox("msubsupBase").right, getBox("msubsupSub").left, e, "msubsup: subscript is after base"); 51 assert_approx_equals(getBox("msubsupBase").right, getBox("msubsupSup").left, e, "msubsup: superscript is after base"); 52 53 assert_approx_equals(getBox("premsubBase").left, getBox("premsubSub").right, e, "msub: space between base and subscript is small"); 54 assert_approx_equals(getBox("premsubBase").left, getBox("premsubSub").right, e, "msub: subscript is after base"); 55 assert_approx_equals(getBox("premsupBase").left, getBox("premsupSup").right, e, "msup: superscript is after base"); 56 assert_approx_equals(getBox("premsubsupBase").left, getBox("premsubsupSub").right, e, "msubsup: subscript is after base"); 57 assert_approx_equals(getBox("premsubsupBase").left, getBox("premsubsupSup").right, e, "msubsup: superscript is after base"); 58 }, "Respective horizontal positions"); 59 60 test(function() { 61 assert_true(MathMLFeatureDetection.has_mspace()); 62 63 var e = 1; 64 assert_approx_equals(getBox("msubBase").middle, getBox("baseline").bottom, e, "base is placed on the baseline"); 65 assert_approx_equals(getBox("msupBase").middle, getBox("baseline").bottom, e, "base is placed on the baseline"); 66 assert_approx_equals(getBox("msubsupBase").middle, getBox("baseline").bottom, e, "base is placed on the baseline"); 67 assert_approx_equals(getBox("premsubBase").middle, getBox("baseline").bottom, e, "base is placed on the baseline"); 68 assert_approx_equals(getBox("premsupBase").middle, getBox("baseline").bottom, e, "base is placed on the baseline"); 69 assert_approx_equals(getBox("premsubsupBase").middle, getBox("baseline").bottom, e, "base is placed on the baseline"); 70 }, "Alignment of the base on the baseline"); 71 72 test(function() { 73 assert_true(MathMLFeatureDetection.has_mspace()); 74 75 assert_greater_than(getBox("msubSub").middle, getBox("msubBase").middle, "script is placed at the bottom of the base"); 76 assert_less_than(getBox("msupSup").middle, getBox("msupBase").middle, "script is placed at the top of the base"); 77 assert_greater_than(getBox("msubsupSub").middle, getBox("msubsupBase").middle, "script is placed at the bottom of the base"); 78 assert_less_than(getBox("msubsupSup").middle, getBox("msubsupBase").middle, "script is placed at the top of the base"); 79 80 assert_greater_than(getBox("premsubSub").middle, getBox("premsubBase").middle, "script is placed at the bottom of the base"); 81 assert_less_than(getBox("premsupSup").middle, getBox("premsupBase").middle, "script is placed at the top of the base"); 82 assert_greater_than(getBox("premsubsupSub").middle, getBox("premsubsupBase").middle, "script is placed at the bottom of the base"); 83 assert_less_than(getBox("premsubsupSup").middle, getBox("premsubsupBase").middle, "script is placed at the top of the base"); 84 }, "Vertical position of scripts"); 85 86 test(function() { 87 assert_true(MathMLFeatureDetection.has_mspace()); 88 89 var e = 3; 90 assert_approx_equals(getBox("msub").width, getBox("msubSub").right - getBox("msubBase").left, e, "width is determined by the left/right sides of base/script (+ some space after script)"); 91 assert_approx_equals(getBox("msup").width, getBox("msupSup").right - getBox("msupBase").left, e, "width is determined by the left/right sides of base/script (+ some space after script)"); 92 assert_approx_equals(getBox("msubsup").width, Math.max(getBox("msubsupSub").right, getBox("msubsupSup").right) - getBox("msubsupBase").left, e, "width is determined by the left/right sides of base/scripts (+ some space after script)"); 93 94 assert_approx_equals(getBox("premsub").width, getBox("premsubBase").right - getBox("premsubSub").left, e, "width is determined by the right/left sides of base/script (+ some space after script)"); 95 assert_approx_equals(getBox("premsup").width, getBox("premsupBase").right - getBox("premsupSup").left, e, "width is determined by the right/left sides of base/script (+ some space after script)"); 96 assert_approx_equals(getBox("premsubsup").width, getBox("premsubsupBase").right - Math.min(getBox("premsubsupSub").left, getBox("premsubsupSup").left), e, "width is determined by the right/left sides of base/scripts (+ some space after script)"); 97 }, "Width of scripted elements"); 98 99 test(function() { 100 assert_true(MathMLFeatureDetection.has_mspace()); 101 102 var e = 5; 103 assert_greater_than_equal(getBox("msub").height, getBox("msubBase").height, e, "height is at least the one of the base"); 104 assert_greater_than_equal(getBox("msup").height, getBox("msupBase").height, e, "height is at least the one of the base"); 105 assert_greater_than_equal(getBox("msubsup").height, getBox("msubsupBase").height, e, "height is at least the one of the base"); 106 assert_greater_than_equal(getBox("premsub").height, getBox("premsubBase").height, e, "height is at least the one of the base"); 107 assert_greater_than_equal(getBox("premsup").height, getBox("premsupBase").height, e, "height is at least the one of the base"); 108 assert_greater_than_equal(getBox("premsubsup").height, getBox("premsubsupBase").height, e, "height is at least the one of the base"); 109 110 assert_approx_equals(getBox("msub").height, Math.max(getBox("msubSub").bottom, getBox("msubBase").bottom) - getBox("msubBase").top, e, "msub height is determined by the top/bottom sides of base/scripts"); 111 assert_approx_equals(getBox("msup").height, getBox("msupBase").bottom - Math.min(getBox("msupSup").top, getBox("msupBase").top), e, "msup height is determined by the top/bottom sides of base/scripts"); 112 assert_approx_equals(getBox("msubsup").height, Math.max(getBox("msubSub").bottom, getBox("msubBase").bottom) - Math.min(getBox("msupSup").top, getBox("msupBase").top), e, "msubsup height is determined by the top/bottom sides of base/scripts"); 113 assert_approx_equals(getBox("premsub").height, Math.max(getBox("premsubSub").bottom, getBox("premsubBase").bottom) - getBox("premsubBase").top, e, "msub height is determined by the top/bottom sides of base/scripts"); 114 assert_approx_equals(getBox("premsup").height, getBox("premsupBase").bottom - Math.min(getBox("premsupSup").top, getBox("premsupBase").top), e, "msup height is determined by the top/bottom sides of base/scripts"); 115 assert_approx_equals(getBox("premsubsup").height, Math.max(getBox("premsubSub").bottom, getBox("premsubBase").bottom) - Math.min(getBox("premsupSup").top, getBox("premsupBase").top), e, "msubsup height is determined by the top/bottom sides of base/scripts"); 116 }, "Height of scripted elements"); 117 118 test(function() { 119 ["none", "mprescripts"].forEach(function(name) { 120 var elements = document.getElementsByTagName(name); 121 for (var i = 0; i < elements.length; i++) { 122 var box = elements[i].getBoundingClientRect(); 123 assert_equals(box.height * box.width, 0, "<" + name + "> " + i + " has zero is empty"); 124 } 125 }); 126 }, "Size of empty elements"); 127 128 done(); 129 } 130 </script> 131 </head> 132 <body> 133 <div id="log"></div> 134 <p> 135 <math> 136 <mspace id="baseline" width="30px" height="2px" depth="0px" style="background: blue"/> 137 <mmultiscripts id="msub" style="background: green"> 138 <mspace id="msubBase" width="30px" height="15px" depth="15px" style="background: black"/> 139 <mspace id="msubSub" width="10px" height="5px" depth="5px" style="background: black"/> 140 <none/> 141 </mmultiscripts> 142 <mmultiscripts id="msup" style="background: green"> 143 <mspace id="msupBase" width="30px" height="15px" depth="15px" style="background: black"/> 144 <none/> 145 <mspace id="msupSup" width="10px" height="5px" depth="5px" style="background: black"/> 146 </mmultiscripts> 147 <mmultiscripts id="msubsup" style="background: green"> 148 <mspace id="msubsupBase" width="30px" height="15px" depth="15px" style="background: black"/> 149 <mspace id="msubsupSub" width="10px" height="5px" depth="5px" style="background: black"/> 150 <mspace id="msubsupSup" width="10px" height="5px" depth="5px" style="background: black"/> 151 </mmultiscripts> 152 <mmultiscripts id="premsub" style="background: green"> 153 <mspace id="premsubBase" width="30px" height="15px" depth="15px" style="background: black"/> 154 <mprescripts/> 155 <mspace id="premsubSub" width="10px" height="5px" depth="5px" style="background: black"/> 156 <none/> 157 </mmultiscripts> 158 <mmultiscripts id="premsup" style="background: green"> 159 <mspace id="premsupBase" width="30px" height="15px" depth="15px" style="background: black"/> 160 <mprescripts/> 161 <none/> 162 <mspace id="premsupSup" width="10px" height="5px" depth="5px" style="background: black"/> 163 </mmultiscripts> 164 <mmultiscripts id="premsubsup" style="background: green"> 165 <mspace id="premsubsupBase" width="30px" height="15px" depth="15px" style="background: black"/> 166 <mprescripts/> 167 <mspace id="premsubsupSub" width="10px" height="5px" depth="5px" style="background: black"/> 168 <mspace id="premsubsupSup" width="10px" height="5px" depth="5px" style="background: black"/> 169 </mmultiscripts> 170 </math> 171 </p> 172 </body> 173 </html>