Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ebac433

Browse filesBrowse files
authored
Merge pull request #11277 from anntzer/nomacroman
Avoid using MacRoman encoding.
2 parents f87c686 + a2287b1 commit ebac433
Copy full SHA for ebac433

File tree

4 files changed

+9
-32
lines changed
Filter options

4 files changed

+9
-32
lines changed

‎lib/matplotlib/backends/backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pdf.py
+1-9Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,15 +1129,7 @@ def embedTTFType42(font, characters, descriptor):
11291129

11301130
# Beginning of main embedTTF function...
11311131

1132-
# You are lost in a maze of TrueType tables, all different...
1133-
sfnt = font.get_sfnt()
1134-
try:
1135-
ps_name = sfnt[1, 0, 0, 6].decode('mac_roman') # Macintosh scheme
1136-
except KeyError:
1137-
# Microsoft scheme:
1138-
ps_name = sfnt[3, 1, 0x0409, 6].decode('utf-16be')
1139-
# (see freetype/ttnameid.h)
1140-
ps_name = ps_name.encode('ascii', 'replace')
1132+
ps_name = font.postscript_name.encode('ascii', 'replace')
11411133
ps_name = Name(ps_name)
11421134
pclt = font.get_sfnt_table('pclt') or {'capHeight': 0, 'xHeight': 0}
11431135
post = font.get_sfnt_table('post') or {'italicAngle': (0, 0)}

‎lib/matplotlib/backends/backend_ps.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_ps.py
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -708,12 +708,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
708708
self.track_characters(font, s)
709709

710710
self.set_color(*gc.get_rgb())
711-
sfnt = font.get_sfnt()
712-
try:
713-
ps_name = sfnt[1, 0, 0, 6].decode('mac_roman')
714-
except KeyError:
715-
ps_name = sfnt[3, 1, 0x0409, 6].decode('utf-16be')
716-
ps_name = ps_name.encode('ascii', 'replace').decode('ascii')
711+
ps_name = (font.postscript_name
712+
.encode('ascii', 'replace').decode('ascii'))
717713
self.set_font(ps_name, prop.get_size_in_points())
718714

719715
lastgind = None

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+5-10Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,11 @@ def ttfFontProperty(font):
328328
# Styles are: italic, oblique, and normal (default)
329329

330330
sfnt = font.get_sfnt()
331-
sfnt2 = sfnt.get((1,0,0,2))
332-
sfnt4 = sfnt.get((1,0,0,4))
333-
if sfnt2:
334-
sfnt2 = sfnt2.decode('mac_roman').lower()
335-
else:
336-
sfnt2 = ''
337-
if sfnt4:
338-
sfnt4 = sfnt4.decode('mac_roman').lower()
339-
else:
340-
sfnt4 = ''
331+
# These tables are actually mac_roman-encoded, but mac_roman support may be
332+
# missing in some alternative Python implementations and we are only going
333+
# to look for ASCII substrings, where any ASCII-compatible encoding works.
334+
sfnt2 = sfnt.get((1, 0, 0, 2), b'').decode('latin-1').lower()
335+
sfnt4 = sfnt.get((1, 0, 0, 4), b'').decode('latin-1').lower()
341336
if sfnt4.find('oblique') >= 0:
342337
style = 'oblique'
343338
elif sfnt4.find('italic') >= 0:

‎lib/matplotlib/textpath.py

Copy file name to clipboardExpand all lines: lib/matplotlib/textpath.py
+1-7Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ def _get_char_id(self, font, ccode):
5656
"""
5757
Return a unique id for the given font and character-code set.
5858
"""
59-
sfnt = font.get_sfnt()
60-
try:
61-
ps_name = sfnt[1, 0, 0, 6].decode('mac_roman')
62-
except KeyError:
63-
ps_name = sfnt[3, 1, 0x0409, 6].decode('utf-16be')
64-
char_id = urllib.parse.quote('%s-%x' % (ps_name, ccode))
65-
return char_id
59+
return urllib.parse.quote('{}-{}'.format(font.postscript_name, ccode))
6660

6761
def _get_char_id_ps(self, font, ccode):
6862
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.