Wrap text by character count (no PIL font needed).
(text, max_chars=40, **kwargs)
| 122 | original_wrap = shared_data.wrap_text |
| 123 | |
| 124 | def wrap_text_pager(text, max_chars=40, **kwargs): |
| 125 | """Wrap text by character count (no PIL font needed).""" |
| 126 | lines = [] |
| 127 | words = text.split() |
| 128 | line = '' |
| 129 | for word in words: |
| 130 | if len(line) + len(word) + 1 <= max_chars: |
| 131 | line = line + (' ' if line else '') + word |
| 132 | else: |
| 133 | if line: |
| 134 | lines.append(line) |
| 135 | line = word |
| 136 | if line: |
| 137 | lines.append(line) |
| 138 | return lines |
| 139 | |
| 140 | shared_data.wrap_text = wrap_text_pager |
| 141 |