I am curious is it possible to get bounding rectangle width and height of font characters with javascript?
Asked
Active
Viewed 1,592 times
3
-
2this is something you could have just googled, and you would have found several tools that do this already, like http://opentype.js.org – Mike 'Pomax' Kamermans Nov 02 '16 at 17:06
-
Thank you! I will explore it. Looks as what I was looking for! – Dmytro Nov 02 '16 at 17:51
1 Answers
2
depending on your exact implementation, you might find this useful: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/measureText
The CanvasRenderingContext2D.measureText() method returns a TextMetrics object that contains information about the measured text (such as its width for example).

Conan
- 670
- 7
- 12
-
Unfortunately: no. This API only measures the dimensions of the inline text, not of bounding box for all pixels painted by that text. The glyphs can have loads of overshoots in any direction for stylistic purposes that will not count towards the TextMetrics dimensions because they don't count "for typesetting purposes". – Mike 'Pomax' Kamermans Nov 02 '16 at 17:15