Repository navigation
find_tables(): map caller paths into the rotated page's frame (#5291) - #5292
Open
thomas-villani wants to merge 1 commit into
Open
thomas-villani wants to merge 1 commit into
thomas-villani wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andpaths=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, whilefind_tables()gave 8×3.This change multiplies caller-supplied paths by
page.rotation_matrixbefore the page is derotated, soget_drawings()output can be passed back unchanged, as thepathsdocumentation describes. The paths are copied, so the caller's dictionaries are not modified. Unrotated pages are untouched.Tests:
test_5291builds an upright 8×3 table at 0, 90, 180 and 270 degrees. For each, it checks thatpaths=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.pygives 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'stable.py.paths=now matches the plain call on every page instead of giving 47×28 against 48×24.