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

Skip to content

Commit b196309

Browse files
committed
Merge pull request #2088 from cgohlke/patch-4
Fix `KeyError: (1, 0, 0, 6)` in backend_ps on Windows
2 parents f84d089 + 5eaf7e6 commit b196309

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

lib/matplotlib/backends/backend_ps.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,13 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
748748
self.track_characters(font, s)
749749

750750
self.set_color(*gc.get_rgb())
751-
self.set_font(font.get_sfnt()[(1,0,0,6)], prop.get_size_in_points())
751+
sfnt = font.get_sfnt()
752+
try:
753+
ps_name = sfnt[(1,0,0,6)]
754+
except KeyError:
755+
ps_name = sfnt[(3,1,0x0409,6)].decode(
756+
'utf-16be').encode('ascii','replace')
757+
self.set_font(ps_name, prop.get_size_in_points())
752758

753759
cmap = font.get_charmap()
754760
lastgind = None

lib/matplotlib/textpath.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ def _get_char_id(self, font, ccode):
6161
"""
6262
Return a unique id for the given font and character-code set.
6363
"""
64-
ps_name = font.get_sfnt()[(1, 0, 0, 6)]
64+
sfnt = font.get_sfnt()
65+
try:
66+
ps_name = sfnt[(1,0,0,6)]
67+
except KeyError:
68+
ps_name = sfnt[(3,1,0x0409,6)].decode(
69+
'utf-16be').encode('ascii','replace')
6570
char_id = urllib.quote('%s-%x' % (ps_name, ccode))
6671
return char_id
6772

0 commit comments

Comments
 (0)