2d.text.measure.fillTextCluster-range.tentative.html (2803B)
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-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.fillTextCluster-range.tentative</h1> 18 <p class="desc">Test that getTextClusters() and fillTextCluster() 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.fillTextCluster(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.fillStyle = '#0f0'; 52 53 // Without the first character. 54 renderClusters(tm.getTextClusters(1, 5), 0, 0); 55 _assertPixelApprox(canvas, 5,5, 255,0,0,255, 2); 56 _assertPixelApprox(canvas, 55,5, 0,255,0,255, 2); 57 _assertPixelApprox(canvas, 105,5, 0,255,0,255, 2); 58 _assertPixelApprox(canvas, 155,5, 0,255,0,255, 2); 59 _assertPixelApprox(canvas, 205,5, 0,255,0,255, 2); 60 // Without the last character. 61 renderClusters(tm.getTextClusters(0, 4), 0, 100); 62 _assertPixelApprox(canvas, 5,105, 0,255,0,255, 2); 63 _assertPixelApprox(canvas, 55,105, 0,255,0,255, 2); 64 _assertPixelApprox(canvas, 105,105, 0,255,0,255, 2); 65 _assertPixelApprox(canvas, 155,105, 0,255,0,255, 2); 66 _assertPixelApprox(canvas, 205,105, 255,0,0,255, 2); 67 // Only the middle character. 68 renderClusters(tm.getTextClusters(2, 3), 0, 150); 69 _assertPixelApprox(canvas, 5,155, 255,0,0,255, 2); 70 _assertPixelApprox(canvas, 55,155, 255,0,0,255, 2); 71 _assertPixelApprox(canvas, 105,155, 0,255,0,255, 2); 72 _assertPixelApprox(canvas, 155,155, 255,0,0,255, 2); 73 _assertPixelApprox(canvas, 205,155, 255,0,0,255, 2); 74 75 }, "Test that getTextClusters() and fillTextCluster() correctly render different ranges of the input text."); 76 </script>