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

Function norm_words

src_classic/utils.py:4352–4376  ·  view source on GitHub ↗

Cut any word in pieces no longer than 'width'.

(width, words)

Source from the content-addressed store, hash-verified

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."""

Callers 2

fill_textboxMethod · 0.85
fill_textboxFunction · 0.85

Calls 2

char_lengthsFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…