Cut any word in pieces no longer than 'width'.
(width, words)
| 16898 | std_start = rect.x0 + tolerance |
| 16899 | |
| 16900 | def norm_words(width, words): |
| 16901 | """Cut any word in pieces no longer than 'width'.""" |
| 16902 | nwords = [] |
| 16903 | word_lengths = [] |
| 16904 | for w in words: |
| 16905 | wl_lst = char_lengths(w) |
| 16906 | wl = sum(wl_lst) |
| 16907 | if wl <= width: # nothing to do - copy over |
| 16908 | nwords.append(w) |
| 16909 | word_lengths.append(wl) |
| 16910 | continue |
| 16911 | |
| 16912 | # word longer than rect width - split it in parts |
| 16913 | n = len(wl_lst) |
| 16914 | while n > 0: |
| 16915 | wl = sum(wl_lst[:n]) |
| 16916 | if wl <= width: |
| 16917 | nwords.append(w[:n]) |
| 16918 | word_lengths.append(wl) |
| 16919 | w = w[n:] |
| 16920 | wl_lst = wl_lst[n:] |
| 16921 | n = len(wl_lst) |
| 16922 | else: |
| 16923 | n -= 1 |
| 16924 | return nwords, word_lengths |
| 16925 | |
| 16926 | def output_justify(start, line): |
| 16927 | """Justified output of a line.""" |
nothing calls this directly
no test coverage detected