Skip to content

Commit

Permalink
Use macroman rather than ascii to decode SFNT table names
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Aug 27, 2013
1 parent 876a2ed commit bd191d5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/matplotlib/backends/backend_pdf.py
Expand Up @@ -1002,11 +1002,12 @@ def embedTTFType42(font, characters, descriptor):
# You are lost in a maze of TrueType tables, all different... # You are lost in a maze of TrueType tables, all different...
sfnt = font.get_sfnt() sfnt = font.get_sfnt()
try: try:
ps_name = sfnt[(1,0,0,6)] # Macintosh scheme ps_name = sfnt[(1,0,0,6)].decode('macroman') # Macintosh scheme
except KeyError: except KeyError:
# Microsoft scheme: # Microsoft scheme:
ps_name = sfnt[(3,1,0x0409,6)].decode('utf-16be').encode('ascii','replace') ps_name = sfnt[(3,1,0x0409,6)].decode('utf-16be')
# (see freetype/ttnameid.h) # (see freetype/ttnameid.h)
ps_name = ps_name.encode('ascii', 'replace')
ps_name = Name(ps_name) ps_name = Name(ps_name)
pclt = font.get_sfnt_table('pclt') \ pclt = font.get_sfnt_table('pclt') \
or { 'capHeight': 0, 'xHeight': 0 } or { 'capHeight': 0, 'xHeight': 0 }
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/backends/backend_ps.py
Expand Up @@ -750,10 +750,11 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
self.set_color(*gc.get_rgb()) self.set_color(*gc.get_rgb())
sfnt = font.get_sfnt() sfnt = font.get_sfnt()
try: try:
ps_name = sfnt[(1,0,0,6)] ps_name = sfnt[(1,0,0,6)].decode('macroman')
except KeyError: except KeyError:
ps_name = sfnt[(3,1,0x0409,6)].decode( ps_name = sfnt[(3,1,0x0409,6)].decode(
'utf-16be').encode('ascii','replace') 'utf-16be')
ps_name = ps_name.encode('ascii','replace')
self.set_font(ps_name, prop.get_size_in_points()) self.set_font(ps_name, prop.get_size_in_points())


cmap = font.get_charmap() cmap = font.get_charmap()
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/font_manager.py
Expand Up @@ -391,11 +391,11 @@ def ttfFontProperty(font):
sfnt2 = sfnt.get((1,0,0,2)) sfnt2 = sfnt.get((1,0,0,2))
sfnt4 = sfnt.get((1,0,0,4)) sfnt4 = sfnt.get((1,0,0,4))
if sfnt2: if sfnt2:
sfnt2 = sfnt2.decode('ascii').lower() sfnt2 = sfnt2.decode('macroman').lower()
else: else:
sfnt2 = '' sfnt2 = ''
if sfnt4: if sfnt4:
sfnt4 = sfnt4.decode('ascii').lower() sfnt4 = sfnt4.decode('macroman').lower()
else: else:
sfnt4 = '' sfnt4 = ''
if sfnt4.find('oblique') >= 0: if sfnt4.find('oblique') >= 0:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/textpath.py
Expand Up @@ -63,7 +63,7 @@ def _get_char_id(self, font, ccode):
""" """
sfnt = font.get_sfnt() sfnt = font.get_sfnt()
try: try:
ps_name = sfnt[(1, 0, 0, 6)].decode('ascii') ps_name = sfnt[(1, 0, 0, 6)].decode('macroman')
except KeyError: except KeyError:
ps_name = sfnt[(3, 1, 0x0409, 6)].decode('utf-16be') ps_name = sfnt[(3, 1, 0x0409, 6)].decode('utf-16be')
char_id = urllib.quote('%s-%x' % (ps_name, ccode)) char_id = urllib.quote('%s-%x' % (ps_name, ccode))
Expand Down

0 comments on commit bd191d5

Please sign in to comment.