Repository navigation
Fix rendering bug for small Chinese characters by adding FT_LOAD_NO_B… - #32072
mohit-sharma-001 wants to merge 3 commits into
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
Thanks for the PR. Please add a test, change the language of your comment to English, and update your PR description to use our PR template. |
Updated comment to clarify the purpose of FT_LOAD_NO_BITMAP.
@scottshambaugh |
|
Please iterate on your code until the automated checks pass. There seems to be real linting (formatting) and test failures on your newly added test. |
| def test_small_chinese_character_rendering(): | ||
| fig, ax = plt.subplots() | ||
| ax.text(0.5, 0.5, '字体', fontsize=6) | ||
| # Smoke test to ensure it renders without crashing |
There was a problem hiding this comment.
The initial bug report rendered without error but did not show the glyphs. We may need to gain an image test here to be sure that the glyphs actually render.
This seems like a reasonably theory as to what is wrong, but preventing bitmaps seems like the wrong fix, instead we should fix what ever is causing the bitmap glyphs to fail to render. |
Thank you for the insight! That makes a lot of sense regarding the embedded bitmaps in SimSun at smaller sizes. Since forcing FT_LOAD_NO_BITMAP might not be the ideal approach, could you point me in the right direction or give some hints on where the font fallback or bitmap rendering failure might be happening in the codebase? I'd be happy to look into a more proper fix and add an image test as requested. |
|
We should definitely support bitmap glyphs, but that's probably a lot more work rather than sticking with scalable glyphs if the font supports it. So I think it's fine to avoid the bitmaps for now. However, if we do that, we should a) reject fonts at load time that only have bitmaps and b) I don't think this is the normal rendering path now; are you sure this PR actually fixes the problem? |
@QuLogic Regarding rejecting fonts at load time that only have bitmaps: could you guide me on where in the codebase font loading checks happen so I can implement that check? |
|
I looked into this more and found the root cause(s), and believe that blocking bitmaps is the wrong direction for the fix. See my comment here for more details: #32063 (comment) So I'm going to close this PR as won't-do, but @mohit-sharma-001 please feel free to open another one that addresses the root causes I describe there. |
|
Actually, I was overzealous on closing this! It looks like this flag is ignored for bitmap-only fonts, so it's safe to set by default. The fixes I mention in that issue should still be made, but will apply to bitmap-only fonts. So this PR will partially but not fully address that issue. That said, there are a few other spots this flag will need to be set. https://github.com/freetype/freetype/blob/VER-2-14-3/include/freetype/freetype.h#L3349-L3351 |
|
@scottshambaugh Thanks for reopening and clarifying! That makes sense. Could you please point out or specify the other spots/files in the codebase where this flag (FT_LOAD_NO_BITMAP) needs to be set? I'd be glad to update those as well to make this fix complete. |
|
There are several places in the code that use the same exact pattern as in this PR, so that's a good starting point (but not a finishing point). Part of the process of submitting PRs is searching and understanding the codebase, so that you yourself are confident that the changes you are making are correct and comprehensive. Please take some time to do that, and ensure that the changes are tested and passing all automated checks. We will be happy to review once that's done. Marking for autoclose for now, will remove that tag on successful revision. |
|
⏰ This pull request might be automatically closed in two weeks from now. Thank you for your contribution to Matplotlib and for the effort you have put into this PR. This pull request does not yet meet the quality and clarity standards needed for an effective review. Project maintainers have limited time for code reviews, and our goal is to prioritize well-prepared contributions to keep Matplotlib maintainable. Matplotlib maintainers cannot provide one-to-one guidance on this PR. However, if you ask focused, well-researched questions, a community member may be willing to help. 💬 To increase the chance of a productive review:
As the author, you are responsible for driving this PR, which entails doing necessary background research as well as presenting its context and your thought process. If you are a new contributor, or do not know how to fulfill these requirements, we recommend that you familiarize yourself with Matplotlib's development conventions or engage with the community via our Discourse or one of our meetings before submitting code. If you substantially improve this PR within two weeks, leave a comment and a team member may remove the |
PR summary
Fixes a rendering issue where small Chinese characters were loaded as pixelated embedded bitmaps instead of smooth vector outlines.
Adding the
FT_LOAD_NO_BITMAPflag toFT_Load_Glyphforces the FreeType engine to ignore embedded bitmaps and use vector outlines, ensuring high-quality rendering at small font sizes.AI Disclosure
Yes, generative AI was used to assist in troubleshooting the FreeType flag and setting up the local build environment.
PR checklist