2d.text.drawing.style.letterSpacing.change.font.html (2120B)
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.drawing.style.letterSpacing.change.font</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 <body class="show_output"> 10 11 <h1>2d.text.drawing.style.letterSpacing.change.font</h1> 12 <p class="desc">Set letter spacing and word spacing to font dependent value and verify it works after font change.</p> 13 14 15 <p class="output">Actual output:</p> 16 <canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas> 17 18 <ul id="d"></ul> 19 <script> 20 var t = async_test("Set letter spacing and word spacing to font dependent value and verify it works after font change."); 21 _addTest(function(canvas, ctx) { 22 23 _assertSame(ctx.letterSpacing, '0px', "ctx.letterSpacing", "'0px'"); 24 _assertSame(ctx.wordSpacing, '0px', "ctx.wordSpacing", "'0px'"); 25 // Get the width for 'Hello World' at default size, 10px. 26 var width_normal = ctx.measureText('Hello World').width; 27 28 ctx.letterSpacing = '1em'; 29 _assertSame(ctx.letterSpacing, '1em', "ctx.letterSpacing", "'1em'"); 30 // 1em = 10px. Add 10px after each letter in "Hello World", 31 // makes it 110px longer. 32 var width_with_spacing = ctx.measureText('Hello World').width; 33 assert_approx_equals(width_with_spacing, width_normal + 110, 0.1, "letter-spacing error"); 34 35 // Changing font to 20px. Without resetting the spacing, 1em letterSpacing 36 // is now 20px, so it's suppose to be 220px longer without any letterSpacing set. 37 ctx.font = '20px serif'; 38 width_with_spacing = ctx.measureText('Hello World').width; 39 // Now calculate the reference spacing for "Hello World" with no spacing. 40 ctx.letterSpacing = '0em'; 41 width_normal = ctx.measureText('Hello World').width; 42 assert_approx_equals(width_with_spacing, width_normal + 220, 0.1, "letter-spacing error after font change"); 43 44 }); 45 </script>