- Find the largest possible font size for a single line of text. File: FontSize4TextBoxSingleLine.m
- Find the largest possible font size for multi lines of text. File: FontSize4TextBoxMultiLine.m
- Estimate roughly the font size by the box size and length of text.
- Find a small font size that fits the text inside the box. (lower limit)
- Find a large font size that exceeds the box size. (upper limit)
- Iterate between the two values until the larges possible font size is found.
- Create an invisible figure with a tall text box with the given width.
- Estimate font size by given box size and length of text.
- Set this font size in the invisible text box.
- Get the image content of the invisible text box by ‘getframe’
- Analyze the content: Font size too small, if position of last vertical text pixel smaller than given box height, Font size too large, if position of last vertical text pixel larger than given box height.
- Decrease or increase font size until a lower and an upper limit for the font size is found.
- Iterate between those limits.
- Do some post processing like overcome discontinuities, try some higher font sizes, etc.
- Leading or trailing spaces discarded.
- Static text box height limited to approx. 1/3 screen height.
- Normalized units for font size or box size not supported.
- Right alignment, especially with tall boxes, not well supported.
Peter Seibold (2023). FontSize4TextBox (https://www.mathworks.com/matlabcentral/fileexchange/113585-fontsize4textbox), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!