Skip to content

text_frame.fit_text crashes if no wrapped representation fits in the width of the shape #936

@rianwouters

Description

@rianwouters

I have a shape with with w and height h.
The size of the first word in the text when rendered with the maximum allowed text size is bigger than w.
In that case, text_fit crashes with the stack trace below, allthough there is a smaller text size that fits.

Exception: cannot unpack non-iterable NoneType object
Traceback (most recent call last):
  File "site-packages\pptx\text\text.py", line 239, 
in _best_fit_font_size
    return TextFitter.best_fit_font_size(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages\pptx\text\layout.py", line 27, in best_fit_font_size
    return text_fitter._best_fit_font_size(max_size)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages\pptx\text\layout.py", line 36, in _best_fit_font_size
    return sizes.find_max(predicate)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages\pptx\text\layout.py", line 130, in find_max
    if predicate(self.value):
       ^^^^^^^^^^^^^^^^^^^^^
  File "site-packages\pptx\text\layout.py", line 79, in predicate
    text_lines = self._wrap_lines(self._line_source, point_size)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages\pptx\text\layout.py", line 107, in _wrap_lines
    text, remainder = self._break_line(line_source, point_size)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions