tor-browser

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

2d.text.measure.selection-rects-baselines.tentative.html (2736B)


      1 <!DOCTYPE html>
      2 <!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
      3 <meta charset="UTF-8">
      4 <title>OffscreenCanvas test: 2d.text.measure.selection-rects-baselines.tentative</title>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/html/canvas/resources/canvas-tests.js"></script>
      8 
      9 <h1>2d.text.measure.selection-rects-baselines.tentative</h1>
     10 <p class="desc">Check that TextMetrics::getSelectionRects() works correctly with textBaseline.</p>
     11 
     12 
     13 <script>
     14 var t = async_test("Check that TextMetrics::getSelectionRects() works correctly with textBaseline.");
     15 var t_pass = t.done.bind(t);
     16 var t_fail = t.step_func(function(reason) {
     17    throw reason;
     18 });
     19 t.step(function() {
     20 
     21  var canvas = new OffscreenCanvas(100, 50);
     22  var ctx = canvas.getContext('2d');
     23 
     24  ctx.font = '50px sans-serif';
     25 
     26  const kBaselines = [
     27    "top",
     28    "hanging",
     29    "middle",
     30    "alphabetic",
     31    "ideographic",
     32    "bottom",
     33  ];
     34 
     35  const kTexts = [
     36    'UNAVAILABLE',
     37    '🏁🎶🏁',
     38    ')(あ)(',
     39    '-abcd_',
     40    'איפה הספרייה?',
     41    'bidiמתמטיקה'
     42  ]
     43 
     44  for (const text of kTexts) {
     45    for (const baseline of kBaselines) {
     46      const tm = ctx.measureText(text);
     47      // First character.
     48      for (const r of tm.getSelectionRects(0, 1)) {
     49        assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0);
     50        assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0);
     51      }
     52      // Last character.
     53      for (const r of tm.getSelectionRects(text.length - 1, text.length)) {
     54        assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0);
     55        assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0);
     56      }
     57      // Whole string.
     58      for (const r of tm.getSelectionRects(0, text.length)) {
     59        assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0);
     60        assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0);
     61      }
     62      // Intermediate string.
     63      for (const r of tm.getSelectionRects(1, text.length - 1)) {
     64        assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0);
     65        assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0);
     66      }
     67      // Invalid start > end string. Creates 0 width rectangle.
     68      for (const r of tm.getSelectionRects(3, 2)) {
     69        assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0);
     70        assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0);
     71      }
     72      for (const r of tm.getSelectionRects(1, 0)) {
     73        assert_approx_equals(r.top, -tm.fontBoundingBoxAscent, 1.0);
     74        assert_approx_equals(r.bottom, tm.fontBoundingBoxDescent, 1.0);
     75      }
     76    }
     77  }
     78  t.done();
     79 
     80 });
     81 </script>