The part of a shape that contains its text. Not all shapes have a text frame. Corresponds to the `p:txBody` element that can appear as a child element of `p:sp`. Not intended to be constructed directly.
| 34 | |
| 35 | |
| 36 | class TextFrame(Subshape): |
| 37 | """The part of a shape that contains its text. |
| 38 | |
| 39 | Not all shapes have a text frame. Corresponds to the `p:txBody` element that can |
| 40 | appear as a child element of `p:sp`. Not intended to be constructed directly. |
| 41 | """ |
| 42 | |
| 43 | def __init__(self, txBody: CT_TextBody, parent: ProvidesPart): |
| 44 | super(TextFrame, self).__init__(parent) |
| 45 | self._element = self._txBody = txBody |
| 46 | self._parent = parent |
| 47 | |
| 48 | def add_paragraph(self): |
| 49 | """ |
| 50 | Return new |_Paragraph| instance appended to the sequence of |
| 51 | paragraphs contained in this text frame. |
| 52 | """ |
| 53 | p = self._txBody.add_p() |
| 54 | return _Paragraph(p, self) |
| 55 | |
| 56 | @property |
| 57 | def auto_size(self) -> MSO_AUTO_SIZE | None: |
| 58 | """Resizing strategy used to fit text within this shape. |
| 59 | |
| 60 | Determins the type of automatic resizing used to fit the text of this shape within its |
| 61 | bounding box when the text would otherwise extend beyond the shape boundaries. May be |
| 62 | |None|, `MSO_AUTO_SIZE.NONE`, `MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT`, or |
| 63 | `MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE`. |
| 64 | """ |
| 65 | return self._bodyPr.autofit |
| 66 | |
| 67 | @auto_size.setter |
| 68 | def auto_size(self, value: MSO_AUTO_SIZE | None): |
| 69 | self._bodyPr.autofit = value |
| 70 | |
| 71 | def clear(self): |
| 72 | """Remove all paragraphs except one empty one.""" |
| 73 | for p in self._txBody.p_lst[1:]: |
| 74 | self._txBody.remove(p) |
| 75 | p = self.paragraphs[0] |
| 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|, |
no outgoing calls
searching dependent graphs…