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

Method output_justify

src/__init__.py:16926–16942  ·  view source on GitHub ↗

Justified output of a line.

(start, line)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

append_thisFunction · 0.85
textlenFunction · 0.85

Tested by

no test coverage detected