Wrap a single line of text to fit within max_width_px.
(self, line: str, max_width_px: int, draw, font)
| 532 | ) |
| 533 | |
| 534 | def _wrap_text_line(self, line: str, max_width_px: int, draw, font) -> List[str]: |
| 535 | """Wrap a single line of text to fit within max_width_px.""" |
| 536 | if not line: |
| 537 | return [""] |
| 538 | |
| 539 | # Use textlength for efficient width calculation |
| 540 | if draw.textlength(line, font=font) <= max_width_px: |
| 541 | return [line] |
| 542 | |
| 543 | # Need to wrap - split into words |
| 544 | wrapped = [] |
| 545 | words = line.split(" ") |
| 546 | current_line = "" |
| 547 | |
| 548 | for word in words: |
| 549 | test_line = current_line + (" " if current_line else "") + word |
| 550 | if draw.textlength(test_line, font=font) <= max_width_px: |
| 551 | current_line = test_line |
| 552 | else: |
| 553 | if current_line: |
| 554 | wrapped.append(current_line) |
| 555 | current_line = word |
| 556 | |
| 557 | if current_line: |
| 558 | wrapped.append(current_line) |
| 559 | |
| 560 | return wrapped |
| 561 | |
| 562 | def _estimate_frame_overflow(self) -> None: |
| 563 | """Estimate if text overflows the shape bounds using PIL text measurement.""" |
no outgoing calls
no test coverage detected