From a1c69dd1a1a1baf1376551a57bd5ffb1df687c23 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 2 Sep 2021 11:59:54 +0200 Subject: [PATCH] Rename symbol_name to glyph_name where appropriate. When referring to a font glyph, "glyph name" is standard terminology (e.g. FT_Get_Glyph_Name or Adobe docs); additionally there is a separate concept of "symbol_name" used by the mathtext parser which has a different meaning (`\foo` commands referring to TeX symbol names), so let's not confuse them. symbol_name is kept in the mathtext SimpleNamespaces for backcompat (changing the SimpleNamespace to a proper class with a property handling the deprecation is not worth the work). --- lib/matplotlib/_mathtext.py | 24 +++++++++++++----------- lib/matplotlib/backends/backend_pdf.py | 12 ++++++------ lib/matplotlib/backends/backend_ps.py | 4 ++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index bbb247ec02fe..73e6163944e1 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -264,7 +264,7 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True): if bunch is not None: return bunch - font, num, symbol_name, fontsize, slanted = \ + font, num, glyph_name, fontsize, slanted = \ self._get_glyph(fontname, font_class, sym, fontsize, math) font.set_size(fontsize, dpi) @@ -292,7 +292,8 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True): fontsize = fontsize, postscript_name = font.postscript_name, metrics = metrics, - symbol_name = symbol_name, + glyph_name = glyph_name, + symbol_name = glyph_name, # Backcompat alias. num = num, glyph = glyph, offset = offset @@ -358,7 +359,7 @@ def __init__(self, *args, **kwargs): _slanted_symbols = set(r"\int \oint".split()) def _get_glyph(self, fontname, font_class, sym, fontsize, math=True): - symbol_name = None + glyph_name = None font = None if fontname in self.fontmap and sym in latex_to_bakoma: basename, num = latex_to_bakoma[sym] @@ -373,13 +374,13 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True): if font is not None: gid = font.get_char_index(num) if gid != 0: - symbol_name = font.get_glyph_name(gid) + glyph_name = font.get_glyph_name(gid) - if symbol_name is None: + if glyph_name is None: return self._stix_fallback._get_glyph( fontname, font_class, sym, fontsize, math) - return font, num, symbol_name, fontsize, slanted + return font, num, glyph_name, fontsize, slanted # The Bakoma fonts contain many pre-sized alternatives for the # delimiters. The AutoSizedChar class will use these alternatives @@ -556,8 +557,8 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True): glyphindex = font.get_char_index(uniindex) slanted = False - symbol_name = font.get_glyph_name(glyphindex) - return font, uniindex, symbol_name, fontsize, slanted + glyph_name = font.get_glyph_name(glyphindex) + return font, uniindex, glyph_name, fontsize, slanted def get_sized_alternatives_for_symbol(self, fontname, sym): if self.cm_fallback: @@ -854,7 +855,7 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True): if found_symbol: try: - symbol_name = font.get_name_char(glyph) + glyph_name = font.get_name_char(glyph) except KeyError: _log.warning( "No glyph in standard Postscript font {!r} for {!r}" @@ -864,7 +865,7 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True): if not found_symbol: glyph = '?' num = ord(glyph) - symbol_name = font.get_name_char(glyph) + glyph_name = font.get_name_char(glyph) offset = 0 @@ -890,7 +891,8 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True): fontsize = fontsize, postscript_name = font.get_fontname(), metrics = metrics, - symbol_name = symbol_name, + glyph_name = glyph_name, + symbol_name = glyph_name, # Backcompat alias. num = num, glyph = glyph, offset = offset diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 9ca791db0c5a..bd0c370f1cba 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -1063,12 +1063,12 @@ def createType1Descriptor(self, t1font, fontfile): return fontdescObject - def _get_xobject_symbol_name(self, filename, symbol_name): + def _get_xobject_glyph_name(self, filename, glyph_name): Fx = self.fontName(filename) return "-".join([ Fx.name.decode(), os.path.splitext(os.path.basename(filename))[0], - symbol_name]) + glyph_name]) _identityToUnicodeCMap = b"""/CIDInit /ProcSet findresource begin 12 dict begin @@ -1204,7 +1204,7 @@ def get_char_width(charcode): # Send the glyphs with ccode > 255 to the XObject dictionary, # and the others to the font itself if charname in multi_byte_chars: - name = self._get_xobject_symbol_name(filename, charname) + name = self._get_xobject_glyph_name(filename, charname) self.multi_byte_charprocs[name] = charprocObject else: charprocs[charname] = charprocObject @@ -1347,7 +1347,7 @@ def embedTTFType42(font, characters, descriptor): self.currentstream.write(stream) self.endStream() - name = self._get_xobject_symbol_name(filename, charname) + name = self._get_xobject_glyph_name(filename, charname) self.multi_byte_charprocs[name] = charprocObject # CIDToGIDMap stream @@ -2417,8 +2417,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): def _draw_xobject_glyph(self, font, fontsize, glyph_idx, x, y): """Draw a multibyte character from a Type 3 font as an XObject.""" - symbol_name = font.get_glyph_name(glyph_idx) - name = self.file._get_xobject_symbol_name(font.fname, symbol_name) + glyph_name = font.get_glyph_name(glyph_idx) + name = self.file._get_xobject_glyph_name(font.fname, glyph_name) self.file.output( Op.gsave, 0.001 * fontsize, 0, 0, 0.001 * fontsize, x, y, Op.concat_matrix, diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 93d0705ae363..c44f89c638d9 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -701,12 +701,12 @@ def draw_mathtext(self, gc, x, y, s, prop, angle): lastfont = font.postscript_name, fontsize self._pswriter.write( f"/{font.postscript_name} {fontsize} selectfont\n") - symbol_name = ( + glyph_name = ( font.get_name_char(chr(num)) if isinstance(font, AFM) else font.get_glyph_name(font.get_char_index(num))) self._pswriter.write( f"{ox:f} {oy:f} moveto\n" - f"/{symbol_name} glyphshow\n") + f"/{glyph_name} glyphshow\n") for ox, oy, w, h in rects: self._pswriter.write(f"{ox} {oy} {w} {h} rectfill\n") self._pswriter.write("grestore\n")