8000 Unicode issue in EPS output when using custom font by mdboom · Pull Request #2523 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Unicode issue in EPS output when using custom font #2523

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
Oct 18, 2013
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
14 changes: 7 additions & 7 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
except KeyError:
ps_name = sfnt[(3,1,0x0409,6)].decode(
'utf-16be')
ps_name = ps_name.encode('ascii','replace')
ps_name = ps_name.encode('ascii', 'replace')
self.set_font(ps_name, prop.get_size_in_points())

cmap = font.get_charmap()
Expand Down Expand Up @@ -1184,7 +1184,7 @@ def print_figure_impl():
# We are going to use an external program to process the output.
# Write to a temporary file.
fd, tmpfile = mkstemp()
with io.open(fd, 'w', encoding='ascii') as fh:
with io.open(fd, 'w', encoding='latin-1') as fh:
print_figure_impl()
else:
# Write directly to outfile.
Expand All @@ 8000 -1193,7 +1193,7 @@ def print_figure_impl():

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

print_figure_impl()
else:
with io.open(outfile, 'w', encoding='ascii') as fh:
with io.open(outfile, 'w', encoding='latin-1') as fh:
print_figure_impl()

if rcParams['ps.usedistiller']:
Expand All @@ -1216,7 +1216,7 @@ def do_nothing():
if passed_in_file_object:
if file_requires_unicode(outfile):
with io.open(tmpfile, 'rb') as fh:
outfile.write(fh.read().decode('ascii'))
outfile.write(fh.read().decode('latin-1'))
else:
with io.open(tmpfile, 'rb') as fh:
outfile.write(fh.read())
Expand Down Expand Up @@ -1290,7 +1290,7 @@ def write(self, *kl, **kwargs):

# write to a temp file, we'll move it to outfile when done
fd, tmpfile = mkstemp()
with io.open(fd, 'w', encoding='ascii') as fh:
with io.open(fd, 'w', encoding='latin-1') as fh:
# write the Encapsulated PostScript headers
print("%!PS-Adobe-3.0 EPSF-3.0", file=fh)
if title: print("%%Title: "+title, file=fh)
Expand Down Expand Up @@ -1373,7 +1373,7 @@ def write(self, *kl, **kwargs):
if is_writable_file_like(outfile):
if file_requires_unicode(outfile):
with io.open(tmpfile, 'rb') as fh:
outfile.write(fh.read().decode('ascii'))
outfile.write(fh.read().decode('latin-1'))
else:
with io.open(tmpfile, 'rb') as fh:
outfile.write(fh.read())
Expand Down
6 changes: 1 addition & 5 deletions src/_ttconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,13 @@ class PythonFileWriter : public TTStreamWriter
PyObject* result = NULL;
if (_write_method)
{
#if PY3K
result = PyObject_CallFunction(_write_method, (char *)"s", a);
#else
PyObject* decoded = NULL;
decoded = PyUnicode_FromString(a);
decoded = PyUnicode_DecodeLatin1(a, strlen(a), "");
if (decoded == NULL) {
throw PythonExceptionOccurred();
}
result = PyObject_CallFunction(_write_method, "O", decoded);
Py_DECREF(decoded);
#endif
if (! result)
{
throw PythonExceptionOccurred();
Expand Down
0