tor-browser

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

2d.text.draw.generic.family.html (1724B)


      1 <!DOCTYPE html>
      2 <title>OffscreenCanvas test: 2d.text.draw.generic.family</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/html/canvas/resources/canvas-tests.js"></script>
      6 <script>
      7 function drawCanvas(ctx, family)
      8 {
      9    ctx.font = '16px ' + family;
     10    ctx.fillText(family, 0, 16);
     11 }
     12 
     13 function testDrawGenericFamily(family)
     14 {
     15    let offscreenCanvas = new OffscreenCanvas(88, 24);
     16    let oCtx = offscreenCanvas.getContext('2d');
     17    drawCanvas(oCtx, family);
     18    let canvas = document.createElement('canvas');
     19    let ctx = canvas.getContext('2d');
     20    drawCanvas(ctx, family);
     21 
     22    let data1 = oCtx.getImageData(0, 0, 88, 24).data;
     23    let data2 = ctx.getImageData(0, 0, 88, 24).data;
     24    assert_array_equals(data1, data2,
     25      "The image data generated by drawing generic font family '" + family +
     26      "' should be the same for both OffscreenCanvas and regular canvas");
     27 }
     28 
     29 test(function() {
     30    testDrawGenericFamily('sans-serif');
     31 }, "Test that drawing sans-serif produces the same result between canvas and OffscreenCanvas");
     32 
     33 test(function() {
     34    testDrawGenericFamily('serif');
     35 }, "Test that drawing serif produces the same result between canvas and OffscreenCanvas");
     36 
     37 test(function() {
     38    testDrawGenericFamily('cursive');
     39 }, "Test that drawing cursive produces the same result between canvas and OffscreenCanvas");
     40 
     41 test(function() {
     42    testDrawGenericFamily('fantasy');
     43 }, "Test that drawing fantasy produces the same result between canvas and OffscreenCanvas");
     44 
     45 test(function() {
     46    testDrawGenericFamily('monospace');
     47 }, "Test that drawing monospace produces the same result between canvas and OffscreenCanvas");
     48 </script>