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

Function dedupe_chars

src/table.py:871–891  ·  view source on GitHub ↗

Removes duplicate chars — those sharing the same text, fontname, size, and positioning (within `tolerance`) as other characters in the set.

(chars: list, tolerance=1)

Source from the content-addressed store, hash-verified

869
870
871def dedupe_chars(chars: list, tolerance=1) -> list:
872 """
873 Removes duplicate chars — those sharing the same text, fontname, size,
874 and positioning (within `tolerance`) as other characters in the set.
875 """
876 key = itemgetter("fontname", "size", "upright", "text")
877 pos_key = itemgetter("doctop", "x0")
878
879 def yield_unique_chars(chars: list):
880 sorted_chars = sorted(chars, key=key)
881 for grp, grp_chars in itertools.groupby(sorted_chars, key=key):
882 for y_cluster in cluster_objects(
883 list(grp_chars), itemgetter("doctop"), tolerance
884 ):
885 for x_cluster in cluster_objects(
886 y_cluster, itemgetter("x0"), tolerance
887 ):
888 yield sorted(x_cluster, key=pos_key)[0]
889
890 deduped = yield_unique_chars(chars)
891 return sorted(deduped, key=chars.index)
892
893
894def line_to_edge(line):

Callers

nothing calls this directly

Calls 1

yield_unique_charsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…