<!DOCTYPE html>
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
<title>Canvas test: 2d.text.drawing.style.letterSpacing.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.letterSpacing.change.font</h1>
<p class="desc">Set letter 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 letter 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' at default size, 10px.
  var width_normal = ctx.measureText('Hello World').width;

  ctx.letterSpacing = '1em';
  _assertSame(ctx.letterSpacing, '1em', "ctx.letterSpacing", "'1em'");
  // 1em = 10px. Add 10px after each letter in "Hello World",
  // makes it 110px longer.
  var width_with_spacing = ctx.measureText('Hello World').width;
  assert_approx_equals(width_with_spacing, width_normal + 110, 0.1, "letterSpacing incorrect before font change");

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

});
</script>

