Fit text-frame text entirely within bounds of its shape. Make the text in this text frame fit entirely within the bounds of its shape by setting word wrap on and applying the "best-fit" font size to all the text it contains. :attr:`TextFrame.auto_size` is set to :attr:`MSO_
(
self,
font_family: str = "Calibri",
max_size: int = 18,
bold: bool = False,
italic: bool = False,
font_file: str | None = None,
)
| 76 | p.clear() |
| 77 | |
| 78 | def fit_text( |
| 79 | self, |
| 80 | font_family: str = "Calibri", |
| 81 | max_size: int = 18, |
| 82 | bold: bool = False, |
| 83 | italic: bool = False, |
| 84 | font_file: str | None = None, |
| 85 | ): |
| 86 | """Fit text-frame text entirely within bounds of its shape. |
| 87 | |
| 88 | Make the text in this text frame fit entirely within the bounds of its shape by setting |
| 89 | word wrap on and applying the "best-fit" font size to all the text it contains. |
| 90 | |
| 91 | :attr:`TextFrame.auto_size` is set to :attr:`MSO_AUTO_SIZE.NONE`. The font size will not |
| 92 | be set larger than `max_size` points. If the path to a matching TrueType font is provided |
| 93 | as `font_file`, that font file will be used for the font metrics. If `font_file` is |None|, |
| 94 | best efforts are made to locate a font file with matchhing `font_family`, `bold`, and |
| 95 | `italic` installed on the current system (usually succeeds if the font is installed). |
| 96 | """ |
| 97 | # ---no-op when empty as fit behavior not defined for that case--- |
| 98 | if self.text == "": |
| 99 | return # pragma: no cover |
| 100 | |
| 101 | font_size = self._best_fit_font_size(font_family, max_size, bold, italic, font_file) |
| 102 | self._apply_fit(font_family, font_size, bold, italic) |
| 103 | |
| 104 | @property |
| 105 | def margin_bottom(self) -> Length: |