MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / output_justify

Function output_justify

src_classic/utils.py:4378–4394  ·  view source on GitHub ↗

Justified output of a line.

(start, line)

Source from the content-addressed store, hash-verified

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

Callers 2

fill_textboxMethod · 0.85
fill_textboxFunction · 0.85

Calls 2

append_thisFunction · 0.85
textlenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…