Correlation between 'FontSize' for "insertText" function and resulting letter/textbox height in pixels?
5 views (last 30 days)
Show older comments
MathWorks Support Team
on 16 Oct 2018
Edited: MathWorks Support Team
on 26 Oct 2021
What is the correlation between 'FontSize' for "insertText" function and resulting letter/textbox height in pixels?
I would like to specify the size of the letters in pixels. For instance, I want the Letter 'A' to be x pixels high. I do not know how to achieve this using the 'FontSize' parameter as the correlation between the font size and the letter/textbox height in pixels is unknown. For instance what does 12 point font equal in pixels for the "insertText" function?
Accepted Answer
MathWorks Support Team
on 22 Oct 2021
Edited: MathWorks Support Team
on 26 Oct 2021
The "insertText" function uses TrueType fonts to render the text. TrueType is software that is embedded in both Windows and Mac operating systems and is outside of MATLAB. Currently there is no way for "insertText" to request the font height in pixels using the underling rendering library. However, once the font is rendered, the "insertText" function will "know" the font height in pixels but this value is currently inaccessible from outside the function.
As a workaround, you can measure the number of pixels of the output text to get the relationship between font height in pixels and the font size.
The workaround steps are as follows:
1. Select whatever string you wish to render.
2. Set the 'BoxOpacity' parameter of "insertText" to 1 to see the background box.
3. Use "imtool" function to measure the height of the box. "imtool" doc is linked below:
0 Comments
More Answers (0)
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!