Justified output of a line.
(start, line)
| 4376 | return nwords, word_lengths |
| 4377 | |
| 4378 | def output_justify(start, line): |
| 4379 | """Justified output of a line.""" |
| 4380 | # ignore leading / trailing / multiple spaces |
| 4381 | words = [w for w in line.split(" ") if w != ""] |
| 4382 | nwords = len(words) |
| 4383 | if nwords == 0: |
| 4384 | return |
| 4385 | if nwords == 1: # single word cannot be justified |
| 4386 | append_this(start, words[0]) |
| 4387 | return |
| 4388 | tl = sum([textlen(w) for w in words]) # total word lengths |
| 4389 | gaps = nwords - 1 # number of word gaps |
| 4390 | gapl = (std_width - tl) / gaps # width of each gap |
| 4391 | for w in words: |
| 4392 | _, lp = append_this(start, w) # output one word |
| 4393 | start.x = lp.x + gapl # next start at word end plus gap |
| 4394 | return |
| 4395 | |
| 4396 | asc = font.ascender |
| 4397 | dsc = font.descender |
no test coverage detected
searching dependent graphs…