2d.text.draw.baseline.top.html (1772B)
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.draw.baseline.top</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.draw.baseline.top</h1> 18 <p class="desc">textBaseline top is the top of the em square (not the bounding box)</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="50"><p class="fallback">FAIL (fallback content)</p></canvas> 24 <p class="output expectedtext">Expected output:<p><img src="/images/green-100x50.png" class="output expected" id="expected" alt=""> 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 ctx.font = '50px CanvasTest'; 34 ctx.fillStyle = '#f00'; 35 ctx.fillRect(0, 0, 100, 50); 36 ctx.fillStyle = '#0f0'; 37 ctx.textBaseline = 'top'; 38 ctx.fillText('CC', 0, 0); 39 _assertPixelApprox(canvas, 5,5, 0,255,0,255, 2); 40 _assertPixelApprox(canvas, 95,5, 0,255,0,255, 2); 41 _assertPixelApprox(canvas, 25,25, 0,255,0,255, 2); 42 _assertPixelApprox(canvas, 75,25, 0,255,0,255, 2); 43 _assertPixelApprox(canvas, 5,45, 0,255,0,255, 2); 44 _assertPixelApprox(canvas, 95,45, 0,255,0,255, 2); 45 46 }, "textBaseline top is the top of the em square (not the bounding box)"); 47 </script>