MCPcopy Create free account
hub / github.com/SpaceZephyr/myskill / _wrap_text_line

Method _wrap_text_line

pptx/scripts/inventory.py:534–560  ·  view source on GitHub ↗

Wrap a single line of text to fit within max_width_px.

(self, line: str, max_width_px: int, draw, font)

Source from the content-addressed store, hash-verified

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."""

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected