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.
@@ -459,7 +460,7 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
459460 _slanted_symbols = set (r"\int \oint" .split ())
460461
461462 def _get_glyph (self , fontname : str , font_class : str ,
462- sym : str ) -> tuple [FT2Font , int , bool ]:
463+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
463464 font = None
464465 if fontname in self .fontmap and sym in latex_to_bakoma :
465466 basename , num = latex_to_bakoma [sym ]
@@ -551,7 +552,7 @@ class UnicodeFonts(TruetypeFonts):
551552 # Some glyphs are not present in the `cmr10` font, and must be brought in
552553 # from `cmsy10`. Map the Unicode indices of those glyphs to the indices at
553554 # which they are found in `cmsy10`.
554- _cmr10_substitutions = {
555+ _cmr10_substitutions : dict [ CharacterCodeType , CharacterCodeType ] = {
555556 0x00D7 : 0x00A3 , # Multiplication sign.
556557 0x2212 : 0x00A1 , # Minus sign.
557558 }
@@ -594,11 +595,11 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
594595 _slanted_symbols = set (r"\int \oint" .split ())
595596
596597 def _map_virtual_font (self , fontname : str , font_class : str ,
597- uniindex : int ) -> tuple [str , int ]:
598+ uniindex : CharacterCodeType ) -> tuple [str , CharacterCodeType ]:
598599 return fontname , uniindex
599600
600601 def _get_glyph (self , fontname : str , font_class : str ,
601- sym : str ) -> tuple [FT2Font , int , bool ]:
602+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
602603 try :
603604 uniindex = get_unicode_index (sym )
604605 found_symbol = True
@@ -607,8 +608,7 @@ def _get_glyph(self, fontname: str, font_class: str,
607608 found_symbol = False
608609 _log .warning ("No TeX to Unicode mapping for %a." , sym )
609610
610- fontname , uniindex = self ._map_virtual_font (
611- fontname , font_class , uniindex )
611+ fontname , uniindex = self ._map_virtual_font (fontname , font_class , uniindex )
612612
613613 new_fontname = fontname
614614
@@ -693,7 +693,7 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
693693 self .fontmap [name ] = fullpath
694694
695695 def _get_glyph (self , fontname : str , font_class : str ,
696- sym : str ) -> tuple [FT2Font , int , bool ]:
696+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
697697 # Override prime symbol to use Bakoma.
698698 if sym == r'\prime' :
699699 return self .bakoma ._get_glyph (fontname , font_class , sym )
@@ -783,7 +783,7 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
783783 self .fontmap [name ] = fullpath
784784
785785 def _map_virtual_font (self , fontname : str , font_class : str ,
786- uniindex : int ) -> tuple [str , int ]:
786+ uniindex : CharacterCodeType ) -> tuple [str , CharacterCodeType ]:
787787 # Handle these "fonts" that are actually embedded in
788788 # other fonts.
789789 font_mapping = stix_virtual_fonts .get (fontname )
@@ -1170,7 +1170,7 @@ def __init__(self, elements: T.Sequence[Node]):
11701170 self .glue_sign = 0 # 0: normal, -1: shrinking, 1: stretching
11711171 self .glue_order = 0 # The order of infinity (0 - 3) for the glue
11721172
1173- def __repr__ (self ):
1173+ def __repr__ (self ) -> str :
11741174 return "{}<w={:.02f} h={:.02f} d={:.02f} s={:.02f}>[{}]" .format (
11751175 super ().__repr__ (),
11761176 self .width , self .height ,
0 commit comments