summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/canvas-text-baseline.html
blob: b0d2467234df22848e199578606bfd5b6ff079e1 (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
<html>
<body>
<canvas id="canvas" width=600 height=300 style="border:5px solid black">
<script>
if (window.testRunner)
  testRunner.dumpAsTextWithPixelResults();

var ctx = document.getElementById('canvas').getContext('2d');

var x = 10;
var y = 150;

ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(0, 150);
ctx.lineTo(600, 150);
ctx.closePath();
ctx.stroke();

ctx.font = "32px 'Times New Roman'";

var text = "Baseline";
var w = ctx.measureText(text).width;
ctx.fillText(text, x, y);
x += w + 10;

text = "Top";
ctx.textBaseline = "top";
w = ctx.measureText(text).width;
ctx.fillText(text, x, y);
x += w + 10;

text = "Bottom";
ctx.textBaseline = "bottom";
w = ctx.measureText(text).width;
ctx.fillText(text, x, y);
x += w + 10;

text = "Middle";
ctx.textBaseline = "middle";
w = ctx.measureText(text).width;
ctx.fillText(text, x, y);
x += w + 10;

</script>