mirror of https://github.com/pyodide/pyodide.git
Fix font encoding issue in a better way. matplotlib/matplotlib#11277
This commit is contained in:
parent
12b05ad373
commit
77266efdd0
|
@ -1,23 +1,85 @@
|
||||||
diff -ur matplotlib-2.2.2/lib/matplotlib/font_manager.py matplotlib-2.2.2/lib/matplotlib/font_manager.py
|
diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py
|
||||||
--- a/lib/matplotlib/font_manager.py 2018-03-17 14:03:23.000000000 -0400
|
index 4f248fde9..0fc17ea37 100644
|
||||||
+++ b/lib/matplotlib/font_manager.py 2018-05-16 16:56:49.399466649 -0400
|
--- a/lib/matplotlib/backends/backend_pdf.py
|
||||||
@@ -416,11 +419,17 @@
|
+++ b/lib/matplotlib/backends/backend_pdf.py
|
||||||
sfnt2 = sfnt.get((1,0,0,2))
|
@@ -1135,15 +1135,7 @@ end"""
|
||||||
sfnt4 = sfnt.get((1,0,0,4))
|
|
||||||
if sfnt2:
|
# 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)}
|
||||||
|
diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py
|
||||||
|
index 1aeee39a2..3d44b6f7f 100644
|
||||||
|
--- a/lib/matplotlib/backends/backend_ps.py
|
||||||
|
+++ b/lib/matplotlib/backends/backend_ps.py
|
||||||
|
@@ -714,12 +714,8 @@ grestore
|
||||||
|
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
|
||||||
|
diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py
|
||||||
|
index cdc82edbf..2ea6efc2d 100644
|
||||||
|
--- a/lib/matplotlib/font_manager.py
|
||||||
|
+++ b/lib/matplotlib/font_manager.py
|
||||||
|
@@ -413,16 +413,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()
|
- sfnt2 = sfnt2.decode('mac_roman').lower()
|
||||||
+ try:
|
- else:
|
||||||
+ sfnt2 = sfnt2.decode('mac_roman').lower()
|
- sfnt2 = ''
|
||||||
+ except LookupError:
|
- if sfnt4:
|
||||||
+ sfnt2 = sfnt2.decode('latin1').lower()
|
|
||||||
else:
|
|
||||||
sfnt2 = ''
|
|
||||||
if sfnt4:
|
|
||||||
- sfnt4 = sfnt4.decode('mac_roman').lower()
|
- sfnt4 = sfnt4.decode('mac_roman').lower()
|
||||||
+ try:
|
- else:
|
||||||
+ sfnt4 = sfnt4.decode('mac_roman').lower()
|
- sfnt4 = ''
|
||||||
+ except LookupError:
|
+ # These tables are actually mac_roman-encoded, but mac_roman support may be
|
||||||
+ sfnt4 = sfnt4.decode('latin1').lower()
|
+ # missing in some alternative Python implementations and we are only going
|
||||||
else:
|
+ # to look for ASCII substrings, where any ASCII-compatible encoding works.
|
||||||
sfnt4 = ''
|
+ 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:
|
if sfnt4.find('oblique') >= 0:
|
||||||
|
style = 'oblique'
|
||||||
|
elif sfnt4.find('italic') >= 0:
|
||||||
|
diff --git a/lib/matplotlib/textpath.py b/lib/matplotlib/textpath.py
|
||||||
|
index 5ee356774..89fcfb79c 100644
|
||||||
|
--- a/lib/matplotlib/textpath.py
|
||||||
|
+++ b/lib/matplotlib/textpath.py
|
||||||
|
@@ -68,13 +68,7 @@ class TextToPath(object):
|
||||||
|
"""
|
||||||
|
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_quote('%s-%x' % (ps_name, ccode))
|
||||||
|
- return char_id
|
||||||
|
+ return urllib_quote('%s-%x' % (font.postscript_name, ccode))
|
||||||
|
|
||||||
|
def _get_char_id_ps(self, font, ccode):
|
||||||
|
"""
|
||||||
|
|
Loading…
Reference in New Issue