Skip to content

Conversation

@MacDue
Copy link
Member

@MacDue MacDue commented Oct 18, 2025

See commits for details:

Progression rotated.pdf:
Before:
Screenshot from 2025-10-18 18-24-32
After:
Screenshot from 2025-10-18 18-27-36

@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label Oct 18, 2025
@MacDue
Copy link
Member Author

MacDue commented Oct 18, 2025

I've not enabled this for these cases (unsure of the perf hit), but it seems like this approach may also be worth considering for oddly scaled text. This is text.pdf:
Before (bad kerning)
Screenshot from 2025-10-18 21-02-17
After (which looks much closer to my system renderer)
Screenshot from 2025-10-18 21-01-38

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.
@MacDue
Copy link
Member Author

MacDue commented Oct 26, 2025

Any thoughts on this one?

@nico
Copy link
Contributor

nico commented Oct 26, 2025

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!

@MacDue
Copy link
Member Author

MacDue commented Oct 26, 2025

Okay, no worries, no rush 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

👀 pr-needs-review PR needs review from a maintainer or community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants