tor-browser

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

2d.text.measure.index-from-offset-edge-cases.tentative.html (2735B)


      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>Canvas test: 2d.text.measure.index-from-offset-edge-cases.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 <link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
      9 <style>
     10 @font-face {
     11  font-family: CanvasTest;
     12  src: url("/fonts/CanvasTest.ttf");
     13 }
     14 </style>
     15 <body class="show_output">
     16 
     17 <h1>2d.text.measure.index-from-offset-edge-cases.tentative</h1>
     18 <p class="desc">Test the edge cases for getIndexFromOffset, where the point is at the edge of glyph and at the midpoint.</p>
     19 
     20 
     21 <span style="font-family: CanvasTest; position: absolute; visibility: hidden">A</span>
     22 <p class="output">Actual output:</p>
     23 <canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
     24 
     25 <ul id="d"></ul>
     26 <script>
     27 promise_test(async t => {
     28 
     29  var canvas = document.getElementById('c');
     30  var ctx = canvas.getContext('2d');
     31 
     32  await document.fonts.ready;
     33  ctx.font = '50px CanvasTest';
     34  ctx.direction = 'ltr';
     35  ctx.align = 'left'
     36  ctx.baseline = 'alphabetic'
     37  tm = ctx.measureText('A');
     38  const a_width = tm.width;
     39  tm = ctx.measureText('B');
     40  const b_width = tm.width;
     41  tm = ctx.measureText('C');
     42  const c_width = tm.width;
     43  const epsilon = 1.0e-4;
     44 
     45  tm = ctx.measureText('ABC');
     46  _assert(tm.getIndexFromOffset(0) == 0, "tm.getIndexFromOffset(0) == 0");
     47  _assert(tm.getIndexFromOffset(a_width / 2) == 0, "tm.getIndexFromOffset(a_width / 2) == 0");
     48  _assert(tm.getIndexFromOffset(a_width / 2 + 1) == 1, "tm.getIndexFromOffset(a_width / 2 + 1) == 1");
     49  _assert(tm.getIndexFromOffset(a_width) == 1, "tm.getIndexFromOffset(a_width) == 1");
     50  _assert(tm.getIndexFromOffset(a_width + b_width / 2) == 1, "tm.getIndexFromOffset(a_width + b_width / 2) == 1");
     51  _assert(tm.getIndexFromOffset(a_width + b_width / 2 + 1) == 2, "tm.getIndexFromOffset(a_width + b_width / 2 + 1) == 2");
     52  _assert(tm.getIndexFromOffset(a_width + b_width) == 2, "tm.getIndexFromOffset(a_width + b_width) == 2");
     53  _assert(tm.getIndexFromOffset(a_width + b_width + c_width / 2) == 2, "tm.getIndexFromOffset(a_width + b_width + c_width / 2) == 2");
     54  _assert(tm.getIndexFromOffset(a_width + b_width + c_width / 2 + 1) == 3, "tm.getIndexFromOffset(a_width + b_width + c_width / 2 + 1) == 3");
     55  _assert(tm.getIndexFromOffset(a_width + b_width + c_width) == 3, "tm.getIndexFromOffset(a_width + b_width + c_width) == 3");
     56 
     57 }, "Test the edge cases for getIndexFromOffset, where the point is at the edge of glyph and at the midpoint.");
     58 </script>