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

Skip to content

Commit 6b4827a

Browse files
committed
Fixed encoding issue in SVG backend
1 parent 31af0e7 commit 6b4827a

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/matplotlib/textpath.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ def __init__(self):
4444

4545
self._texmanager = None
4646

47-
self._adobe_standard_encoding = None
48-
49-
def _get_adobe_standard_encoding(self):
50-
enc_name = dviread.find_tex_file('8a.enc')
51-
enc = dviread.Encoding(enc_name)
52-
return {c: i for i, c in enumerate(enc.encoding)}
53-
5447
def _get_font(self, prop):
5548
"""
5649
find a ttf font.
@@ -299,14 +292,12 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
299292
# codes are modstly borrowed from pdf backend.
300293

301294
texmanager = self.get_texmanager()
295+
use_glyph = False
302296

303297
if self.tex_font_map is None:
304298
self.tex_font_map = dviread.PsfontsMap(
305299
dviread.find_tex_file('pdftex.map'))
306300

307-
if self._adobe_standard_encoding is None:
308-
self._adobe_standard_encoding = self._get_adobe_standard_encoding()
309-
310301
fontsize = prop.get_size_in_points()
311302
if hasattr(texmanager, "get_dvi"):
312303
dvifilelike = texmanager.get_dvi(s, self.FONT_SCALE)
@@ -358,11 +349,21 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
358349
warnings.warn("No supported encoding in font (%s)." %
359350
font_bunch.filename)
360351

352+
# Character is a glyph and needs to be mapped to corresponding index
361353
if charmap_name == "ADOBE_STANDARD" and font_bunch.encoding:
354+
use_glyph = True
362355
enc0 = dviread.Encoding(font_bunch.encoding)
363-
enc = {i: self._adobe_standard_encoding.get(c, None)
364-
for i, c in enumerate(enc0.encoding)}
356+
357+
# Make a list of each glyph by splitting the encoding
358+
enc0_list = []
359+
for e in enc0.encoding:
360+
enc0_list += e.split("/")
361+
362+
# Encoding provided by the font file mapping names to index
363+
enc = {i: font.get_name_index(c) or None
364+
for i, c in enumerate(enc0_list)}
365365
else:
366+
use_glyph = False
366367
enc = {}
367368
self._ps_fontd[dvifont.texname] = font, enc
368369

@@ -382,7 +383,10 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
382383
charcode = glyph
383384

384385
if charcode is not None:
385-
glyph0 = font.load_char(charcode, flags=ft2font_flag)
386+
if use_glyph:
387+
glyph0 = font.load_glyph(charcode, flags=ft2font_flag)
388+
else:
389+
glyph0 = font.load_char(charcode, flags=ft2font_flag)
386390
else:
387391
warnings.warn("The glyph (%d) of font (%s) cannot be "
388392
"converted with the encoding. Glyph may "

0 commit comments

Comments
 (0)