|
32 | 32 | from . import cbook |
33 | 33 | from ._mathtext_data import ( |
34 | 34 | latex_to_bakoma, stix_glyph_fixes, stix_virtual_fonts, tex2uni) |
35 | | -from .font_manager import FontProperties, findfont, get_font |
| 35 | +from .font_manager import FontProperties, findfont, fontManager, get_font |
36 | 36 | from .ft2font import FT2Font, Kerning, LoadFlags |
37 | 37 |
|
38 | 38 |
|
@@ -683,6 +683,19 @@ def _get_glyph(self, fontname: str, font_class: str, |
683 | 683 | if (fontname in ('it', 'regular', 'normal') |
684 | 684 | and isinstance(self, StixFonts)): |
685 | 685 | return self._get_glyph('rm', font_class, sym) |
| 686 | + # Before substituting a dummy glyph, fall back through the |
| 687 | + # configured text fonts and their fallback chain (system fonts |
| 688 | + # and the Last Resort font), mirroring the regular-text path, so |
| 689 | + # characters the math fonts lack -- such as CJK characters -- |
| 690 | + # still render. See |
| 691 | + # https://github.com/matplotlib/matplotlib/issues/29173. |
| 692 | + text_font = get_font( |
| 693 | + fontManager._find_fonts_by_props(self.default_font_prop)) |
| 694 | + for fallback_font in [text_font, *text_font._fallbacks]: |
| 695 | + if fallback_font.get_char_index(uniindex, _fallback=False): |
| 696 | + _log.info("Substituting symbol %a from font %s.", |
| 697 | + sym, fallback_font.family_name) |
| 698 | + return fallback_font, uniindex, False |
686 | 699 | _log.warning("Font %r does not have a glyph for %a [U+%x], " |
687 | 700 | "substituting with a dummy symbol.", |
688 | 701 | new_fontname, sym, uniindex) |
|
0 commit comments