2d.text.measure.strokeTextCluster-options.tentative.html (3231B)
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.strokeTextCluster-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.strokeTextCluster-options.tentative</h1> 18 <p class="desc">Test that strokeTextCluster() 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.strokeStyle = '#0f0'; 46 ctx.lineWidth = 12; 47 48 // Override the align and baseline of the cluster. 49 ctx.strokeTextCluster(cluster, 50, 50, {align: 'right', baseline: 'bottom'}); 50 _assertPixelApprox(canvas, 5,5, 0,255,0,255, 2); 51 _assertPixelApprox(canvas, 45,5, 0,255,0,255, 2); 52 _assertPixelApprox(canvas, 5,45, 0,255,0,255, 2); 53 _assertPixelApprox(canvas, 45,45, 0,255,0,255, 2); 54 _assertPixelApprox(canvas, 5,95, 255,0,0,255, 2); 55 _assertPixelApprox(canvas, 50,95, 255,0,0,255, 2); 56 _assertPixelApprox(canvas, 95,50, 255,0,0,255, 2); 57 _assertPixelApprox(canvas, 95,5, 255,0,0,255, 2); 58 59 // Override the x and y values of the cluster. 60 ctx.strokeTextCluster(cluster, 0, 100, {x: 10, y: 10}); 61 _assertPixelApprox(canvas, 15,115, 0,255,0,255, 2); 62 _assertPixelApprox(canvas, 55,115, 0,255,0,255, 2); 63 _assertPixelApprox(canvas, 15,155, 0,255,0,255, 2); 64 _assertPixelApprox(canvas, 55,155, 0,255,0,255, 2); 65 _assertPixelApprox(canvas, 1,101, 255,0,0,255, 2); 66 _assertPixelApprox(canvas, 1,151, 255,0,0,255, 2); 67 _assertPixelApprox(canvas, 51,101, 255,0,0,255, 2); 68 69 // Override the align, baseline, x, and y values of the cluster. 70 ctx.strokeTextCluster(cluster, 50, 250, 71 {align: 'right', baseline: 'bottom', x: 10, y: 10}); 72 _assertPixelApprox(canvas, 15,215, 0,255,0,255, 2); 73 _assertPixelApprox(canvas, 55,215, 0,255,0,255, 2); 74 _assertPixelApprox(canvas, 15,255, 0,255,0,255, 2); 75 _assertPixelApprox(canvas, 55,255, 0,255,0,255, 2); 76 _assertPixelApprox(canvas, 5,295, 255,0,0,255, 2); 77 _assertPixelApprox(canvas, 50,295, 255,0,0,255, 2); 78 _assertPixelApprox(canvas, 95,250, 255,0,0,255, 2); 79 _assertPixelApprox(canvas, 95,25, 255,0,0,255, 2); 80 81 }, "Test that strokeTextCluster() correctly applies the options passed as a dictionary."); 82 </script>