tor-browser

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

2d.text.measure.fillTextCluster-options.tentative.html (3090B)


      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.fillTextCluster-options.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.fillTextCluster-options.tentative</h1>
     18 <p class="desc">Test that fillTextCluster() correctly applies the options passed as a dictionary.</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="300"><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 
     34  ctx.font = '50px CanvasTest';
     35  ctx.textAlign = 'left';
     36  ctx.textBaseline = 'top';
     37  const text = 'E';
     38  const tm = ctx.measureText(text);
     39  const cluster = tm.getTextClusters()[0];
     40 
     41  // Background color.
     42  ctx.fillStyle = '#f00';
     43  ctx.fillRect(0, 0, canvas.width, canvas.height);
     44 
     45  ctx.fillStyle = '#0f0';
     46 
     47  // Override the align and baseline of the cluster.
     48  ctx.fillTextCluster(cluster, 50, 50, {align: 'right', baseline: 'bottom'});
     49  _assertPixelApprox(canvas, 5,5, 0,255,0,255, 2);
     50  _assertPixelApprox(canvas, 45,5, 0,255,0,255, 2);
     51  _assertPixelApprox(canvas, 5,45, 0,255,0,255, 2);
     52  _assertPixelApprox(canvas, 45,45, 0,255,0,255, 2);
     53  _assertPixelApprox(canvas, 55,5, 255,0,0,255, 2);
     54  _assertPixelApprox(canvas, 5,55, 255,0,0,255, 2);
     55  _assertPixelApprox(canvas, 55,55, 255,0,0,255, 2);
     56 
     57  // Override the x and y values of the cluster.
     58  ctx.fillTextCluster(cluster, 0, 100, {x: 10, y: 10});
     59  _assertPixelApprox(canvas, 15,115, 0,255,0,255, 2);
     60  _assertPixelApprox(canvas, 55,115, 0,255,0,255, 2);
     61  _assertPixelApprox(canvas, 15,155, 0,255,0,255, 2);
     62  _assertPixelApprox(canvas, 55,155, 0,255,0,255, 2);
     63  _assertPixelApprox(canvas, 65,115, 255,0,0,255, 2);
     64  _assertPixelApprox(canvas, 15,165, 255,0,0,255, 2);
     65  _assertPixelApprox(canvas, 65,165, 255,0,0,255, 2);
     66 
     67  // Override the align, baseline, x, and y values of the cluster.
     68  ctx.fillTextCluster(cluster, 50, 250,
     69                      {align: 'right', baseline: 'bottom', x: 10,  y: 10});
     70  _assertPixelApprox(canvas, 15,215, 0,255,0,255, 2);
     71  _assertPixelApprox(canvas, 55,215, 0,255,0,255, 2);
     72  _assertPixelApprox(canvas, 15,255, 0,255,0,255, 2);
     73  _assertPixelApprox(canvas, 55,255, 0,255,0,255, 2);
     74  _assertPixelApprox(canvas, 65,215, 255,0,0,255, 2);
     75  _assertPixelApprox(canvas, 15,265, 255,0,0,255, 2);
     76  _assertPixelApprox(canvas, 65,265, 255,0,0,255, 2);
     77 
     78 }, "Test that fillTextCluster() correctly applies the options passed as a dictionary.");
     79 </script>