37
37
38
38
if T .TYPE_CHECKING :
39
39
from collections .abc import Iterable
40
- from .ft2font import Glyph
40
+ from .ft2font import CharacterCodeType , Glyph
41
+
41
42
42
43
ParserElement .enable_packrat ()
43
44
_log = logging .getLogger ("matplotlib.mathtext" )
47
48
# FONTS
48
49
49
50
50
- def get_unicode_index (symbol : str ) -> int : # Publicly exported.
51
+ def get_unicode_index (symbol : str ) -> CharacterCodeType : # Publicly exported.
51
52
r"""
52
53
Return the integer index (from the Unicode table) of *symbol*.
53
54
@@ -85,7 +86,7 @@ class VectorParse(NamedTuple):
85
86
width : float
86
87
height : float
87
88
depth : float
88
- glyphs : list [tuple [FT2Font , float , int , float , float ]]
89
+ glyphs : list [tuple [FT2Font , float , CharacterCodeType , float , float ]]
89
90
rects : list [tuple [float , float , float , float ]]
90
91
91
92
VectorParse .__module__ = "matplotlib.mathtext"
@@ -212,7 +213,7 @@ class FontInfo(NamedTuple):
212
213
fontsize : float
213
214
postscript_name : str
214
215
metrics : FontMetrics
215
- num : int
216
+ num : CharacterCodeType
216
217
glyph : Glyph
217
218
offset : float
218
219
@@ -365,7 +366,7 @@ def _get_offset(self, font: FT2Font, glyph: Glyph, fontsize: float,
365
366
return 0.
366
367
367
368
def _get_glyph (self , fontname : str , font_class : str ,
368
- sym : str ) -> tuple [FT2Font , int , bool ]:
369
+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
369
370
raise NotImplementedError
370
371
371
372
# 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
459
460
_slanted_symbols = set (r"\int \oint" .split ())
460
461
461
462
def _get_glyph (self , fontname : str , font_class : str ,
462
- sym : str ) -> tuple [FT2Font , int , bool ]:
463
+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
463
464
font = None
464
465
if fontname in self .fontmap and sym in latex_to_bakoma :
465
466
basename , num = latex_to_bakoma [sym ]
@@ -551,7 +552,7 @@ class UnicodeFonts(TruetypeFonts):
551
552
# Some glyphs are not present in the `cmr10` font, and must be brought in
552
553
# from `cmsy10`. Map the Unicode indices of those glyphs to the indices at
553
554
# which they are found in `cmsy10`.
554
- _cmr10_substitutions = {
555
+ _cmr10_substitutions : dict [ CharacterCodeType , CharacterCodeType ] = {
555
556
0x00D7 : 0x00A3 , # Multiplication sign.
556
557
0x2212 : 0x00A1 , # Minus sign.
557
558
}
@@ -594,11 +595,11 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
594
595
_slanted_symbols = set (r"\int \oint" .split ())
595
596
596
597
def _map_virtual_font (self , fontname : str , font_class : str ,
597
- uniindex : int ) -> tuple [str , int ]:
598
+ uniindex : CharacterCodeType ) -> tuple [str , CharacterCodeType ]:
598
599
return fontname , uniindex
599
600
600
601
def _get_glyph (self , fontname : str , font_class : str ,
601
- sym : str ) -> tuple [FT2Font , int , bool ]:
602
+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
602
603
try :
603
604
uniindex = get_unicode_index (sym )
604
605
found_symbol = True
@@ -607,8 +608,7 @@ def _get_glyph(self, fontname: str, font_class: str,
607
608
found_symbol = False
608
609
_log .warning ("No TeX to Unicode mapping for %a." , sym )
609
610
610
- fontname , uniindex = self ._map_virtual_font (
611
- fontname , font_class , uniindex )
611
+ fontname , uniindex = self ._map_virtual_font (fontname , font_class , uniindex )
612
612
613
613
new_fontname = fontname
614
614
@@ -693,7 +693,7 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
693
693
self .fontmap [name ] = fullpath
694
694
695
695
def _get_glyph (self , fontname : str , font_class : str ,
696
- sym : str ) -> tuple [FT2Font , int , bool ]:
696
+ sym : str ) -> tuple [FT2Font , CharacterCodeType , bool ]:
697
697
# Override prime symbol to use Bakoma.
698
698
if sym == r'\prime' :
699
699
return self .bakoma ._get_glyph (fontname , font_class , sym )
@@ -783,7 +783,7 @@ def __init__(self, default_font_prop: FontProperties, load_glyph_flags: LoadFlag
783
783
self .fontmap [name ] = fullpath
784
784
785
785
def _map_virtual_font (self , fontname : str , font_class : str ,
786
- uniindex : int ) -> tuple [str , int ]:
786
+ uniindex : CharacterCodeType ) -> tuple [str , CharacterCodeType ]:
787
787
# Handle these "fonts" that are actually embedded in
788
788
# other fonts.
789
789
font_mapping = stix_virtual_fonts .get (fontname )
@@ -1170,7 +1170,7 @@ def __init__(self, elements: T.Sequence[Node]):
1170
1170
self .glue_sign = 0 # 0: normal, -1: shrinking, 1: stretching
1171
1171
self .glue_order = 0 # The order of infinity (0 - 3) for the glue
1172
1172
1173
- def __repr__ (self ):
1173
+ def __repr__ (self ) -> str :
1174
1174
return "{}<w={:.02f} h={:.02f} d={:.02f} s={:.02f}>[{}]" .format (
1175
1175
super ().__repr__ (),
1176
1176
self .width , self .height ,
0 commit comments