2d.text.measure.width.space.html (1796B)
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.width.space</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.width.space</h1> 18 <p class="desc">Space characters are converted to U+0020 and NOT collapsed</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 _assertSame(ctx.measureText('A B').width, 150, "ctx.measureText('A B').width", "150"); 35 _assertSame(ctx.measureText('A B').width, 200, "ctx.measureText('A B').width", "200"); 36 _assertSame(ctx.measureText('A \x09\x0a\x0c\x0d \x09\x0a\x0c\x0dB').width, 650, "ctx.measureText('A \\x09\\x0a\\x0c\\x0d \\x09\\x0a\\x0c\\x0dB').width", "650"); 37 _assert(ctx.measureText('A \x0b B').width >= 200, "ctx.measureText('A \\x0b B').width >= 200"); 38 39 _assertSame(ctx.measureText(' AB').width, 150, "ctx.measureText(' AB').width", "150"); 40 _assertSame(ctx.measureText('AB ').width, 150, "ctx.measureText('AB ').width", "150"); 41 42 }, "Space characters are converted to U+0020 and NOT collapsed"); 43 </script>