FontSize4TextBox
Versión 1.0.0 (1,45 MB) por
Peter Seibold
Find the largest possible font size that fits a text into a given static text box.
Purpose
Find the largest possible font size that fits a text into a given static text box.
Features
- 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
Method
For a single line find the largest font size by extent (very fast) or by image processing (exact).
For multiple lines find the largest font size by image processing.
By extent (very fast):
- 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.
By image processing:
- 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.
Restrictions
- 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.
Usage
The code file ‘FontSize4TextBoxSingleLine.m’ is for a single line of text.
The code file ‘FontSize4TextBoxMultiLine.m’ is for multiple lines of text.
A third file, ‘DemoFontSize4TextBox.m’, is for demonstration and evaluation.
Inside the first two files you will find advices on how to use them. Also the demo-file displays the appropriate commands.
For more information, please read the enclosed pdf-file.
Citar como
Peter Seibold (2024). FontSize4TextBox (https://www.mathworks.com/matlabcentral/fileexchange/113585-fontsize4textbox), MATLAB Central File Exchange. Recuperado .
Compatibilidad con la versión de MATLAB
Se creó con
R2022a
Compatible con cualquier versión desde R2016a
Compatibilidad con las plataformas
Windows macOS LinuxEtiquetas
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Descubra Live Editor
Cree scripts con código, salida y texto formateado en un documento ejecutable.
Versión | Publicado | Notas de la versión | |
---|---|---|---|
1.0.0 |