Skip to content

BUG: Add font stack to q/Q operations in layout mode #3225

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

Merged
merged 7 commits into from
Apr 2, 2025

Conversation

hackowitz-af
Copy link
Contributor

This is my first contribution to open source - please give feedback!

This addresses issue #3212, and the tested pdf is the upload from that issue. This fixes 100s of pages of my team's documents, in addition to the test file, and is a much-needed fix.

I'm sure there is a better way to handle the stack of text state(s), but 3 lines added is not worth conflating, in my opinion.

Closes py-pdf#3212

Enters/exits font stack in q/Q operations.
Pass ruff linting, add myself as a contributor

Closes py-pdf#3212
@hackowitz-af hackowitz-af changed the title Add font stack to q/Q operations in layout mode BUG: Add font stack to q/Q operations in layout mode Mar 28, 2025
Copy link

codecov bot commented Mar 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.59%. Comparing base (7f7fd95) to head (746656a).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3225   +/-   ##
=======================================
  Coverage   96.59%   96.59%           
=======================================
  Files          53       53           
  Lines        8950     8953    +3     
  Branches     1648     1648           
=======================================
+ Hits         8645     8648    +3     
  Misses        183      183           
  Partials      122      122           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I have added some small remarks about the tests.

For the actual implementation, I see no obvious issue as all tests seems to still pass, although @shartzog is of course invited to have a look at it before merging.

Copy link
Contributor

@shartzog shartzog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, @hackowitz-af. I think you're on the right track. Can you test w/ these updates in place?

EDIT: Upon further review, the font state is NOT preserved across graphic state saves/restores, so your original logic should work as submitted. I've already submitted an approval. Please disregard this review.

Copy link
Contributor

@shartzog shartzog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some further reading the PDF standard, I think this change is OK as is. I originally thought font state was preserved across graphic state saves and restores, but it turns out that's not the case.

@hackowitz-af
Copy link
Contributor Author

@stefan6419846 I addressed your requested changes and resolved the threads - but the PR is still blocked because of "requested changes". Can you please point me to any outstanding requests and make sure the rest are closed? Thanks!

Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and your patience. Going to merge this now.

@stefan6419846 stefan6419846 merged commit 499cd9d into py-pdf:main Apr 2, 2025
16 checks passed
@stefan6419846
Copy link
Collaborator

The outstanding request has been from my initial review which I just did not update while there still has been a second review in progress, as approving the PR myself usually is the last step which leads to a merge.

@hackowitz-af
Copy link
Contributor Author

Understood, thank you!

stefan6419846 added a commit that referenced this pull request May 11, 2025
## What's new

### New Features (ENH)
- Add support for IndirectObject.__iter__ (#3228) by @bryan-brancotte
- Allow filtering by font when removing text (#3216) by @samuelbradshaw

### Bug Fixes (BUG)
- Add missing named destinations being ByteStringObjects (#3282) by @stefan6419846
- Get font information more reliably when removing text (#3252) by @samuelbradshaw
- T* 2D Translation consistent with PDF 1.7 Spec (#3250) by @hackowitz-af
- Add font stack to q/Q operations in layout mode (#3225) by @hackowitz-af
- Avoid completely hiding image loading issues like exceeding image size limits (#3221) by @stefan6419846
- Using compress_identical_objects on transformed content duplicates differing content (#3197) by @danio
- Consider BlackIs1 parameter for CCITTFaxDecode filter (#3196) by @stefan6419846

### Robustness (ROB)
- Deal with insufficient cm matrix during text extraction (#3283) by @stefan6419846
- Allow merging when annotations miss D entry (#3281) by @stefan6419846
- Fix merging documents if there are no Dests (#3280) by @stefan6419846
- Fix crash on malformed action in outline (#3278) by @larsga
- Fix compression issues for removed images which might be None (#3246) by @stefan6419846
- Attempt to deal with non-rectangular FlateDecode streams (#3245) by @stefan6419846
- Handle some None values for broken PDF files (#3230) by @stefan6419846

### Developer Experience (DEV)
- Multiple style improvements by @j-t-1
- Update ruff to 0.11.0 by @stefan6419846

### Maintenance (MAINT)
- Conform ASCIIHexDecode implementation to specification (#3274) by @j-t-1
- Modify comments of filters that do not use decode_parms (#3260) by @j-t-1

### Code Style (STY)
- Simplify warnings & debugging in layout mode text extraction (#3271) by @hackowitz-af
- Standardize mypy assert statements (#3276) by @j-t-1

[Full Changelog](5.4.0...5.5.0)
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.

3 participants