FontSize4TextBox

버전 1.0.0 (1.45 MB) 작성자: Peter Seibold
Find the largest possible font size that fits a text into a given static text box.
다운로드 수: 10
업데이트 날짜: 2022/6/19

라이선스 보기

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):
  1. Estimate roughly the font size by the box size and length of text.
  2. Find a small font size that fits the text inside the box. (lower limit)
  3. Find a large font size that exceeds the box size. (upper limit)
  4. Iterate between the two values until the larges possible font size is found.
By image processing:
  1. Create an invisible figure with a tall text box with the given width.
  2. Estimate font size by given box size and length of text.
  3. Set this font size in the invisible text box.
  4. Get the image content of the invisible text box by ‘getframe’
  5. 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.
  6. Decrease or increase font size until a lower and an upper limit for the font size is found.
  7. Iterate between those limits.
  8. 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.

인용 양식

Peter Seibold (2024). FontSize4TextBox (https://www.mathworks.com/matlabcentral/fileexchange/113585-fontsize4textbox), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2022a
R2016a 이상 릴리스와 호환
플랫폼 호환성
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0