-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Update FreeType to 2.13.3 #29816
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?
Update FreeType to 2.13.3 #29816
Conversation
Another size test:
So once everything is repacked and compressed by git, the repo only gains 16M! |
If we're going to regen the baselines, we should also take that opportunity to remove some of the backcompat knobs -- at least text.kerning_factor (which clearly only existed to avoid regen'ing the baselines), and possibly text.hinting_factor as well (at least I would switch the default to 1 and generate the images with that amount of hinting, even if we decide to keep this functionality). |
Rather than regenerating the images at this point, I would start by pulling the tolerances used by Fedora upstream (so we can backport that to 3.10.x) and then in a second step regenerate the images on main and push the tolerances back to 0. |
Yes, good point; I will see what effect that has on things.
Fedora doesn't have any other tolerances other than the 6 other files already changed (though in this PR I changed the results instead of the tolerance, we could do like in Fedora instead). For image tests, we overlay the correct images from my |
Removing
I'll commit these all separately to make it easier to review, but we can squash these all together if it's all working fine. The majority of these are things like |
On a related note, and I'm not sure which ones are relevant here, but I wonder if we should drop several PDF and SVG test images when they would be changed but don't effectively test anything different from the PNG. |
For the repo size problem we could provide some guidance for the depth flag so most contributors don't need to download the whole thing. Eg --depth=500 gets you the last two years of commits and is x MB. Most folks don't need the full commit history (or even anything more than depth=1) |
The first image comparison that shows up Is it beneficial/necessary to grab the images from that other repo you've been keeping, or would it make sense to blow away the images directory on CI and move all the resultant images into the directory to start fresh in a sense? |
Surprisingly, this doesn't appear to make any difference to test images. It only affects 9 tests, and only with regards to bboxes and tight layout that are explicitly compared. This doesn't matter whether I try with FreeType 2.6.1 or 2.13.3.
Ah, you're right. I had not done a deep dive into the changes, but likely this was an image that had text that was removed, so it was regenerated from the FreeType changes, but effectively looked the same. I will go through these again and make sure we don't have any extraneous changes like this one.
The other repo was useful for tracking purposes and a quick changeover, but it might be best to start fresh and make sure we don't change too many extra images. |
I haven't updated this PR for it yet, but going over the diffs, one surprising change is that while the mathtext tests with DejaVu Sans look better (more consistent baselines, tweaks to kerning), the same ones with Computer Modern look worse (mostly due to a wobbly baseline.) But on the other hand, a lot of those had the wobbly baseline before... I've also opened #29827 to remove most of the redundant PDFs that would be changed here (except the ones from |
See also #14177 (comment) and #22459 re: wobbly baseline. I have some hopes that switching agg+usetex to rasterizing glyphs ourselves (see also #29807) would be one way to fix that. |
Slightly unrelated, but if we decide to update this many PNGs, it should be a good time to add an oxipng pre-commit hook. https://github.com/shssoichiro/oxipng I would expect that the sizes are halved or so on average. (It would be useful independent of this, but I have not gotten around to propose it and it would be unfortunate to change all those images without compression.) |
But these are not Unfortunately, updating FreeType still causes changes in those test images due to different kerning and metrics (the whole line may move up/down a pixel, but individual glyphs no longer do.) So I'm going to roll that change in here for the changed images to be squashed together. |
I've now rebased this on top of #29827, and gone through and removed the extra image changes. Now it's about 60% the number it was before. As I expect this will be squashed, there are a few things here:
|
Are the new tests also using hinting_factor=1? |
No, as I mentioned earlier, that barely changed anything. I'm trying to see if that's true or whether I didn't set it up right. |
I ran this, and without checking the changes, it will change several of the images changed here, with the addition of:
There are not really a whole bunch of changes here; only 111 tests. Again, I didn't do a full review yet, but it will change:
I have pushed the corresponding test image changes here for now: https://github.com/QuLogic/matplotlib/tree/ft213-additions |
lib/matplotlib/_mathtext.py
Outdated
image = np.asarray(image) | ||
while h and (image[0] == 0).all(): | ||
image = image[1:] | ||
while d and (image[-1] == 0).all(): | ||
image = image[:-1] | ||
return RasterParse(xmin, 0, w, h + d, d, image) |
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.
@anntzer h
and d
don't change in these loops; are they supposed to be reduced each time?
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.
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.
Yes, sorry about that, I had noticed this earlier and force-pushed a version of the mt1 branch where I am also more careful with positioning the origin of the rasterized image relative to the origin of the text string, can you try again? I think that fixes the problem.
Namely, `text.hinting` is now `default` instead of `force_autohint` (or `none` for classic tests) and `text.hinting_factor` is now 1, not 8.
If we've updated an image in the past couple commits, then we can remove the backwards-compatibility styling so that they're generated as intended.
The `FontInfo.num` value returned by `TruetypeFonts._get_info` is a character code, but `FT2Font.get_kerning` takes *glyph indices*, meaning that kerning was likely off in most cases.
Maybe this is a good time to revive #23189? (If we still are going to change the rendering of text.) There are two things there:
I can try to joint the next call. |
PR summary
On the call last week, we considered whether it made sense to do this upgrade. This PR shows the effect of doing so. Note for simplicity, I simply copied the new images from https://github.com/QuLogic/mpl-images, and then updated any new images directly. It's possible that there were some extraneously changed images as a result. I will check this shortly.
The latest FreeType version supports many newer font features, and fixes several CVEs, which we were mostly hoping were not relevant to us, but this may or may not be true. Additionally, I've found that libraqm runs into issues with hinting in older versions. While I'm not entirely sure which of libraqm or FreeType holds that bug, updating libraqm to new versions would also require newer FreeType anyway.
The main concern here was the repo size. Locally, I started with a completely fresh clone before creating this commit. The
.git
directory increased from 461M to 482M, or an increase of 21M / 4.6%.PR checklist