ENH: AppearanceStream: Allow arbitrary rotations and apply rotations for annotation appearance streams#3917
Open
PJBrs wants to merge 4 commits into
Open
ENH: AppearanceStream: Allow arbitrary rotations and apply rotations for annotation appearance streams#3917PJBrs wants to merge 4 commits into
PJBrs wants to merge 4 commits into
Conversation
Now that we need BaseStreamConfig.rectangle in more places, just have it always be a RectangleObject. This is more accurate and it prevents code coverage / mypy problems where lines needed to check whether rectangle is a RectangleObject are either detected as missing by mypy or untested by coverage.
This patch adds rotation to BaseStreamConfig and applies it to BaseStreamAppearance by adding a "/Matrix" key when rotation is 90, 180 or 270 degrees.
When an annotation includes a ["/MK"]["/R"] field for rotation, detect it and rotate the appearance stream accordingly.
When a page has a rotation set of 90 or 270 degrees (for instance, portrait to landscape), also rotate the axes of the annotation's appearance stream rectangle.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3917 +/- ##
=======================================
Coverage 97.86% 97.87%
=======================================
Files 57 57
Lines 10738 10758 +20
Branches 2006 2009 +3
=======================================
+ Hits 10509 10529 +20
Misses 127 127
Partials 102 102 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
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.

This PR adds a "rotation" attribute to class BaseStreamConfig. When instantiating a class BaseStreamAppearance, we apply the rotation to the appearance stream in the form of a Transformation, both rotating and translating the BaseStreamAppearance object so that its origin remains (0, 0).
When we parse an annotation to generate an appearance stream, we now read its ["/MK"]["/R"] field to determine rotation, and pass the rotation along with the other layout options. In some cases, we also need to take into account page rotation (in particular, this happens in issue #2737.
Finally this PR adds one patch to change the typing of BaseStreamConfig so that rectangle is always a RectangleObject. This to prevent mypy warnings or coverage problems.
Fixes: #2737
I made extensive use of Google Gemini preparing this PR. Especially the Transformation code I could not have produced myself. The resulting logic, though, is mainly my own.