-
Couldn't load subscription status.
- Fork 3.3k
LibPDF: Add "slow path" for text rendering that can handle transforms #26292
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
Open
MacDue
wants to merge
3
commits into
SerenityOS:master
Choose a base branch
from
MacDue:pdf_fonts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−57
Conversation
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
MacDue
added a commit
to MacDue/serenity
that referenced
this pull request
Oct 19, 2025
While working on SerenityOS#26292, I noticed that while fills/strokes can be Gfx::PaintStyles in LibPDF, currently they never are, which confused me. It turns out that a few years ago, tiled patterns were implemented in PR SerenityOS#22197, but were partially reverted due to crashes in SerenityOS#22364, leaving around a partial implementation. It appears the author was going to look into the crashes, but never got around to it. So, this patch resolves all the crashes on `0000.zip`, mainly by checking types and not assuming dictionary keys exist. Summary of `./Meta/test_pdf.py ~/Downloads/0000`: ``` Stacks: 0 crashes (0.0%) 0 distinct crash stacks 7 failed to open (0.7%) /home/macdue/Downloads/0000/0000346.pdf /home/macdue/Downloads/0000/0000202.pdf /home/macdue/Downloads/0000/0000399.pdf /home/macdue/Downloads/0000/0000421.pdf /home/macdue/Downloads/0000/0000480.pdf /home/macdue/Downloads/0000/0000920.pdf /home/macdue/Downloads/0000/0000819.pdf 3 files with password (0.3%) 909 files without issues (90.9%) ```
MacDue
added a commit
to MacDue/serenity
that referenced
this pull request
Oct 21, 2025
This reverts commit 6032c06. This relands the original commit with fixups to make `PatternColorSpace` more robust to unexpected inputs. While working on SerenityOS#26292, I noticed that while fills/strokes can be Gfx::PaintStyles in LibPDF, currently they never are, which confused me. It turns out that a few years ago, tiled patterns were implemented in PR SerenityOS#22197, but were partially reverted due to crashes in SerenityOS#22364, leaving around a partial implementation. It appears the author was going to look into the crashes, but never got around to it. So, this patch resolves all the crashes on `0000.zip`, mainly by checking types and not assuming dictionary keys exist. Summary of `./Meta/test_pdf.py ~/Downloads/0000`: ``` Stacks: 0 crashes (0.0%) 0 distinct crash stacks 7 failed to open (0.7%) /home/macdue/Downloads/0000/0000346.pdf /home/macdue/Downloads/0000/0000202.pdf /home/macdue/Downloads/0000/0000399.pdf /home/macdue/Downloads/0000/0000421.pdf /home/macdue/Downloads/0000/0000480.pdf /home/macdue/Downloads/0000/0000920.pdf /home/macdue/Downloads/0000/0000819.pdf 3 files with password (0.3%) 909 files without issues (90.9%) ``` Co-authored-by: MacDue <[email protected]>
nico
pushed a commit
that referenced
this pull request
Oct 21, 2025
This reverts commit 6032c06. This relands the original commit with fixups to make `PatternColorSpace` more robust to unexpected inputs. While working on #26292, I noticed that while fills/strokes can be Gfx::PaintStyles in LibPDF, currently they never are, which confused me. It turns out that a few years ago, tiled patterns were implemented in PR #22197, but were partially reverted due to crashes in #22364, leaving around a partial implementation. It appears the author was going to look into the crashes, but never got around to it. So, this patch resolves all the crashes on `0000.zip`, mainly by checking types and not assuming dictionary keys exist. Summary of `./Meta/test_pdf.py ~/Downloads/0000`: ``` Stacks: 0 crashes (0.0%) 0 distinct crash stacks 7 failed to open (0.7%) /home/macdue/Downloads/0000/0000346.pdf /home/macdue/Downloads/0000/0000202.pdf /home/macdue/Downloads/0000/0000399.pdf /home/macdue/Downloads/0000/0000421.pdf /home/macdue/Downloads/0000/0000480.pdf /home/macdue/Downloads/0000/0000920.pdf /home/macdue/Downloads/0000/0000819.pdf 3 files with password (0.3%) 909 files without issues (90.9%) ``` Co-authored-by: MacDue <[email protected]>
This will make reusing the logic to determine glyph IDs easier. No behaviour change intended.
This adds a slow path for drawing text (that is not simply scaled or translated), which works by creating a Gfx::Path for the text, applying the transform, then filling it. This supports arbitrary (affine) transforms. Currently, the APIs needed to support this are only implemented for TrueType fonts. It should be possible to extend to other (non-bitmap) fonts too, but since not all PDF fonts are built on top of the existing Gfx::Font classes, it requires more work to implement.
Seems a little neater. This excludes Type0Fonts for now, but it looks like not much of the implementation would be shared. No behaviour change intended.
|
Any thoughts on this one? |
|
I think it's great, I'm super excited about it, and I want to make some time to take a real look. I have some notes on this feature somewhere I'd like to re-read, etc. Hopefully this week! |
|
Okay, no worries, no rush 😄 |
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.


See commits for details:
Progression


rotated.pdf:Before:
After: