<
body
style
=
"margin: 0px;padding: 0px;"
>
<
canvas
id
=
"myCanvas"
width
=
"550"
height
=
"200"
>
</
canvas
>
<
script
>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 3;
var y = canvas.height / 2 - 15;
var text = 'HI ';
// Set the font to set the height
context.font = '26pt Calibri';
context.textAlign = 'middle';
context.fillStyle = 'yellow';
context.fillText(text, x, y);
context.font = '20pt Calibri';
// Check the width of the text
var metrics = context.measureText(text);
var width = metrics.width;
// Text is aligned in the left
context.textAlign = 'left';
context.fillStyle = '#010';
context.fillText('(' + width
+ 'px wide)', x, y + 40);
</
script
>
</
body
>