tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

subsup-1.html (6581B)


      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 elements msub, msup and msubsup.">
      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, "msub: subscript is after base");
     37      assert_less_than_equal(getBox("msupBase").right, getBox("msupSup").left, e, "msup: superscript is after base");
     38      assert_less_than_equal(getBox("msubsupBase").right, getBox("msubsupSub").left, e, "msubsup: subscript is after base");
     39      assert_less_than_equal(getBox("msubsupBase").right, getBox("msubsupSup").left, e, "msubsup: superscript is after base");
     40 
     41      e = 3;
     42      assert_approx_equals(getBox("msubBase").right, getBox("msubSub").left, e, "msub: space between base and subscript is small");
     43      assert_approx_equals(getBox("msubBase").right, getBox("msubSub").left, e, "msub: subscript is after base");
     44      assert_approx_equals(getBox("msupBase").right, getBox("msupSup").left, e, "msup: superscript is after base");
     45      assert_approx_equals(getBox("msubsupBase").right, getBox("msubsupSub").left, e, "msubsup: subscript is after base");
     46      assert_approx_equals(getBox("msubsupBase").right, getBox("msubsupSup").left, e, "msubsup: superscript is after base");
     47    }, "Respective horizontal positions");
     48 
     49    test(function() {
     50      assert_true(MathMLFeatureDetection.has_mspace());
     51 
     52      var e = 1;
     53      assert_approx_equals(getBox("msubBase").middle, getBox("baseline").bottom, e, "msub: base is placed on the baseline");
     54      assert_approx_equals(getBox("msupBase").middle, getBox("baseline").bottom, e, "msup: base is placed on the baseline");
     55      assert_approx_equals(getBox("msubsupBase").middle, getBox("baseline").bottom, e, "msubsup: base is placed on the baseline");
     56    }, "Alignment of the base on the baseline");
     57 
     58    test(function() {
     59      assert_true(MathMLFeatureDetection.has_mspace());
     60 
     61      assert_greater_than(getBox("msubSub").middle, getBox("msubBase").middle, "msub: script is placed at the bottom of the base");
     62      assert_less_than(getBox("msupSup").middle, getBox("msupBase").middle, "msup: script is placed at the top of the base");
     63      assert_greater_than(getBox("msubsupSub").middle, getBox("msubsupBase").middle, "msubsup: script is placed at the bottom of the base");
     64      assert_less_than(getBox("msubsupSup").middle, getBox("msubsupBase").middle, "msubsup: script is placed at the top of the base");
     65    }, "Vertical position of scripts");
     66 
     67    test(function() {
     68      assert_true(MathMLFeatureDetection.has_mspace());
     69 
     70      var e = 5;
     71      assert_approx_equals(getBox("msub").width, getBox("msubSub").right - getBox("msubBase").left, e, "msub: width is determined by the left/right sides of base/script (+ some space after script)");
     72      assert_approx_equals(getBox("msup").width, getBox("msupSup").right - getBox("msupBase").left, e, "msup: width is determined by the left/right sides of base/script (+ some space after script)");
     73      assert_approx_equals(getBox("msubsup").width, Math.max(getBox("msubsupSub").right, getBox("msubsupSup").right) - getBox("msubsupBase").left, e, "msubsup: width is determined by the left/right sides of base/scripts (+ some space after script)");
     74    }, "Width of scripted elements");
     75 
     76    test(function() {
     77      assert_true(MathMLFeatureDetection.has_mspace());
     78 
     79      var e = 1;
     80      assert_greater_than_equal(getBox("msub").height, getBox("msubBase").height, e, "msub: height is at least the one of the base");
     81      assert_greater_than_equal(getBox("msup").height, getBox("msupBase").height, e, "msup: height is at least the one of the base");
     82      assert_greater_than_equal(getBox("msubsup").height, getBox("msubsupBase").height, e, "msubsup: height is at least the one of the base");
     83 
     84      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");
     85      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");
     86      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");
     87    }, "Height of scripted elements");
     88 
     89    done();
     90  }
     91 </script>
     92 </head>
     93 <body>
     94  <div id="log"></div>
     95  <p>
     96    <math>
     97      <mspace id="baseline" width="30px" height="2px" depth="0px" style="background: blue"/>
     98      <msub id="msub" style="background: green">
     99        <mspace id="msubBase" width="30px" height="15px" depth="15px" style="background: black"/>
    100        <mspace id="msubSub" width="10px" height="5px" depth="5px" style="background: black"/>
    101      </msub>
    102      <msup id="msup" style="background: blue">
    103        <mspace id="msupBase" width="30px" height="15px" depth="15px" style="background: black"/>
    104        <mspace id="msupSup" width="10px" height="5px" depth="5px" style="background: black"/>
    105      </msup>
    106      <msubsup id="msubsup" style="background: green">
    107        <mspace id="msubsupBase" width="30px" height="15px" depth="15px" style="background: black"/>
    108        <mspace id="msubsupSub" width="10px" height="5px" depth="5px" style="background: black"/>
    109        <mspace id="msubsupSup" width="10px" height="5px" depth="5px" style="background: black"/>
    110      </msubsup>
    111    </math>
    112  </p>
    113 </body>
    114 </html>