2d.text.measure.strokeTextCluster-range.tentative.html (2837B)
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-range.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-range.tentative</h1> 18 <p class="desc">Test that getTextClusters() and strokeTextCluster() correctly render different ranges of the input text.</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="400" 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 // Renders all the clusters in the list from position (x, y). 33 function renderClusters(clusters, x, y) { 34 for (const cluster of clusters) { 35 ctx.strokeTextCluster(cluster, x, y); 36 } 37 } 38 39 await document.fonts.ready; 40 41 ctx.font = '50px CanvasTest'; 42 ctx.textAlign = 'left'; 43 ctx.textBaseline = 'top'; 44 const text = 'EEEEE'; 45 let tm = ctx.measureText(text); 46 47 // Background color. 48 ctx.fillStyle = '#f00'; 49 ctx.fillRect(0, 0, canvas.width, canvas.height); 50 51 ctx.strokeStyle = '#0f0'; 52 ctx.lineWidth = 12; 53 54 // Without the first character. 55 renderClusters(tm.getTextClusters(1, 5), 0, 0); 56 _assertPixelApprox(canvas, 5,5, 255,0,0,255, 2); 57 _assertPixelApprox(canvas, 55,5, 0,255,0,255, 2); 58 _assertPixelApprox(canvas, 105,5, 0,255,0,255, 2); 59 _assertPixelApprox(canvas, 155,5, 0,255,0,255, 2); 60 _assertPixelApprox(canvas, 205,5, 0,255,0,255, 2); 61 // Without the last character. 62 renderClusters(tm.getTextClusters(0, 4), 0, 100); 63 _assertPixelApprox(canvas, 5,105, 0,255,0,255, 2); 64 _assertPixelApprox(canvas, 55,105, 0,255,0,255, 2); 65 _assertPixelApprox(canvas, 105,105, 0,255,0,255, 2); 66 _assertPixelApprox(canvas, 155,105, 0,255,0,255, 2); 67 _assertPixelApprox(canvas, 245,105, 255,0,0,255, 2); 68 // Only the middle character. 69 renderClusters(tm.getTextClusters(2, 3), 0, 200); 70 _assertPixelApprox(canvas, 5,205, 255,0,0,255, 2); 71 _assertPixelApprox(canvas, 55,205, 255,0,0,255, 2); 72 _assertPixelApprox(canvas, 105,205, 0,255,0,255, 2); 73 _assertPixelApprox(canvas, 195,205, 255,0,0,255, 2); 74 _assertPixelApprox(canvas, 245,205, 255,0,0,255, 2); 75 76 }, "Test that getTextClusters() and strokeTextCluster() correctly render different ranges of the input text."); 77 </script>