0

For example, if I do this on a 400 x 400 canvas with id of offscreen:

<canvas id="offscreen" width="400" height="400">
Your crappy browser does not support this!
</canvas>

var fauxCanvas = document.getElementById('offscreen');
var ctx = fauxCanvas.getContext("2d");
ctx.font = "bold 80px Arial";
ctx.fillStyle = "#000000";
ctx.fillText('Hello World', 10, 60);

The following doesn't work to give me the newly added text height/width!

var rawWidth = parseInt(ctx.width);
console.log("The Raw Width is "+rawWidth);

var rawHeight = parseInt(ctx.height);
console.log("The Raw Height is "+rawHeight);
Cremona
  • 1
  • 1
  • Possible dublicate: http://stackoverflow.com/questions/1134586/how-can-you-find-the-height-of-text-on-an-html-canvas – Niddro Jun 22 '15 at 06:35
  • how possibly could the canvas width/height give you the size of the text you've drawn on it ? By magic ? What about reading the specs of the context2D ? Ok, it's admittedly doing an effort, but you might encounter measureText. 4.12.4.2.12 of https://html.spec.whatwg.org/multipage/scripting.html#the-canvas-element and https://html.spec.whatwg.org/multipage/scripting.html#dom-textmetrics-fontboundingboxascent – GameAlchemist Jun 22 '15 at 10:40

0 Answers0