Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ def chars_in_rect(CHARS, rect):
1
and rect[0] <= c["x0"]
and c["x1"] <= rect[2]
and rect[1] <= c["y0"]
and rect[3] >= c["y1"]
and rect[1] <= c["top"]
and rect[3] >= c["bottom"]
for c in CHARS
)

Expand Down
20 changes: 20 additions & 0 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,3 +939,23 @@ def test_find_tables_union_no_layout_degrades_to_line_candidates():
finally:
pymupdf._get_layout = original_get_layout_fn
doc.close()


def test_5092():
"""chars_in_rect must pair a top-down rect with top/bottom, not CTM y0/y1.

A character whose top/bottom sit inside rect, but whose y0/y1 do not,
must still be detected. This matches the has_text() pairing.
"""
from pymupdf.table import chars_in_rect

char = {
"x0": 10.0,
"x1": 20.0,
"top": 100.0,
"bottom": 110.0,
"y0": 690.0,
"y1": 700.0,
}
rect = (0.0, 90.0, 30.0, 120.0) # top-down: top=90, bottom=120
assert chars_in_rect([char], rect)
Loading