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

Method get_edges

src/table.py:2052–2149  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2050 ]
2051
2052 def get_edges(self) -> list:
2053 settings = self.settings
2054
2055 for orientation in ["vertical", "horizontal"]:
2056 strategy = getattr(settings, orientation + "_strategy")
2057 if strategy == "explicit":
2058 lines = getattr(settings, "explicit_" + orientation + "_lines")
2059 if len(lines) < 2:
2060 raise ValueError(
2061 f"If {orientation}_strategy == 'explicit', "
2062 f"explicit_{orientation}_lines "
2063 f"must be specified as a list/tuple of two or more "
2064 f"floats/ints."
2065 )
2066
2067 v_strat = settings.vertical_strategy
2068 h_strat = settings.horizontal_strategy
2069
2070 if v_strat == "text" or h_strat == "text":
2071 words = extract_words(CHARS, **(settings.text_settings or {}))
2072 else:
2073 words = []
2074
2075 v_explicit = []
2076 for desc in settings.explicit_vertical_lines or []:
2077 if isinstance(desc, dict):
2078 for e in obj_to_edges(desc):
2079 if e["orientation"] == "v":
2080 v_explicit.append(e)
2081 else:
2082 v_explicit.append(
2083 {
2084 "x0": desc,
2085 "x1": desc,
2086 "top": self.page.rect[1],
2087 "bottom": self.page.rect[3],
2088 "height": self.page.rect[3] - self.page.rect[1],
2089 "orientation": "v",
2090 }
2091 )
2092
2093 if v_strat == "lines":
2094 v_base = filter_edges(EDGES, "v")
2095 elif v_strat == "lines_strict":
2096 v_base = filter_edges(EDGES, "v", edge_type="line")
2097 elif v_strat == "text":
2098 v_base = words_to_edges_v(words, word_threshold=settings.min_words_vertical)
2099 elif v_strat == "explicit":
2100 v_base = []
2101 else:
2102 v_base = []
2103
2104 v = v_base + v_explicit
2105
2106 h_explicit = []
2107 for desc in settings.explicit_horizontal_lines or []:
2108 if isinstance(desc, dict):
2109 for e in obj_to_edges(desc):

Callers 1

__init__Method · 0.95

Calls 7

extract_wordsFunction · 0.85
obj_to_edgesFunction · 0.85
filter_edgesFunction · 0.85
words_to_edges_vFunction · 0.85
words_to_edges_hFunction · 0.85
merge_edgesFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected