Skip to content

Rename symbol_name to glyph_name where appropriate. #20974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}"
Expand All @@ -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

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down