Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd6f9d8

Browse files
committed
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...
1 parent 1c06de3 commit cd6f9d8

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

lib/matplotlib/afm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ def _parse_char_metrics(fh):
244244
# Reference).
245245
if name == 'Euro':
246246
num = 128
247+
elif name == 'minus':
248+
num = ord("\N{MINUS SIGN}") # 0x2212
247249
if num != -1:
248250
ascii_d[num] = metrics
249251
name_d[name] = metrics

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@
4545
'eps afm',
4646
'eps with usetex'
4747
])
48-
def test_savefig_to_stringio(format, use_log, rcParams):
48+
def test_savefig_to_stringio(format, use_log, rcParams, monkeypatch):
4949
mpl.rcParams.update(rcParams)
50+
monkeypatch.setenv("SOURCE_DATE_EPOCH", "0") # For reproducibility.
5051

5152
fig, ax = plt.subplots()
5253

@@ -56,17 +57,16 @@ def test_savefig_to_stringio(format, use_log, rcParams):
5657
ax.set_yscale('log')
5758

5859
ax.plot([1, 2], [1, 2])
59-
ax.set_title("Déjà vu")
60+
title = "Déjà vu"
61+
if not mpl.rcParams["text.usetex"]:
62+
title += " \N{MINUS SIGN}\N{EURO SIGN}"
63+
ax.set_title(title)
6064
fig.savefig(s_buf, format=format)
6165
fig.savefig(b_buf, format=format)
6266

6367
s_val = s_buf.getvalue().encode('ascii')
6468
b_val = b_buf.getvalue()
6569

66-
# Remove comments from the output. This includes things that could
67-
# change from run to run, such as the time.
68-
s_val, b_val = [re.sub(b'%%.*?\n', b'', x) for x in [s_val, b_val]]
69-
7070
assert s_val == b_val.replace(b'\r\n', b'\n')
7171

7272

0 commit comments

Comments
 (0)