tor-browser

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

2d.text.measure.strokeTextCluster-options.tentative.worker.js (2706B)


      1 // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py.
      2 // OffscreenCanvas test in a worker:2d.text.measure.strokeTextCluster-options.tentative
      3 // Description:Test that strokeTextCluster() correctly applies the options passed as a dictionary.
      4 // Note:
      5 
      6 importScripts("/resources/testharness.js");
      7 importScripts("/html/canvas/resources/canvas-tests.js");
      8 
      9 promise_test(async t => {
     10  var canvas = new OffscreenCanvas(100, 300);
     11  var ctx = canvas.getContext('2d');
     12 
     13  var f = new FontFace("CanvasTest", "url('/fonts/CanvasTest.ttf')");
     14  f.load();
     15  self.fonts.add(f);
     16  await self.fonts.ready;
     17 
     18  ctx.font = '50px CanvasTest';
     19  ctx.textAlign = 'left';
     20  ctx.textBaseline = 'top';
     21  const text = 'E';
     22  const tm = ctx.measureText(text);
     23  const cluster = tm.getTextClusters()[0];
     24 
     25  // Background color.
     26  ctx.fillStyle = '#f00';
     27  ctx.fillRect(0, 0, canvas.width, canvas.height);
     28 
     29  ctx.strokeStyle = '#0f0';
     30  ctx.lineWidth = 12;
     31 
     32  // Override the align and baseline of the cluster.
     33  ctx.strokeTextCluster(cluster, 50, 50, {align: 'right', baseline: 'bottom'});
     34  _assertPixelApprox(canvas, 5,5, 0,255,0,255, 2);
     35  _assertPixelApprox(canvas, 45,5, 0,255,0,255, 2);
     36  _assertPixelApprox(canvas, 5,45, 0,255,0,255, 2);
     37  _assertPixelApprox(canvas, 45,45, 0,255,0,255, 2);
     38  _assertPixelApprox(canvas, 5,95, 255,0,0,255, 2);
     39  _assertPixelApprox(canvas, 50,95, 255,0,0,255, 2);
     40  _assertPixelApprox(canvas, 95,50, 255,0,0,255, 2);
     41  _assertPixelApprox(canvas, 95,5, 255,0,0,255, 2);
     42 
     43  // Override the x and y values of the cluster.
     44  ctx.strokeTextCluster(cluster, 0, 100, {x: 10, y: 10});
     45  _assertPixelApprox(canvas, 15,115, 0,255,0,255, 2);
     46  _assertPixelApprox(canvas, 55,115, 0,255,0,255, 2);
     47  _assertPixelApprox(canvas, 15,155, 0,255,0,255, 2);
     48  _assertPixelApprox(canvas, 55,155, 0,255,0,255, 2);
     49  _assertPixelApprox(canvas, 1,101, 255,0,0,255, 2);
     50  _assertPixelApprox(canvas, 1,151, 255,0,0,255, 2);
     51  _assertPixelApprox(canvas, 51,101, 255,0,0,255, 2);
     52 
     53  // Override the align, baseline, x, and y values of the cluster.
     54  ctx.strokeTextCluster(cluster, 50, 250,
     55                      {align: 'right', baseline: 'bottom', x: 10,  y: 10});
     56  _assertPixelApprox(canvas, 15,215, 0,255,0,255, 2);
     57  _assertPixelApprox(canvas, 55,215, 0,255,0,255, 2);
     58  _assertPixelApprox(canvas, 15,255, 0,255,0,255, 2);
     59  _assertPixelApprox(canvas, 55,255, 0,255,0,255, 2);
     60  _assertPixelApprox(canvas, 5,295, 255,0,0,255, 2);
     61  _assertPixelApprox(canvas, 50,295, 255,0,0,255, 2);
     62  _assertPixelApprox(canvas, 95,250, 255,0,0,255, 2);
     63  _assertPixelApprox(canvas, 95,25, 255,0,0,255, 2);
     64 }, "Test that strokeTextCluster() correctly applies the options passed as a dictionary.");
     65 done();