Skip to content

find_tables(): map caller paths into the rotated page's frame (#5291) - #5292

Open
thomas-villani wants to merge 1 commit into
pymupdf:mainfrom
thomas-villani:fix-find-tables-rotated-paths
Open

thomas-villani wants to merge 1 commit into
pymupdf:mainfrom
thomas-villani:fix-find-tables-rotated-paths

Conversation

@thomas-villani

Copy link
Copy Markdown

Fixes #5291.

On a rotated page, find_tables() derotates the page (page_rotation_set0) and then works in the coordinates the page is displayed in. Page.get_drawings() returns unrotated coordinates, and paths= was used as given, so its edges did not line up with the text. On a /Rotate 90 page holding an 8×3 ruled table, find_tables(paths=page.get_drawings()) gave 2×8 on 1.28.2 and 8×5 on 2.1, while find_tables() gave 8×3.

This change multiplies caller-supplied paths by page.rotation_matrix before the page is derotated, so get_drawings() output can be passed back unchanged, as the paths documentation describes. The paths are copied, so the caller's dictionaries are not modified. Unrotated pages are untouched.

Tests:

  • New test_5291 builds an upright 8×3 table at 0, 90, 180 and 270 degrees. For each, it checks that paths=page.get_drawings() extracts the same cells as the plain call and that the caller's paths are not changed. It fails on main at 90 and passes with this change.
  • tests/test_tables.py gives 56 passed and 1 failed on main (the new test), and 57 passed with this change. This was run with the 2.1 wheel's binary and this branch's table.py.
  • Also checked: a non-zero MediaBox origin (all four rotations agree), and a real landscape government report (/Rotate 90, 4 pages of a 24-column ruled table), where paths= now matches the plain call on every page instead of giving 47×28 against 48×24.

…f#5291)

On a rotated page find_tables() derotates the page and then works in the
coordinates the page is displayed in, but Page.get_drawings() gives
unrotated coordinates. Paths passed via `paths=` were used as given, so on a
/Rotate 90 page an 8x3 ruled table came out 2x8 (1.28.2) or 8x5 (2.1),
while the plain call found 8x3.

Caller paths are now multiplied by page.rotation_matrix before the page is
derotated, on copies, so get_drawings() output can be passed back unchanged.
test_5291 checks 0, 90, 180 and 270 degrees against the plain call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

find_tables(paths=page.get_drawings()) misreads a rotated page: paths are taken in the wrong frame

1 participant