Justified output of a line.
(start, line)
| 16924 | return nwords, word_lengths |
| 16925 | |
| 16926 | def output_justify(start, line): |
| 16927 | """Justified output of a line.""" |
| 16928 | # ignore leading / trailing / multiple spaces |
| 16929 | words = [w for w in line.split(" ") if w != ""] |
| 16930 | nwords = len(words) |
| 16931 | if nwords == 0: |
| 16932 | return |
| 16933 | if nwords == 1: # single word cannot be justified |
| 16934 | append_this(start, words[0]) |
| 16935 | return |
| 16936 | tl = sum([textlen(w) for w in words]) # total word lengths |
| 16937 | gaps = nwords - 1 # number of word gaps |
| 16938 | gapl = (std_width - tl) / gaps # width of each gap |
| 16939 | for w in words: |
| 16940 | _, lp = append_this(start, w) # output one word |
| 16941 | start.x = lp.x + gapl # next start at word end plus gap |
| 16942 | return |
| 16943 | |
| 16944 | asc = font.ascender |
| 16945 | dsc = font.descender |
nothing calls this directly
no test coverage detected