8000 Merge pull request #2523 from mdboom/ps-unicode-error · matplotlib/matplotlib@f9c62d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9c62d2

Browse files
committed
Merge pull request #2523 from mdboom/ps-unicode-error
Unicode issue in EPS output when using custom font
2 parents a3d2992 + 0788c28 commit f9c62d2

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
756756
except KeyError:
757757
ps_name = sfnt[(3,1,0x0409,6)].decode(
758758
'utf-16be')
759-
ps_name = ps_name.encode('ascii','replace')
759+
ps_name = ps_name.encode('ascii', 'replace')
760760
self.set_font(ps_name, prop.get_size_in_points())
761761

762762
cmap = font.get_charmap()
@@ -1184,7 +1184,7 @@ def print_figure_impl():
11841184
# We are going to use an external program to process the output.
11851185
# Write to a temporary file.
11861186
fd, tmpfile = mkstemp()
1187-
with io.open(fd, 'w', encoding='ascii') as fh:
1187+
with io.open(fd, 'w', encoding='latin-1') as fh:
11881188
print_figure_impl()
11891189
else:
11901190
# Write directly to outfile.
@@ -1193,7 +1193,7 @@ def print_figure_impl():
11931193

11941194
if (not requires_unicode and
11951195
(six.PY3 or not isinstance(outfile, StringIO))):
1196-
fh = io.TextIOWrapper(outfile, encoding="ascii")
1196+
fh = io.TextIOWrapper(outfile, encoding="latin-1")
11971197
# Prevent the io.TextIOWrapper from closing the
11981198
# underlying file
11991199
def do_nothing():
@@ -1204,7 +1204,7 @@ def do_nothing():
12041204

12051205
print_figure_impl()
12061206
else:
1207-
with io.open(outfile, 'w', encoding='ascii') as fh:
1207+
with io.open(outfile, 'w', encoding='latin-1') as fh:
12081208
print_figure_impl()
12091209

12101210
if rcParams['ps.usedistiller']:
@@ -1216,7 +1216,7 @@ def do_nothing():
12161216
if passed_in_file_object:
12171217
if file_requires_unicode(outfile):
12181218
with io.open(tmpfile, 'rb') as fh:
1219-
outfile.write(fh.read().decode('ascii'))
1219+
outfile.write(fh.read().decode('latin-1'))
12201220
else:
12211221
with io.open(tmpfile, 'rb') as fh:
12221222
outfile.write(fh.read())
@@ -1290,7 +1290,7 @@ def write(self, *kl, **kwargs):
12901290

12911291
# write to a temp file, we'll move it to outfile when done
12921292
fd, tmpfile = mkstemp()
1293-
with io.open(fd, 'w', encoding='ascii') as fh:
1293+
with io.open(fd, 'w', encoding='latin-1') as fh:
12941294
# write the Encapsulated PostScript headers
12951295
print("%!PS-Adobe-3.0 EPSF-3.0", file=fh)
12961296
if title: print("%%Title: "+title, file=fh)
@@ -1373,7 +1373,7 @@ def write(self, *kl, **kwargs):
13731373
if is_writable_file_like(outfile):
13741374
if file_requires_unicode(outfile):
13751375
with io.open(tmpfile, 'rb') as fh:
1376-
outfile.write(fh.read().decode('ascii'))
1376+
outfile.write(fh.read().decode('latin-1'))
13771377
else:
13781378
with io.open(tmpfile, 'rb') as fh:
13791379
outfile.write(fh.read())

src/_ttconv.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@ class PythonFileWriter : public TTStreamWriter
4848
PyObject* result = NULL;
4949
if (_write_method)
5050
{
51-
#if PY3K
52-
result = PyObject_CallFunction(_write_method, (char *)"s", a);
53-
#else
5451
PyObject* decoded = NULL;
55-
decoded = PyUnicode_FromString(a);
52+
decoded = PyUnicode_DecodeLatin1(a, strlen(a), "");
5653
if (decoded == NULL) {
5754
throw PythonExceptionOccurred();
5855
}
5956
result = PyObject_CallFunction(_write_method, "O", decoded);
6057
Py_DECREF(decoded);
61-
#endif
6258
if (! result)
6359
{
6460
throw PythonExceptionOccurred();

0 commit comments

Comments
 (0)
0