Permalink
Browse files

Use macroman rather than ascii to decode SFNT table names

  • Loading branch information...
1 parent 876a2ed commit bd191d50823b8797c765d86e227e4ca4f8595c31 @mdboom mdboom committed Aug 26, 2013
@@ -1002,11 +1002,12 @@ def embedTTFType42(font, characters, descriptor):
# You are lost in a maze of TrueType tables, all different...
sfnt = font.get_sfnt()
try:
- ps_name = sfnt[(1,0,0,6)] # Macintosh scheme
+ ps_name = sfnt[(1,0,0,6)].decode('macroman') # Macintosh scheme
except KeyError:
# 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)
+ ps_name = ps_name.encode('ascii', 'replace')
ps_name = Name(ps_name)
pclt = font.get_sfnt_table('pclt') \
or { 'capHeight': 0, 'xHeight': 0 }
@@ -750,10 +750,11 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
self.set_color(*gc.get_rgb())
sfnt = font.get_sfnt()
try:
- ps_name = sfnt[(1,0,0,6)]
+ ps_name = sfnt[(1,0,0,6)].decode('macroman')
except KeyError:
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())
cmap = font.get_charmap()
@@ -391,11 +391,11 @@ def ttfFontProperty(font):
sfnt2 = sfnt.get((1,0,0,2))
sfnt4 = sfnt.get((1,0,0,4))
if sfnt2:
- sfnt2 = sfnt2.decode('ascii').lower()
+ sfnt2 = sfnt2.decode('macroman').lower()
else:
sfnt2 = ''
if sfnt4:
- sfnt4 = sfnt4.decode('ascii').lower()
+ sfnt4 = sfnt4.decode('macroman').lower()
else:
sfnt4 = ''
if sfnt4.find('oblique') >= 0:
@@ -63,7 +63,7 @@ def _get_char_id(self, font, ccode):
"""
sfnt = font.get_sfnt()
try:
- ps_name = sfnt[(1, 0, 0, 6)].decode('ascii')
+ ps_name = sfnt[(1, 0, 0, 6)].decode('macroman')
except KeyError:
ps_name = sfnt[(3, 1, 0x0409, 6)].decode('utf-16be')
char_id = urllib.quote('%s-%x' % (ps_name, ccode))

0 comments on commit bd191d5

Please sign in to comment.