-
Notifications
You must be signed in to change notification settings - Fork 1.5k
BUG: PageObject.scale() scales media box incorrectly (#3487) #3489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I'm not sure if I'm required to create a test for this fix. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3489 +/- ##
=======================================
Coverage 97.09% 97.09%
=======================================
Files 56 56
Lines 9658 9664 +6
Branches 1748 1750 +2
=======================================
+ Hits 9377 9383 +6
Misses 168 168
Partials 113 113 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I have not been aware that the faulty commit would not have proper tests, thus I did not require a new one. With the current regression, we should add one to ensure this does not break again.
This is a very strange side effect, as the boxes all look correct: @pytest.mark.enable_socket
def test_scale_by():
"""Tests for #3487"""
url = "https://github.com/user-attachments/files/22685841/input.pdf"
name = "issue3487.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
original_box = RectangleObject((0, 0, 595.275604, 841.88974))
expected_box = RectangleObject((0.0, 0.0, 297.637802, 420.94487))
for page in reader.pages:
assert page.artbox == original_box
assert page.bleedbox == original_box
assert page.cropbox == original_box
assert page.mediabox == original_box
assert page.trimbox == original_box
page.scale_by(0.5)
assert page.artbox == expected_box
assert page.bleedbox == expected_box
assert page.cropbox == expected_box
assert page.mediabox == expected_box
assert page.trimbox == expected_box Thus, we need a rendering test with Ghostscript here to actually detect this bug (which has already been fixed in the past in #1314 - without adding a test). |
If I am not mistaken, the added test is not sufficient, as running it against main is successful as well, not providing any benefits (as outlined in my comment as well). We have to add a test similar to the discussions in the issue by comparing the rendering results with Ghostscript, as mentioned in my comment as well (examples are already available for watermarking for example). |
Ah, the usage of Ghostscript exceeds my current skill level for now and I don't know, when I have the time available to look into that for a proper test. 🤔 |
to its content and updating the page size. | ||
This updates the various page boundaries (mediabox, cropbox, etc.) | ||
This updates the various page boundaries (artbox, cropbox, etc.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change does not seem necessary?
I have added a Ghostscript-based test. After resolving the open discussion, this should be ready for merging. |
Partly undo d89fb78#diff-153e5cee71ddf471246ff5c0e198345f005942a540a8f39297736f0b620d631dR1587-R1592 since the changed order of updates to the page boundaries results in wrongly scaled pdfs.