镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Improve text rendering - #9909

Open
akx wants to merge 19 commits into
python-pillow:mainfrom
akx:ft-next
Open

akx wants to merge 19 commits into
python-pillow:mainfrom
akx:ft-next

Conversation

@akx

@akx akx commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Note

Stacked on #9908.
That PR ought to be reviewed and merged first and I'll happily rebase this.

Refs #9898 (not "fixes", since I can't be sure this ends up fixing OP's issues).

What's moving?

Some infrastructure:

  • PILLOW_TEST_SNAPSHOTS can now be set to create, overwrite or update, so assert_image_similar_tofile and assert_image_equal_tofile can update the golden image to what was passed in; this is similar to --snapshot-update for Syrupy or INSTA_UPDATE for Rust's Insta.
  • A test based on Kerning woes #9898's example code, golden snapshots updated as they improve over the patches.

These are the actual fixes; see #9908 for notes on the clean-ups:

  • Passing in a bytestring where some characters had the high bit set would render mojibake/tofu/.NOTDEF (whatever you want to call it) when using the basic renderer. Very corner-case, but also the fix is just a proper (unsigned char) cast.
  • Fractional variable font axis values were truncated; no more!
  • When using basic font layout (which is the case for the default font added in Added TrueType default font to allow for different sizes #7354), advance values were 64× off due to type confusion (see Document and clarify _imagingft #9908's description). No more!
  • Finally (the last 2/3 commits), glyph positioning within a single call is now subpixel and not pixel-snap-hinted (when available), leading to more accurate rendering.

Comment thread Tests/test_imagefont.py Resolved
@akx
akx force-pushed the ft-next branch 2 times, most recently from d0031ad to df6065f Compare September 9, 2026 12:44
Comment thread docs/releasenotes/13.0.0.rst Resolved
@akx

akx commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

I'll rebase this again after #9908 gets merged since this builds on it 👍

@akx

This comment was marked as outdated.

@akx

akx commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on the freshly rebased ft-clarify (#9908).

@akx

akx commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on the once more freshly rebased ft-clarify, now with release notes targeting version 13.1.0.

akx and others added 8 commits November 2, 2026 09:01
Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
* Avoids a segfault when `encoding` and `font_bytes` weren't passed at all (they were left uninitialized)
* Make font bytes optional
* Remove keyword support from core.getfont

Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@radarhere

Copy link
Copy Markdown
Member

PILLOW_TEST_SNAPSHOTS can now be set to create, overwrite or update, so assert_image_similar_tofile and assert_image_equal_tofile can update the golden image to what was passed in; this is similar to --snapshot-update for Syrupy or INSTA_UPDATE for Rust's Insta.

I'm not sold on the need for this. It's rare that many test images need to be updated at once. For most scenarios, if you're writing tests, you can simply im.save() the individual image.

OVERWRITE seems dangerous. The reason for assert_image_similar is that some images are rendered differently in different environments. We run the risk of receiving PRs where someone has resaved all of the assert_image_similar images on their machine and blindly committed them.

@akx

akx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

I'm not sold on the need for this. It's rare that many test images need to be updated at once.

This is a PR where I needed to do just that, and doing it manually seemed like a chore, since there were lots of affected tests, scattered throughout.

OVERWRITE seems dangerous. We run the risk of receiving PRs where someone has resaved all of the assert_image_similar images on their machine and blindly committed them.

Sure, and such a PR would probably be tagged in review, right, just like any change..? Either way I'm not convinced there's a huge risk of inadvertent usage, as you'd have to find the envvar, turn it on, then notice that "huh, a lot of files have changed, wonder why, ah well, I'll commit them anyway", and make a PR with all of them?

Either way, I can rip out the commit that adds that switch if you like.

This branch has not been deployed

No deployments
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.

2 participants