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 a0f30cf

Browse filesBrowse files
committed
Avoid using MacRoman encoding.
... as support for it may be missing in some alternate Python implementations. 1) For fetching the postscript name of a font, we can just use FT_Get_Postscript_Name (the .postscript_name attribute in FT2Font), which is exactly implemented in the same way (see the private sfnt_get_ps_name in the FreeType sources). 2) In ttfFontProperty, we are only looking for ASCII substrings (and MacRoman is not a multibyte encoding), so any ASCII compatible encoding works. The only remaining instance of MacRoman is in the implementation of SVG fonts in the SVG backend, but that feature is itself deprecated.
1 parent 31d2c2f commit a0f30cf
Copy full SHA for a0f30cf

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
@@ -329,16 +329,11 @@ def ttfFontProperty(font):
329329
# Styles are: italic, oblique, and normal (default)
330330

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