OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <title>Subscripts and Superscripts metrics</title> |
| 6 <link rel="help" href="http://www.mathml-association.org/MathMLinHTML5/S3.html#S
S4"> |
| 7 <meta name="assert" content="Basic metrics for the mmultiscript element with man
y scripts."> |
| 8 <script src="/resources/testharness.js"></script> |
| 9 <script src="/resources/testharnessreport.js"></script> |
| 10 <style> |
| 11 math, mspace { |
| 12 font-size: 10px; |
| 13 } |
| 14 </style> |
| 15 <script> |
| 16 /* This test does not use any specific fonts and so the exact rules are not |
| 17 specified precisely. We assume reasonable values for script shifts and |
| 18 spacing. */ |
| 19 |
| 20 function getBox(aId) { |
| 21 var box = document.getElementById(aId).getBoundingClientRect(); |
| 22 box.middle = (box.bottom + box.top) / 2; |
| 23 return box; |
| 24 } |
| 25 |
| 26 setup({ explicit_done: true }); |
| 27 window.addEventListener("load", runTests); |
| 28 |
| 29 function runTests() { |
| 30 test(function() { |
| 31 var e = 1; |
| 32 for (var i = 0; i < 5; i++) |
| 33 assert_approx_equals(getBox("multi" + i + "base").middle, getBox("baseli
ne").bottom, e, "base " + i + "is placed on the baseline"); |
| 34 }, "Alignment of the base on the baseline"); |
| 35 |
| 36 test(function() { |
| 37 var e = 5; |
| 38 assert_approx_equals(getBox("multi0").width, 30, e, "width of multi0"); |
| 39 assert_approx_equals(getBox("multi0").height, 30, e, "height of multi0"); |
| 40 assert_approx_equals(getBox("multi1").width, 30, e, "width of multi1"); |
| 41 assert_approx_equals(getBox("multi1").height, 30, e, "height of multi1"); |
| 42 for (i = 2; i <= 4; i++) { |
| 43 var scriptedBox = getBox("multi" + i); |
| 44 var lastPostScript = getBox("multi" + i + "postsup" + (i - 1)); |
| 45 var firstPreScript = getBox("multi" + i + "presub1"); |
| 46 assert_approx_equals(scriptedBox.height, firstPreScript.bottom - lastPos
tScript.top, e, "height of multiscript" + i); |
| 47 assert_approx_equals(scriptedBox.width, lastPostScript.right - firstPreS
cript.left, e, "width of multiscript" + i); |
| 48 } |
| 49 }, "Dimensions of the scripted elements"); |
| 50 |
| 51 test(function() { |
| 52 var e = 3; |
| 53 for (var i = 2; i <= 4; i++) { |
| 54 var base = getBox("multi" + i + "base"); |
| 55 for (var j = 1; j < i; j++) { |
| 56 var presup = getBox("multi" + i + "presup" + j); |
| 57 var postsup = getBox("multi" + i + "postsup" + j); |
| 58 var presub = getBox("multi" + i + "presub" + j); |
| 59 var postsub = getBox("multi" + i + "postsub" + j); |
| 60 assert_approx_equals(base.top, presup.middle, e, "multi" + i + " " + j
+ " presup script"); |
| 61 assert_approx_equals(base.top, postsup.middle, e, "multi" + i + " " +
j + " postsup script"); |
| 62 assert_approx_equals(base.bottom, presub.middle, e, "multi" + i + " "
+ j + " presub script"); |
| 63 assert_approx_equals(base.bottom, postsub.middle, e, "multi" + i + " "
+ j + " postsub script"); |
| 64 } |
| 65 } |
| 66 }, "Vertical positions of scripts"); |
| 67 |
| 68 test(function() { |
| 69 var e = 1; |
| 70 for (var i = 2; i <= 4; i++) { |
| 71 var base = getBox("multi" + i + "base"); |
| 72 for (var j = 1; j < i; j++) { |
| 73 var presup = getBox("multi" + i + "presup" + j); |
| 74 var postsup = getBox("multi" + i + "postsup" + j); |
| 75 var presub = getBox("multi" + i + "presub" + j); |
| 76 var postsub = getBox("multi" + i + "postsub" + j); |
| 77 assert_approx_equals(presup.right, presub.right, e, "multi" + i + "pre
"); |
| 78 assert_approx_equals(postsup.left, postsub.left, e, "multi" + i + "pos
t"); |
| 79 } |
| 80 } |
| 81 }, "Horizontal alignment of scripts"); |
| 82 |
| 83 test(function() { |
| 84 for (var i = 2; i <= 4; i++) { |
| 85 var base = getBox("multi" + i + "base"); |
| 86 var firstPostScript = getBox("multi" + i + "postsub1"); |
| 87 var lastPreScript = getBox("multi" + i + "presup" + (i - 1)); |
| 88 assert_less_than_equal(base.right, firstPostScript.left, 1, "postcripts
are after base"); |
| 89 assert_less_than_equal(lastPreScript.right, base.left, 1, "prescripts ar
e before base"); |
| 90 assert_approx_equals(base.right, firstPostScript.left, 5, "spacing after
base is not too large"); |
| 91 assert_approx_equals(lastPreScript.right, base.left, 5, "spacing before
base is not too large"); |
| 92 for (var j = 1; j < i - 1; j++) { |
| 93 var post = getBox("multi" + i + "postsub" + j); |
| 94 var postNext = getBox("multi" + i + "postsub" + (j + 1)); |
| 95 var pre = getBox("multi" + i + "presup" + j); |
| 96 var preNext = getBox("multi" + i + "presup" + (j + 1)); |
| 97 assert_less_than_equal(post.right, postNext.left, 1, "multi" + i + "or
der post" + j + " is before its successor"); |
| 98 assert_less_than_equal(pre.right, preNext.left, 1, "multi" + i + "orde
r pre" + j + " is before its successor"); |
| 99 assert_approx_equals(post.right, postNext.left, 5, "multi" + i + "spac
e after post" + j + " is not too large"); |
| 100 assert_approx_equals(pre.right, preNext.left, 5, "multi" + i + "space
after pre" + j + " is not too large"); |
| 101 } |
| 102 } |
| 103 }, "Horizontal positions of scripts"); |
| 104 |
| 105 done(); |
| 106 } |
| 107 </script> |
| 108 </head> |
| 109 <body> |
| 110 <p> |
| 111 <math> |
| 112 <mspace id="baseline" width="30px" height="2px" depth="0px" mathbackground
="blue"/> |
| 113 <mmultiscripts id="multi0" mathbackground="green"> |
| 114 <mspace id="multi0base" width="30px" height="15px" depth="15px" mathback
ground="black"/> |
| 115 </mmultiscripts> |
| 116 <mmultiscripts id="multi1" mathbackground="green"> |
| 117 <mspace id="multi1base" width="30px" height="15px" depth="15px" mathback
ground="black"/> |
| 118 <mprescripts/> |
| 119 </mmultiscripts> |
| 120 <mmultiscripts id="multi2" mathbackground="green"> |
| 121 <mspace id="multi2base" width="30px" height="15px" depth="15px" mathback
ground="black"/> |
| 122 <mspace id="multi2postsub1" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 123 <mspace id="multi2postsup1" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 124 <mprescripts/> |
| 125 <mspace id="multi2presub1" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 126 <mspace id="multi2presup1" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 127 </mmultiscripts> |
| 128 <mmultiscripts id="multi3" mathbackground="green"> |
| 129 <mspace id="multi3base" width="30px" height="15px" depth="15px" mathback
ground="black"/> |
| 130 <mspace id="multi3postsub1" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 131 <mspace id="multi3postsup1" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 132 <mspace id="multi3postsub2" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 133 <mspace id="multi3postsup2" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 134 <mprescripts/> |
| 135 <mspace id="multi3presub1" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 136 <mspace id="multi3presup1" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 137 <mspace id="multi3presub2" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 138 <mspace id="multi3presup2" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 139 </mmultiscripts> |
| 140 <mmultiscripts id="multi4" mathbackground="green"> |
| 141 <mspace id="multi4base" width="30px" height="15px" depth="15px" mathback
ground="black"/> |
| 142 <mspace id="multi4postsub1" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 143 <mspace id="multi4postsup1" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 144 <mspace id="multi4postsub2" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 145 <mspace id="multi4postsup2" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 146 <mspace id="multi4postsub3" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 147 <mspace id="multi4postsup3" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 148 <mprescripts/> |
| 149 <mspace id="multi4presub1" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 150 <mspace id="multi4presup1" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 151 <mspace id="multi4presub2" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 152 <mspace id="multi4presup2" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 153 <mspace id="multi4presub3" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 154 <mspace id="multi4presup3" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 155 </mmultiscripts> |
| 156 <mmultiscripts id="multi5" mathbackground="green"> |
| 157 <mspace id="multi5base" width="30px" height="15px" depth="15px" mathback
ground="black"/> |
| 158 <mspace id="multi5postsub1" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 159 <mspace id="multi5postsup1" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 160 <mspace id="multi5postsub2" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 161 <mspace id="multi5postsup2" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 162 <mspace id="multi5postsub3" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 163 <mspace id="multi5postsup3" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 164 <mspace id="multi5postsub4" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 165 <mspace id="multi5postsup4" width="10px" height="5px" depth="5px" mathba
ckground="black"/> |
| 166 <mprescripts/> |
| 167 <mspace id="multi5presub1" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 168 <mspace id="multi5presup1" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 169 <mspace id="multi5presub2" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 170 <mspace id="multi5presup2" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 171 <mspace id="multi5presub3" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 172 <mspace id="multi5presup3" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 173 <mspace id="multi5presub4" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 174 <mspace id="multi5presup4" width="10px" height="5px" depth="5px" mathbac
kground="black"/> |
| 175 </mmultiscripts> |
| 176 </math> |
| 177 </p> |
| 178 <hr/> |
| 179 </body> |
| 180 </html> |
OLD | NEW |