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

Skip to content

Avoid using MacRoman encoding. #11277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,15 +1129,7 @@ def embedTTFType42(font, characters, descriptor):

# Beginning of main embedTTF function...

# You are lost in a maze of TrueType tables, all different...
sfnt = font.get_sfnt()
try:
ps_name = sfnt[1, 0, 0, 6].decode('mac_roman') # Macintosh scheme
except KeyError:
# Microsoft scheme:
ps_name = sfnt[3, 1, 0x0409, 6].decode('utf-16be')
# (see freetype/ttnameid.h)
ps_name = ps_name.encode('ascii', 'replace')
ps_name = font.postscript_name.encode('ascii', 'replace')
ps_name = Name(ps_name)
pclt = font.get_sfnt_table('pclt') or {'capHeight': 0, 'xHeight': 0}
post = font.get_sfnt_table('post') or {'italicAngle': (0, 0)}
Expand Down
8 changes: 2 additions & 6 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,12 +708,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
self.track_characters(font, s)

self.set_color(*gc.get_rgb())
sfnt = font.get_sfnt()
try:
ps_name = sfnt[1, 0, 0, 6].decode('mac_roman')
except KeyError:
ps_name = sfnt[3, 1, 0x0409, 6].decode('utf-16be')
ps_name = ps_name.encode('ascii', 'replace').decode('ascii')
ps_name = (font.postscript_name
.encode('ascii', 'replace').decode('ascii'))
self.set_font(ps_name, prop.get_size_in_points())

lastgind = None
Expand Down
15 changes: 5 additions & 10 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,11 @@ def ttfFontProperty(font):
# Styles are: italic, oblique, and normal (default)

sfnt = font.get_sfnt()
sfnt2 = sfnt.get((1,0,0,2))
sfnt4 = sfnt.get((1,0,0,4))
if sfnt2:
sfnt2 = sfnt2.decode('mac_roman').lower()
else:
sfnt2 = ''
if sfnt4:
sfnt4 = sfnt4.decode('mac_roman').lower()
else:
sfnt4 = ''
# These tables are actually mac_roman-encoded, but mac_roman support may be
# missing in some alternative Python implementations and we are only going
# to look for ASCII substrings, where any ASCII-compatible encoding works.
sfnt2 = sfnt.get((1, 0, 0, 2), b'').decode('latin-1').lower()
sfnt4 = sfnt.get((1, 0, 0, 4), b'').decode('latin-1').lower()
if sfnt4.find('oblique') >= 0:
style = 'oblique'
elif sfnt4.find('italic') >= 0:
Expand Down
8 changes: 1 addition & 7 deletions lib/matplotlib/textpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ def _get_char_id(self, font, ccode):
"""
Return a unique id for the given font and character-code set.
"""
sfnt = font.get_sfnt()
try:
ps_name = sfnt[1, 0, 0, 6].decode('mac_roman')
except KeyError:
ps_name = sfnt[3, 1, 0x0409, 6].decode('utf-16be')
char_id = urllib.parse.quote('%s-%x' % (ps_name, ccode))
return char_id
return urllib.parse.quote('{}-{}'.format(font.postscript_name, ccode))

def _get_char_id_ps(self, font, ccode):
"""
Expand Down