functionmeasureTextHeight(fontSizeFace){// create a temp canvas
varwidth=1000;varheight=60;varcanvas=document.createElement("canvas");canvas.width=width;canvas.height=height;varctx=canvas.getContext("2d");// Draw the entire a-z/A-Z alphabet in the canvas
vartext="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";ctx.save();ctx.font=fontSizeFace;ctx.clearRect(0,0,width,height);ctx.fillText(text,0,40);ctx.restore();// Get the pixel data from the canvas
vardata=ctx.getImageData(0,0,width,height).data,first=false,last=false,r=height,c=0;// Find the last line with a non-transparent pixel
while(!last&&r){r--;for(c=0;c<width;c++){if(data[r*width*4+c*4+3]){last=r;break;}}}// Find the first line with a non-transparent pixel
while(r){r--;for(c=0;c<width;c++){if(data[r*width*4+c*4+3]){first=r;break;}}// If we've got it then return the height
if(first!=r)returnlast-first;}// error condition if we get here
return0;}