3737
3838if T .TYPE_CHECKING :
3939 from collections .abc import Iterable
40- from .ft2font import Glyph
40+ from .ft2font import CharacterCodeType , Glyph
41+
4142
4243ParserElement .enable_packrat ()
4344_log = logging .getLogger ("matplotlib.mathtext" )
4748# FONTS
4849
4950
50- def get_unicode_index (symbol : str ) -> int : # Publicly exported.
51+ def get_unicode_index (symbol : str ) -> CharacterCodeType : # Publicly exported.
5152 r"""
5253 Return the integer index (from the Unicode table) of *symbol*.
5354
@@ -85,7 +86,7 @@ class VectorParse(NamedTuple):
8586 width : float
8687 height : float
8788 depth : float
88- glyphs : list [tuple [FT2Font , float , int , float , float ]]
89+ glyphs : list [tuple [FT2Font , float , CharacterCodeType , float , float ]]
8990 rects : list [tuple [float , float , float , float ]]
9091
9192VectorParse .__module__ = "matplotlib.mathtext"
@@ -212,7 +213,7 @@ class FontInfo(NamedTuple):
212213 fontsize : float
213214 postscript_name : str
214215 metrics : FontMetrics
215- num : int
216+ num : CharacterCodeType
216217 glyph : Glyph
217218 offset : float
218219
@@ -365,7 +366,7 @@ def _get_offset(self, font: FT2Font, glyph: Glyph, fontsize: float,
365366 return 0.
366367
367368 def _get_glyph (self , fontname : str , font_class : str ,
368- sym : str ) -> tuple [FT2Font , int , bool ]:
369+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
369370 raise NotImplementedError
370371
371372 # The return value of _get_info is cached per-instance.
@@ -425,7 +426,9 @@ def get_kern(self, font1: str, fontclass1: str, sym1: str, fontsize1: float,
425426 info1 = self ._get_info (font1 , fontclass1 , sym1 , fontsize1 , dpi )
426427 info2 = self ._get_info (font2 , fontclass2 , sym2 , fontsize2 , dpi )
427428 font = info1 .font
428- return font .get_kerning (info1 .num , info2 .num , Kerning .DEFAULT ) / 64
429+ return font .get_kerning (font .get_char_index (info1 .num ),
430+ font .get_char_index (info2 .num ),
431+ Kerning .DEFAULT ) / 64
429432 return super ().get_kern (font1 , fontclass1 , sym1 , fontsize1 ,
430433 font2 , fontclass2 , sym2 , fontsize2 , dpi )
431434
@@ -459,7 +462,7 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
459462 _slanted_symbols = set (r"\int \oint" .split ())
460463
461464 def _get_glyph (self , fontname : str , font_class : str ,
462- sym : str ) -> tuple [FT2Font , int , bool ]:
465+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
463466 font = None
464467 if fontname in self .fontmap and sym in latex_to_bakoma :
465468 basename , num = latex_to_bakoma [sym ]
@@ -551,7 +554,7 @@ class UnicodeFonts(TruetypeFonts):
551554 # Some glyphs are not present in the `cmr10` font, and must be brought in
552555 # from `cmsy10`. Map the Unicode indices of those glyphs to the indices at
553556 # which they are found in `cmsy10`.
554- _cmr10_substitutions = {
557+ _cmr10_substitutions : dict [ CharacterCodeType , CharacterCodeType ] = {
555558 0x00D7 : 0x00A3 , # Multiplication sign.
556559 0x2212 : 0x00A1 , # Minus sign.
557560 }
@@ -594,11 +597,11 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
594597 _slanted_symbols = set (r"\int \oint" .split ())
595598
596599 def _map_virtual_font (self , fontname : str , font_class : str ,
597- uniindex : int ) -> tuple [str , int ]:
600+ uniindex : CharacterCodeType ) -> tuple [str , CharacterCodeType ]:
598601 return fontname , uniindex
599602
600603 def _get_glyph (self , fontname : str , font_class : str ,
601- sym : str ) -> tuple [FT2Font , int , bool ]:
604+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
602605 try :
603606 uniindex = get_unicode_index (sym )
604607 found_symbol = True
@@ -607,8 +610,7 @@ def _get_glyph(self, fontname: str, font_class: str,
607610 found_symbol = False
608611 _log .warning ("No TeX to Unicode mapping for %a." , sym )
609612
610- fontname , uniindex = self ._map_virtual_font (
611- fontname , font_class , uniindex )
613+ fontname , uniindex = self ._map_virtual_font (fontname , font_class , uniindex )
612614
613615 new_fontname = fontname
614616
@@ -693,7 +695,7 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
693695 self .fontmap [name ] = fullpath
694696
695697 def _get_glyph (self , fontname : str , font_class : str ,
696- sym : str ) -> tuple [FT2Font , int , bool ]:
698+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
697699 # Override prime symbol to use Bakoma.
698700 if sym == r'\prime' :
699701 return self .bakoma ._get_glyph (fontname , font_class , sym )
@@ -783,7 +785,7 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
783785 self .fontmap [name ] = fullpath
784786
785787 def _map_virtual_font (self , fontname : str , font_class : str ,
786- uniindex : int ) -> tuple [str , int ]:
788+ uniindex : CharacterCodeType ) -> tuple [str , CharacterCodeType ]:
787789 # Handle these "fonts" that are actually embedded in
788790 # other fonts.
789791 font_mapping = stix_virtual_fonts .get (fontname )
@@ -1170,7 +1172,7 @@ def __init__(self, elements: T.Sequence[Node]):
11701172 self .glue_sign = 0 # 0: normal, -1: shrinking, 1: stretching
11711173 self .glue_order = 0 # The order of infinity (0 - 3) for the glue
11721174
1173- def __repr__ (self ):
1175+ def __repr__ (self ) -> str :
11741176 return "{}<w={:.02f} h={:.02f} d={:.02f} s={:.02f}>[{}]" .format (
11751177 super ().__repr__ (),
11761178 self .width , self .height ,
0 commit comments