Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4df33d2

Browse files
committed
Stop computing glyph_name in mathtext font handling.
None of the MathtextBackends actually accesses the .glyph_name attribute anymore, and they are the only public API that can interact with the glyph infos returned by the Fonts classes (and there is no public API to register new MathtextBackends).
1 parent 2ad10de commit 4df33d2

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True):
245245
if bunch is not None:
246246
return bunch
247247

248-
font, num, glyph_name, fontsize, slanted = \
249-
self._get_glyph(fontname, font_class, sym, fontsize, math)
248+
font, num, fontsize, slanted = self._get_glyph(
249+
fontname, font_class, sym, fontsize, math)
250250

251251
font.set_size(fontsize, dpi)
252252
glyph = font.load_char(
@@ -273,8 +273,6 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True):
273273
fontsize = fontsize,
274274
postscript_name = font.postscript_name,
275275
metrics = metrics,
276-
glyph_name = glyph_name,
277-
symbol_name = glyph_name, # Backcompat alias.
278276
num = num,
279277
glyph = glyph,
280278
offset = offset
@@ -340,7 +338,6 @@ def __init__(self, *args, **kwargs):
340338
_slanted_symbols = set(r"\int \oint".split())
341339

342340
def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
343-
glyph_name = None
344341
font = None
345342
if fontname in self.fontmap and sym in latex_to_bakoma:
346343
basename, num = latex_to_bakoma[sym]
@@ -351,18 +348,12 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
351348
font = self._get_font(fontname)
352349
if font is not None:
353350
num = ord(sym)
354-
355-
if font is not None:
356-
gid = font.get_char_index(num)
357-
if gid != 0:
358-
glyph_name = font.get_glyph_name(gid)
359-
360-
if glyph_name is None:
351+
if font is not None and font.get_char_index(num) != 0:
352+
return font, num, fontsize, slanted
353+
else:
361354
return self._stix_fallback._get_glyph(
362355
fontname, font_class, sym, fontsize, math)
363356

364-
return font, num, glyph_name, fontsize, slanted
365-
366357
# The Bakoma fonts contain many pre-sized alternatives for the
367358
# delimiters. The AutoSizedChar class will use these alternatives
368359
# and select the best (closest sized) glyph.
@@ -532,14 +523,11 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
532523
_log.warning("Font {!r} does not have a glyph for {!a} "
533524
"[U+{:x}], substituting with a dummy "
534525
"symbol.".format(new_fontname, sym, uniindex))
535-
fontname = 'rm'
536-
font = self._get_font(fontname)
526+
font = self._get_font('rm')
537527
uniindex = 0xA4 # currency char, for lack of anything better
538-
glyphindex = font.get_char_index(uniindex)
539528
slanted = False
540529

541-
glyph_name = font.get_glyph_name(glyphindex)
542-
return font, uniindex, glyph_name, fontsize, slanted
530+
return font, uniindex, fontsize, slanted
543531

544532
def get_sized_alternatives_for_symbol(self, fontname, sym):
545533
if self.cm_fallback:

0 commit comments

Comments
 (0)