Cut any word in pieces no longer than 'width'.
(width, words)
| 4350 | std_start = rect.x0 + tolerance |
| 4351 | |
| 4352 | def norm_words(width, words): |
| 4353 | """Cut any word in pieces no longer than 'width'.""" |
| 4354 | nwords = [] |
| 4355 | word_lengths = [] |
| 4356 | for w in words: |
| 4357 | wl_lst = char_lengths(w) |
| 4358 | wl = sum(wl_lst) |
| 4359 | if wl <= width: # nothing to do - copy over |
| 4360 | nwords.append(w) |
| 4361 | word_lengths.append(wl) |
| 4362 | continue |
| 4363 | |
| 4364 | # word longer than rect width - split it in parts |
| 4365 | n = len(wl_lst) |
| 4366 | while n > 0: |
| 4367 | wl = sum(wl_lst[:n]) |
| 4368 | if wl <= width: |
| 4369 | nwords.append(w[:n]) |
| 4370 | word_lengths.append(wl) |
| 4371 | w = w[n:] |
| 4372 | wl_lst = wl_lst[n:] |
| 4373 | n = len(wl_lst) |
| 4374 | else: |
| 4375 | n -= 1 |
| 4376 | return nwords, word_lengths |
| 4377 | |
| 4378 | def output_justify(start, line): |
| 4379 | """Justified output of a line.""" |
no test coverage detected
searching dependent graphs…