MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _get_glyph

Method _get_glyph

lib/matplotlib/_mathtext.py:630–693  ·  view source on GitHub ↗
(self, fontname: str, font_class: str,
                   sym: str)

Source from the content-addressed store, hash-verified

628 return fontname, uniindex
629
630 def _get_glyph(self, fontname: str, font_class: str,
631 sym: str) -> tuple[FT2Font, CharacterCodeType, bool]:
632 try:
633 uniindex = get_unicode_index(sym)
634 found_symbol = True
635 except ValueError:
636 uniindex = ord('?')
637 found_symbol = False
638 _log.warning("No TeX to Unicode mapping for %a.", sym)
639
640 fontname, uniindex = self._map_virtual_font(fontname, font_class, uniindex)
641
642 new_fontname = fontname
643
644 # Only characters in the "Letter" class should be italicized in 'it'
645 # mode. Greek capital letters should be Roman.
646 if found_symbol:
647 if fontname == 'normal' and uniindex < 0x10000:
648 # normal mathematics font
649 char = chr(uniindex)
650 if (unicodedata.category(char)[0] != "L"
651 or unicodedata.name(char).startswith("GREEK CAPITAL")):
652 new_fontname = 'rm'
653 else:
654 new_fontname = 'it'
655
656 slanted = (new_fontname == 'it') or sym in self._slanted_symbols
657 found_symbol = False
658 font = self._get_font(new_fontname)
659 if font is not None:
660 if (uniindex in self._cmr10_substitutions
661 and font.family_name == "cmr10"):
662 font = get_font(
663 cbook._get_data_path("fonts/ttf/cmsy10.ttf"))
664 uniindex = self._cmr10_substitutions[uniindex]
665 glyphindex = font.get_char_index(uniindex)
666 if glyphindex != 0:
667 found_symbol = True
668
669 if not found_symbol:
670 if self._fallback_font:
671 if (fontname in ('it', 'regular', 'normal')
672 and isinstance(self._fallback_font, StixFonts)):
673 fontname = 'rm'
674
675 g = self._fallback_font._get_glyph(fontname, font_class, sym)
676 family = g[0].family_name
677 if family in BakomaFonts._fontmap.values():
678 family = "Computer Modern"
679 _log.info("Substituting symbol %s from %s", sym, family)
680 return g
681
682 else:
683 if (fontname in ('it', 'regular', 'normal')
684 and isinstance(self, StixFonts)):
685 return self._get_glyph('rm', font_class, sym)
686 _log.warning("Font %r does not have a glyph for %a [U+%x], "
687 "substituting with a dummy symbol.",

Callers

nothing calls this directly

Calls 7

_map_virtual_fontMethod · 0.95
get_unicode_indexFunction · 0.85
get_fontFunction · 0.85
get_char_indexMethod · 0.80
valuesMethod · 0.80
_get_fontMethod · 0.45
_get_glyphMethod · 0.45

Tested by

no test coverage detected