I'm working with canvases and i can't think of any solution, or find answer on line to my problem.
I have a font that contains symbols\characters from varies sizes - heights and width.
I want to draw some characters (Symbols) from the font and some on top\down of the symbol. The problem is that I can't figure out a way to have the exact height in pixels of the character that i'm drawing, and it's causes unwanted spaces between the center symbol to the one on top\down (for getting the width of a string there is the function context.measureText(theText) ).
for ex. lets say that i want 'X' to be my center symbol. and '-' to be on top. It's looks like this
-
x
but now there is space between the 'X' and the '-' that i don't want.
Can anyone help me with this ?
Thanks
Width is easy: canvas's context has a built in metric for measuring text width.
Height is more difficult because measureText doesn't compute height.
You can often use the font size to approximate the height--that's what I do.
But if you really need more accuracy here is a function that examines the text's pixels to calculate its height:
Just to build upon the previous good answers here. This will give the height and width (I had some problems with some of the unicode characters and measureText, this was the only solution for some characters).
Ok, well tried this code and i had to change it a bit for make it work.
this is the code after we found the last line with non-transparent pixel.
so In case someone needs it. just replace Enjoy.