3838
3939if T .TYPE_CHECKING :
4040 from collections .abc import Iterable
41- from .ft2font import CharacterCodeType , Glyph
41+ from .ft2font import CharacterCodeType , Glyph , GlyphIndexType
4242
4343
4444ParserElement .enable_packrat ()
@@ -87,7 +87,7 @@ class VectorParse(NamedTuple):
8787 width : float
8888 height : float
8989 depth : float
90- glyphs : list [tuple [FT2Font , float , CharacterCodeType , float , float ]]
90+ glyphs : list [tuple [FT2Font , float , CharacterCodeType , GlyphIndexType , float , float ]]
9191 rects : list [tuple [float , float , float , float ]]
9292
9393VectorParse .__module__ = "matplotlib.mathtext"
@@ -132,7 +132,8 @@ def __init__(self, box: Box):
132132 def to_vector (self ) -> VectorParse :
133133 w , h , d = map (
134134 np .ceil , [self .box .width , self .box .height , self .box .depth ])
135- gs = [(info .font , info .fontsize , info .num , ox , h - oy + info .offset )
135+ gs = [(info .font , info .fontsize , info .num , info .glyph_index ,
136+ ox , h - oy + info .offset )
136137 for ox , oy , info in self .glyphs ]
137138 rs = [(x1 , h - y2 , x2 - x1 , y2 - y1 )
138139 for x1 , y1 , x2 , y2 in self .rects ]
@@ -215,6 +216,7 @@ class FontInfo(NamedTuple):
215216 postscript_name : str
216217 metrics : FontMetrics
217218 num : CharacterCodeType
219+ glyph_index : GlyphIndexType
218220 glyph : Glyph
219221 offset : float
220222
@@ -375,7 +377,8 @@ def _get_info(self, fontname: str, font_class: str, sym: str, fontsize: float,
375377 dpi : float ) -> FontInfo :
376378 font , num , slanted = self ._get_glyph (fontname , font_class , sym )
377379 font .set_size (fontsize , dpi )
378- glyph = font .load_char (num , flags = self .load_glyph_flags )
380+ glyph_index = font .get_char_index (num )
381+ glyph = font .load_glyph (glyph_index , flags = self .load_glyph_flags )
379382
380383 xmin , ymin , xmax , ymax = (val / 64 for val in glyph .bbox )
381384 offset = self ._get_offset (font , glyph , fontsize , dpi )
@@ -398,6 +401,7 @@ def _get_info(self, fontname: str, font_class: str, sym: str, fontsize: float,
398401 postscript_name = font .postscript_name ,
399402 metrics = metrics ,
400403 num = num ,
404+ glyph_index = glyph_index ,
401405 glyph = glyph ,
402406 offset = offset
403407 )
@@ -427,8 +431,7 @@ def get_kern(self, font1: str, fontclass1: str, sym1: str, fontsize1: float,
427431 info1 = self ._get_info (font1 , fontclass1 , sym1 , fontsize1 , dpi )
428432 info2 = self ._get_info (font2 , fontclass2 , sym2 , fontsize2 , dpi )
429433 font = info1 .font
430- return font .get_kerning (font .get_char_index (info1 .num ),
431- font .get_char_index (info2 .num ),
434+ return font .get_kerning (info1 .glyph_index , info2 .glyph_index ,
432435 Kerning .DEFAULT ) / 64
433436 return super ().get_kern (font1 , fontclass1 , sym1 , fontsize1 ,
434437 font2 , fontclass2 , sym2 , fontsize2 , dpi )
0 commit comments