summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/canvas/element/text/2d.text.drawing.style.wordSpacing.change.font.html
blob: 8bad1a0447cba76e0f6178678ddd588f2af07c65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.text.drawing.style.wordSpacing.change.font</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/html/canvas/resources/canvas-tests.js"></script>
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
<body class="show_output">

<h1>2d.text.drawing.style.wordSpacing.change.font</h1>
<p class="desc">Set word spacing and word spacing to font dependent value and verify it works after font change.</p>


<p class="output">Actual output:</p>
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>

<ul id="d"></ul>
<script>
var t = async_test("Set word spacing and word spacing to font dependent value and verify it works after font change.");
_addTest(function(canvas, ctx) {

  _assertSame(ctx.letterSpacing, '0px', "ctx.letterSpacing", "'0px'");
  _assertSame(ctx.wordSpacing, '0px', "ctx.wordSpacing", "'0px'");
  // Get the width for 'Hello World, again' at default size, 10px.
  var width_normal = ctx.measureText('Hello World, again').width;

  ctx.wordSpacing = '1em';
  _assertSame(ctx.wordSpacing, '1em', "ctx.wordSpacing", "'1em'");
  // 1em = 10px. Add 10px after each word in "Hello World, again",
  // makes it 20px longer.
  var width_with_spacing = ctx.measureText('Hello World, again').width;
  _assertSame(width_with_spacing, width_normal + 20, "width_with_spacing", "width_normal + 20");

  // Changing font to 20px. Without resetting the spacing, 1em wordSpacing
  // is now 20px, so it's suppose to be 40px longer without any wordSpacing set.
  ctx.font = '20px serif';
  width_with_spacing = ctx.measureText('Hello World, again').width;
  // Now calculate the reference spacing for "Hello World, again" with no spacing.
  ctx.wordSpacing = '0em';
  width_normal = ctx.measureText('Hello World, again').width;
  _assertSame(width_with_spacing, width_normal + 40, "width_with_spacing", "width_normal + 40");

});
</script>