Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pptx/text/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,20 @@ def __eq__(self, other):

def __iter__(self):
"""
Generate a (text, remainder) pair for each possible even-word line
Generate a (text, remainder) pair for each possible line
break in this line source, where *text* is a str value and remainder
is a |_LineSource| value.
is a |_LineSource| value. Line breaks are possible between each word
or between characters of the first word.
"""

words = self._text.split()
first_word = words[0]
# If the first word is long, we can linebreak in the middle of it
for idx in range(1, len(first_word)):
line_text = first_word[:idx]
remainder_text = ' '.join([first_word[idx:]] + words[1:])
remainder = _LineSource(remainder_text)
yield _Line(line_text, remainder)
for idx in range(1, len(words)+1):
line_text = ' '.join(words[:idx])
remainder_text = ' '.join(words[idx:])
Expand Down
2 changes: 2 additions & 0 deletions tests/text/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ class Describe_LineSource(object):
def it_generates_text_remainder_pairs(self):
line_source = _LineSource('foo bar baz')
expected = (
('f', _LineSource('oo bar baz')),
('fo', _LineSource('o bar baz')),
('foo', _LineSource('bar baz')),
('foo bar', _LineSource('baz')),
('foo bar baz', _LineSource('')),
Expand Down