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

Skip to content

Commit ffb3746

Browse files
committed
Merge pull request #2307 from mdboom/font-name-decoding
font_manager.py UnicodeDecodeError when starting ipython --pylab
2 parents b36b148 + bd191d5 commit ffb3746

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,11 +1002,12 @@ def embedTTFType42(font, characters, descriptor):
10021002
# You are lost in a maze of TrueType tables, all different...
10031003
sfnt = font.get_sfnt()
10041004
try:
1005-
ps_name = sfnt[(1,0,0,6)] # Macintosh scheme
1005+
ps_name = sfnt[(1,0,0,6)].decode('macroman') # Macintosh scheme
10061006
except KeyError:
10071007
# Microsoft scheme:
1008-
ps_name = sfnt[(3,1,0x0409,6)].decode('utf-16be').encode('ascii','replace')
1008+
ps_name = sfnt[(3,1,0x0409,6)].decode('utf-16be')
10091009
# (see freetype/ttnameid.h)
1010+
ps_name = ps_name.encode('ascii', 'replace')
10101011
ps_name = Name(ps_name)
10111012
pclt = font.get_sfnt_table('pclt') \
10121013
or { 'capHeight': 0, 'xHeight': 0 }

lib/matplotlib/backends/backend_ps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,11 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
750750
self.set_color(*gc.get_rgb())
751751
sfnt = font.get_sfnt()
752752
try:
753-
ps_name = sfnt[(1,0,0,6)]
753+
ps_name = sfnt[(1,0,0,6)].decode('macroman')
754754
except KeyError:
755755
ps_name = sfnt[(3,1,0x0409,6)].decode(
756-
'utf-16be').encode('ascii','replace')
756+
'utf-16be')
757+
ps_name = ps_name.encode('ascii','replace')
757758
self.set_font(ps_name, prop.get_size_in_points())
758759

759760
cmap = font.get_charmap()

lib/matplotlib/font_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,11 @@ def ttfFontProperty(font):
391391
sfnt2 = sfnt.get((1,0,0,2))
392392
sfnt4 = sfnt.get((1,0,0,4))
393393
if sfnt2:
394-
sfnt2 = sfnt2.decode('ascii').lower()
394+
sfnt2 = sfnt2.decode('macroman').lower()
395395
else:
396396
sfnt2 = ''
397397
if sfnt4:
398-
sfnt4 = sfnt4.decode('ascii').lower()
398+
sfnt4 = sfnt4.decode('macroman').lower()
399399
else:
400400
sfnt4 = ''
401401
if sfnt4.find('oblique') >= 0:

lib/matplotlib/texmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def __init__(self):
169169
ff = rcParams['font.family']
170170
if len(ff) == 1 and ff[0].lower() in self.font_families:
171171
self.font_family = ff[0].lower()
172-
elif ff.lower() in self.font_families:
172+
elif isinstance(ff, basestring) and ff.lower() in self.font_families:
173173
self.font_family = ff.lower()
174174
else:
175175
mpl.verbose.report(

lib/matplotlib/textpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _get_char_id(self, font, ccode):
6363
"""
6464
sfnt = font.get_sfnt()
6565
try:
66-
ps_name = sfnt[(1, 0, 0, 6)].decode('ascii')
66+
ps_name = sfnt[(1, 0, 0, 6)].decode('macroman')
6767
except KeyError:
6868
ps_name = sfnt[(3, 1, 0x0409, 6)].decode('utf-16be')
6969
char_id = urllib.quote('%s-%x' % (ps_name, ccode))

0 commit comments

Comments
 (0)