tor-browser

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

2d.text.measure.actualBoundingBox.whitespace.html (1957B)


      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.actualBoundingBox.whitespace</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.actualBoundingBox.whitespace</h1>
     10 <p class="desc">Testing actualBoundingBox with leading/trailing whitespace</p>
     11 
     12 
     13 <script>
     14 promise_test(async t => {
     15 
     16  var canvas = new OffscreenCanvas(100, 50);
     17  var ctx = canvas.getContext('2d');
     18 
     19  var f = new FontFace("CanvasTest", "url('/fonts/CanvasTest.ttf')");
     20  f.load();
     21  document.fonts.add(f);
     22  await document.fonts.ready;
     23  ctx.font = '50px CanvasTest';
     24  ctx.direction = 'ltr';
     25  ctx.align = 'left'
     26  ctx.baseline = 'alphabetic'
     27  // Different platforms may render text slightly different.
     28  // Values that are nominally expected to be zero might actually vary by a
     29  // pixel or so if the UA accounts for antialiasing at glyph edges, so we
     30  // allow a slight deviation.
     31  var whitespaces = [0x9, 0xa, 0xc, 0xd, 0x20, 0x3000];
     32  for (var codepoint of whitespaces) {
     33    let whitespace = String.fromCharCode(codepoint);
     34 
     35    _assert(Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1, "Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1");
     36    _assert(ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50, "ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50");
     37 
     38    _assert(Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49, "Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49");
     39    _assert(ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101, "ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101");
     40  }
     41 
     42 }, "Testing actualBoundingBox with leading/trailing whitespace");
     43 </script>