Repository navigation
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. |
| # https://github.com/matplotlib/matplotlib/issues/29173. | ||
| text_font = get_font( | ||
| fontManager._find_fonts_by_props(self.default_font_prop)) | ||
| for fallback_font in [text_font, *text_font._fallbacks]: |
There was a problem hiding this comment.
Is it worth pushing this logic farther up into the font object so we don't have to access private state here?
There was a problem hiding this comment.
Done. FT2Font now has a private _get_font_for_char(codepoint) that returns the font in the chain that actually has the glyph, so mathtext doesn't touch _fallbacks anymore. The unused C++ get_char_fallback_index became get_font_for_char along the way. Also rebased on main.
Instead of walking the private FT2Font._fallbacks list from mathtext, add FT2Font._get_font_for_char(codepoint), which returns the font in the fallback chain that has a glyph for the code point, or None. On the C++ side it replaces the unused get_char_fallback_index helper with get_font_for_char, which also searches nested fallback lists. Addresses review feedback on matplotlib#31766. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Instead of walking the private FT2Font._fallbacks list from mathtext, add FT2Font._get_font_for_char(codepoint), which returns the font in the fallback chain that has a glyph for the code point, or None. On the C++ side it replaces the unused get_char_fallback_index helper with get_font_for_char, which also searches nested fallback lists. Addresses review feedback on matplotlib#31766. Co-Authored-By: Claude Fable 5.1 <[email protected]>
f33e56e to
d74df12
Compare
Instead of walking the private FT2Font._fallbacks list from mathtext, add FT2Font._get_font_for_char(codepoint), which returns the font in the fallback chain that has a glyph for the code point, or None. On the C++ side it replaces the unused get_char_fallback_index helper with get_font_for_char, which also searches nested fallback lists. Addresses review feedback on matplotlib#31766.
d74df12 to
3afb3bc
Compare
Search the font's fallback chain before substituting a dummy glyph, so that e.g. CJK characters in math expressions render like they do in regular text. Closes matplotlib#29173
Instead of walking the private FT2Font._fallbacks list from mathtext, add FT2Font._get_font_for_char(codepoint), which returns the font in the fallback chain that has a glyph for the code point, or None. On the C++ side it replaces the unused get_char_fallback_index helper with get_font_for_char, which also searches nested fallback lists. Addresses review feedback on matplotlib#31766.
3afb3bc to
3c8747a
Compare
PR summary
Closes #29173.
Characters missing from the math fonts (e.g. CJK) were replaced by a ¤ dummy
glyph, because mathtext had no glyph-level font fallback. Regular text walks the
configured font list and its fallback chain instead.
UnicodeFonts._get_glyphnow does the same before giving up: it asks theconfigured text font for the font in its chain that has the glyph, via a new
private
FT2Font._get_font_for_char(codepoint)(backed by a C++FT2Font::get_font_for_char, which replaces the unusedget_char_fallback_index). Only the missing-glyph path changes, so existingoutput is unaffected. The
get_char_indexstub also gains the_fallbackkeyword the binding already had.
AI Disclosure
I used Claude to explore the font code and draft the implementation, tests, and
this text; I chose the approach and reviewed and tested everything locally.
PR quality check