From cd6f9d8879bfca7704659faebeee9f3182b78998 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 7 Jun 2019 14:35:21 +0200 Subject: [PATCH] Support unicode minus with ps.useafm. Really, the whole postscript font encoding system should be rethought, but for now, given that there's already special casing for \N{EURO SIGN}, I don't feel too bad adding another special case for \N{MINUS SIGN}. Note that the test has a `if not mpl.rcParams["text.usetex"]` clause because `\N{MINUS SIGN}` + usetex + useafm doesn't work yet... --- lib/matplotlib/afm.py | 2 ++ lib/matplotlib/tests/test_backend_ps.py | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/afm.py b/lib/matplotlib/afm.py index f0b9bfefcc9a..030fc19b37a7 100644 --- a/lib/matplotlib/afm.py +++ b/lib/matplotlib/afm.py @@ -244,6 +244,8 @@ def _parse_char_metrics(fh): # Reference). if name == 'Euro': num = 128 + elif name == 'minus': + num = ord("\N{MINUS SIGN}") # 0x2212 if num != -1: ascii_d[num] = metrics name_d[name] = metrics diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index f6932673b349..32daee439a41 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -45,8 +45,9 @@ 'eps afm', 'eps with usetex' ]) -def test_savefig_to_stringio(format, use_log, rcParams): +def test_savefig_to_stringio(format, use_log, rcParams, monkeypatch): mpl.rcParams.update(rcParams) + monkeypatch.setenv("SOURCE_DATE_EPOCH", "0") # For reproducibility. fig, ax = plt.subplots() @@ -56,17 +57,16 @@ def test_savefig_to_stringio(format, use_log, rcParams): ax.set_yscale('log') ax.plot([1, 2], [1, 2]) - ax.set_title("Déjà vu") + title = "Déjà vu" + if not mpl.rcParams["text.usetex"]: + title += " \N{MINUS SIGN}\N{EURO SIGN}" + ax.set_title(title) fig.savefig(s_buf, format=format) fig.savefig(b_buf, format=format) s_val = s_buf.getvalue().encode('ascii') b_val = b_buf.getvalue() - # Remove comments from the output. This includes things that could - # change from run to run, such as the time. - s_val, b_val = [re.sub(b'%%.*?\n', b'', x) for x in [s_val, b_val]] - assert s_val == b_val.replace(b'\r\n', b'\n')