How would I get the area occupied by a filled ctx.font
? For example:
All my research points to baseline and ctx.measureText(word);
which gives me the width (perfectly, I should add) but the height is something I'm really struggling with, as descenders seem to always be included in the calculation.
Can I bitmap the font and then calculate the scale that way?
Here is a (failing) canvas size function I was using:
function textSize(word, size){
var div = document.createElement("div");
div.innerHTML = word;
div.style.position = 'absolute';
div.style.fontFamily = 'serif';
div.style.fontWeight = 'normal';
div.style.fontSize = size + 'px';
document.body.appendChild(div);
var size = {
'width': div.offsetWidth,
'height': div.offsetHeight
};
return size; // size.height would be much larger than required with fonts with no descenders
}