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

Method iter_sort_chars

src/table.py:760–782  ·  view source on GitHub ↗
(self, chars)

Source from the content-addressed store, hash-verified

758 yield current_word
759
760 def iter_sort_chars(self, chars):
761 def upright_key(x) -> int:
762 return -int(x["upright"])
763
764 for upright_cluster in cluster_objects(list(chars), upright_key, 0):
765 upright = upright_cluster[0]["upright"]
766 cluster_key = "doctop" if upright else "x0"
767
768 # Cluster by line
769 subclusters = cluster_objects(
770 upright_cluster, itemgetter(cluster_key), self.y_tolerance
771 )
772
773 for sc in subclusters:
774 # Sort within line
775 sort_key = "x0" if upright else "doctop"
776 to_yield = sorted(sc, key=itemgetter(sort_key))
777
778 # Reverse order if necessary
779 if not (self.horizontal_ltr if upright else self.vertical_ttb):
780 yield from reversed(to_yield)
781 else:
782 yield from to_yield
783
784 def iter_extract_tuples(self, chars):
785 ordered_chars = chars if self.use_text_flow else self.iter_sort_chars(chars)

Callers 1

iter_extract_tuplesMethod · 0.95

Calls 1

cluster_objectsFunction · 0.85

Tested by

no test coverage detected