From 138d959060a4cc0c6d6f4a7eaebbf52e7c33b6bb Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 6 May 2013 12:46:50 -0400 Subject: [PATCH] Fix including Type 42 fonts in PDF on Python 3.x --- lib/matplotlib/backends/backend_pdf.py | 2 +- lib/matplotlib/tests/test_backend_pdf.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 6373aca6d2aa..ff36324c6444 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -970,7 +970,7 @@ def embedTTFType42(font, characters, descriptor): " ".join(["<%04x>" % x for x in range(start, end+1)]))) unicode_cmap = (self._identityToUnicodeCMap % (len(unicode_groups), - "\n".join(unicode_bfrange))) + "\n".join(unicode_bfrange))).encode('ascii') # CIDToGIDMap stream cid_to_gid_map = "".join(cid_to_gid_map).encode("utf-16be") diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index 63b2b7c2b397..5d4e0e136806 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -22,3 +22,15 @@ def test_use14corefonts(): plt.title(title) plt.text(0.5, 0.5, text, horizontalalignment='center', fontsize=24) plt.axhline(0.5, linewidth=0.5) + + +def test_type42(): + import io + + rcParams['backend'] = 'pdf' + rcParams['pdf.fonttype'] = 42 + + fig = plt.figure() + ax = fig.add_subplot(111) + ax.plot([1,2,3]) + fig.savefig(io.BytesIO())