2d.text.measure.actualBoundingBox.whitespace.html (2289B)
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.actualBoundingBox.whitespace</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.actualBoundingBox.whitespace</h1> 18 <p class="desc">Testing actualBoundingBox with leading/trailing whitespace</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 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.direction = 'ltr'; 35 ctx.align = 'left' 36 ctx.baseline = 'alphabetic' 37 // Different platforms may render text slightly different. 38 // Values that are nominally expected to be zero might actually vary by a 39 // pixel or so if the UA accounts for antialiasing at glyph edges, so we 40 // allow a slight deviation. 41 var whitespaces = [0x9, 0xa, 0xc, 0xd, 0x20, 0x3000]; 42 for (var codepoint of whitespaces) { 43 let whitespace = String.fromCharCode(codepoint); 44 45 _assert(Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1, "Math.abs(ctx.measureText('A' + whitespace).actualBoundingBoxLeft) <= 1"); 46 _assert(ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50, "ctx.measureText('A' + whitespace).actualBoundingBoxRight >= 50"); 47 48 _assert(Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49, "Math.abs(ctx.measureText(whitespace + 'A').actualBoundingBoxLeft) >= 49"); 49 _assert(ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101, "ctx.measureText(whitespace + 'A').actualBoundingBoxRight <= 101"); 50 } 51 52 }, "Testing actualBoundingBox with leading/trailing whitespace"); 53 </script>