2d.text.drawing.style.wordSpacing.change.font.html (2056B)
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>OffscreenCanvas test: 2d.text.drawing.style.wordSpacing.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 9 <h1>2d.text.drawing.style.wordSpacing.change.font</h1> 10 <p class="desc">Set word spacing and word spacing to font dependent value and verify it works after font change.</p> 11 12 13 <script> 14 var t = async_test("Set word spacing and word spacing to font dependent value and verify it works after font change."); 15 var t_pass = t.done.bind(t); 16 var t_fail = t.step_func(function(reason) { 17 throw reason; 18 }); 19 t.step(function() { 20 21 var canvas = new OffscreenCanvas(100, 50); 22 var ctx = canvas.getContext('2d'); 23 24 _assertSame(ctx.letterSpacing, '0px', "ctx.letterSpacing", "'0px'"); 25 _assertSame(ctx.wordSpacing, '0px', "ctx.wordSpacing", "'0px'"); 26 // Get the width for 'Hello World, again' at default size, 10px. 27 var width_normal = ctx.measureText('Hello World, again').width; 28 29 ctx.wordSpacing = '1em'; 30 _assertSame(ctx.wordSpacing, '1em', "ctx.wordSpacing", "'1em'"); 31 // 1em = 10px. Add 10px after each word in "Hello World, again", 32 // makes it 20px longer. 33 var width_with_spacing = ctx.measureText('Hello World, again').width; 34 _assertSame(width_with_spacing, width_normal + 20, "width_with_spacing", "width_normal + 20"); 35 36 // Changing font to 20px. Without resetting the spacing, 1em wordSpacing 37 // is now 20px, so it's suppose to be 40px longer without any wordSpacing set. 38 ctx.font = '20px serif'; 39 width_with_spacing = ctx.measureText('Hello World, again').width; 40 // Now calculate the reference spacing for "Hello World, again" with no spacing. 41 ctx.wordSpacing = '0em'; 42 width_normal = ctx.measureText('Hello World, again').width; 43 _assertSame(width_with_spacing, width_normal + 40, "width_with_spacing", "width_normal + 40"); 44 t.done(); 45 46 }); 47 </script>