38
38
39
39
if T .TYPE_CHECKING :
40
40
from collections .abc import Iterable
41
- from .ft2font import CharacterCodeType , Glyph
41
+ from .ft2font import CharacterCodeType , Glyph , GlyphIndexType
42
42
43
43
44
44
ParserElement .enable_packrat ()
@@ -87,7 +87,7 @@ class VectorParse(NamedTuple):
87
87
width : float
88
88
height : float
89
89
depth : float
90
- glyphs : list [tuple [FT2Font , float , CharacterCodeType , float , float ]]
90
+ glyphs : list [tuple [FT2Font , float , CharacterCodeType , GlyphIndexType , float , float ]]
91
91
rects : list [tuple [float , float , float , float ]]
92
92
93
93
VectorParse .__module__ = "matplotlib.mathtext"
@@ -132,7 +132,8 @@ def __init__(self, box: Box):
132
132
def to_vector (self ) -> VectorParse :
133
133
w , h , d = map (
134
134
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 )
136
137
for ox , oy , info in self .glyphs ]
137
138
rs = [(x1 , h - y2 , x2 - x1 , y2 - y1 )
138
139
for x1 , y1 , x2 , y2 in self .rects ]
@@ -215,6 +216,7 @@ class FontInfo(NamedTuple):
215
216
postscript_name : str
216
217
metrics : FontMetrics
217
218
num : CharacterCodeType
219
+ glyph_index : GlyphIndexType
218
220
glyph : Glyph
219
221
offset : float
220
222
@@ -375,7 +377,8 @@ def _get_info(self, fontname: str, font_class: str, sym: str, fontsize: float,
375
377
dpi : float ) -> FontInfo :
376
378
font , num , slanted = self ._get_glyph (fontname , font_class , sym )
377
379
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 )
379
382
380
383
xmin , ymin , xmax , ymax = (val / 64 for val in glyph .bbox )
381
384
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,
398
401
postscript_name = font .postscript_name ,
399
402
metrics = metrics ,
400
403
num = num ,
404
+ glyph_index = glyph_index ,
401
405
glyph = glyph ,
402
406
offset = offset
403
407
)
@@ -427,8 +431,7 @@ def get_kern(self, font1: str, fontclass1: str, sym1: str, fontsize1: float,
427
431
info1 = self ._get_info (font1 , fontclass1 , sym1 , fontsize1 , dpi )
428
432
info2 = self ._get_info (font2 , fontclass2 , sym2 , fontsize2 , dpi )
429
433
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 ,
432
435
Kerning .DEFAULT ) / 64
433
436
return super ().get_kern (font1 , fontclass1 , sym1 , fontsize1 ,
434
437
font2 , fontclass2 , sym2 , fontsize2 , dpi )
0 commit comments