FontSize4TextBox
Version 1.0.0 (1,45 MB) von
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.
Zitieren als
Peter Seibold (2024). FontSize4TextBox (https://www.mathworks.com/matlabcentral/fileexchange/113585-fontsize4textbox), MATLAB Central File Exchange. Abgerufen .
Kompatibilität der MATLAB-Version
Erstellt mit
R2022a
Kompatibel mit R2016a und späteren Versionen
Plattform-Kompatibilität
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
1.0.0 |