8000 Fix some bugs in the STIX font mappings introduced a long time ago wh… · matplotlib/matplotlib@9a93a5c · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a93a5c

Browse files
astropy-buildbotddale
authored andcommitted
Fix some bugs in the STIX font mappings introduced a long time ago when the STIX fonts were updated. Add a number of regression tests to check for this kind of thing.
1 parent 781d8fe commit 9a93a5c

11 files changed

+9508
-16
lines changed

lib/matplotlib/_mathtext_data.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,17 +2355,17 @@
23552355
[
23562356
(0x0030, 0x0039, 'rm', 0x1d7d8), # 0-9
23572357
(0x0041, 0x0042, 'it', 0xe154), # A-B
2358-
(0x0043, 0x0043, 'it', 0x2102), # C (missing in beta STIX fonts)
2358+
(0x0043, 0x0043, 'it', 0x2102), # C
23592359
(0x0044, 0x0044, 'it', 0x2145), # D
23602360
(0x0045, 0x0047, 'it', 0xe156), # E-G
2361-
(0x0048, 0x0048, 'it', 0x210d), # H (missing in beta STIX fonts)
2361+
(0x0048, 0x0048, 'it', 0x210d), # H
23622362
(0x0049, 0x004d, 'it', 0xe159), # I-M
2363-
(0x004e, 0x004e, 'it', 0x2115), # N (missing in beta STIX fonts)
2363+
(0x004e, 0x004e, 'it', 0x2115), # N
23642364
(0x004f, 0x004f, 'it', 0xe15e), # O
2365-
(0x0050, 0x0051, 'it', 0x2119), # P-Q (missing in beta STIX fonts)
2366-
(0x0052, 0x0052, 'it', 0x211d), # R (missing in beta STIX fonts)
2365+
(0x0050, 0x0051, 'it', 0x2119), # P-Q
2366+
(0x0052, 0x0052, 'it', 0x211d), # R
23672367
(0x0053, 0x0059, 'it', 0xe15f), # S-Y
2368-
(0x005a, 0x005a, 'it', 0x2124), # Z (missing in beta STIX fonts)
2368+
(0x005a, 0x005a, 'it', 0x2124), # Z
23692369
(0x0061, 0x0063, 'it', 0xe166), # a-c
23702370
(0x0064, 0x0065, 'it', 0x2146), # d-e
23712371
(0x0066, 0x0068, 'it', 0xe169), # f-h
@@ -2380,8 +2380,23 @@
23802380
'bf':
23812381
[
23822382
(0x0030, 0x0039, 'rm', 0x1d7d8), # 0-9
2383-
(0x0041, 0x005a, 'bf', 0xe38a), # A-Z
2384-
(0x0061, 0x007a, 'bf', 0xe39d), # a-z
2383+
(0x0041, 0x0042, 'bf', 0xe38a), # A-B
2384+
(0x0043, 0x0043, 'bf', 0x2102), # C
2385+
(0x0044, 0x0044, 'bf', 0x2145), # D
2386+
(0x0045, 0x0047, 'bf', 0xe38d), # E-G
2387+
(0x0048, 0x0048, 'bf', 0x210d), # H
2388+
(0x0049, 0x004d, 'bf', 0xe390), # I-M
2389+
(0x004e, 0x004e, 'bf', 0x2115), # N
2390+
(0x004f, 0x004f, 'bf', 0xe395), # O
2391+
(0x0050, 0x0051, 'bf', 0x2119), # P-Q
2392+
(0x0052, 0x0052, 'bf', 0x211d), # R
2393+
(0x0053, 0x0059, 'bf', 0xe396), # S-Y
2394+
(0x005a, 0x005a, 'bf', 0x2124), # Z
2395+
(0x0061, 0x0063, 'bf', 0xe39d), # a-c
2396+
(0x0064, 0x0065, 'bf', 0x2146), # d-e
2397+
(0x0066, 0x0068, 'bf', 0xe3a2), # f-h
2398+
(0x0069, 0x006a, 'bf', 0x2148), # i-j
2399+
(0x006b, 0x007a, 'bf', 0xe3a7), # k-z
23852400
(0x0393, 0x0393, 'bf', 0x213e), # \Gamma
23862401
(0x03a0, 0x03a0, 'bf', 0x213f), # \Pi
23872402
(0x03a3, 0x03a3, 'bf', 0x2140), # \Sigma
Binary file not shown.
Loading

lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_font.svg

Lines changed: 3056 additions & 0 deletions
Loading
Binary file not shown.
Loading

lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_font_stix.svg

Lines changed: 3272 additions & 0 deletions
Loading
Binary file not shown.
Loading

lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_font_stixsans.svg

Lines changed: 3080 additions & 0 deletions
Loading

lib/matplotlib/tests/test_mathtext.py

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,73 @@
8282
r'${x}_{92}^{31415}+\pi $',
8383
r'${x}_{{y}_{b}^{a}}^{{z}_{c}^{d}}$',
8484
r'${y}_{3}^{\prime \prime \prime }$',
85-
r"$\left( \xi \left( 1 - \xi \right) \right)$" # Bug 2969451
85+
r"$\left( \xi \left( 1 - \xi \right) \right)$", # Bug 2969451
8686
]
8787

88-
def _run_all_tests():
89-
fig = plt.figure(figsize=(5, len(math_tests) / 2.0))
90-
for i, test in enumerate(math_tests):
91-
fig.text(0, float(len(math_tests) - i - 1) / len(math_tests), test)
88+
digits = "0123456789"
89+
uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
90+
lowercase = "abcdefghijklmnopqrstuvwxyz"
91+
uppergreek = (r"\Gamma \Delta \Theta \Lambda \Xi \Pi \Sigma \Upsilon \Phi \Psi "
92+
r"\Omega")
93+
lowergreek = (r"\alpha \beta \gamma \delta \epsilon \zeta \eta \theta \iota "
94+
r"\lambda \mu \nu \xi \pi \kappa \rho \sigma \tau \upsilon "
95+
r"\phi \chi \psi")
96+
all = [digits, uppercase, lowercase, uppergreek, lowergreek]
97+
98+
font_test_specs = [
99+
([], all),
100+
(['mathrm'], all),
101+
(['mathbf'], all),
102+
(['mathit'], all),
103+
(['mathtt'], [digits, uppercase, lowercase]),
104+
(['mathcircled'], [digits, uppercase, lowercase]),
105+
(['mathrm', 'mathcircled'], [digits, uppercase, lowercase]),
106+
(['mathbf', 'mathcircled'], [digits, uppercase, lowercase]),
107+
(['mathbb'], [digits, uppercase, lowercase,
108+
r'\Gamma \Pi \Sigma \gamma \pi']),
109+
(['mathrm', 'mathbb'], [digits, uppercase, lowercase,
110+
r'\Gamma \Pi \Sigma \gamma \pi']),
111+
(['mathbf', 'mathbb'], [digits, uppercase, lowercase,
112+
r'\Gamma \Pi \Sigma \gamma \pi']),
113+
(['mathcal'], [uppercase]),
114+
(['mathfrak'], [uppercase, lowercase]),
115+
(['mathbf', 'mathfrak'], [uppercase, lowercase]),
116+
(['mathscr'], [uppercase, lowercase]),
117+
(['mathsf'], [digits, uppercase, lowercase]),
118+
(['mathrm', 'mathsf'], [digits, uppercase, lowercase]),
119+
(['mathbf', 'mathsf'], [digits, uppercase, lowercase])
120+
]
121+
122+
font_tests = []
123+
for fonts, chars in font_test_specs:
124+
wrapper = [' '.join(fonts), ' $']
125+
for font in fonts:
126+
wrapper.append(r'\%s{' % font)
127+
wrapper.append('%s')
128+
for font in fonts:
129+
wrapper.append('}')
130+
wrapper.append('$')
131+
wrapper = ''.join(wrapper)
132+
133+
for set in chars:
134+
font_tests.append(wrapper % set)
135+
136+
def _run_all_tests(tests):
137+
fig = plt.figure(figsize=(5, len(tests) / 2.0))
138+
for i, test in enumerate(tests):
139+
fig.text(0, float(len(tests) - i - 1) / len(tests), test)
92140
return fig
93141

94142
@image_comparison(baseline_images=['mathtext'])
95143
def test_mathtext():
96-
fig = _run_all_tests()
144+
fig = _run_all_tests(math_tests)
97145
fig.savefig('mathtext')
98146

99147
@image_comparison(baseline_images=['mathtext_stix'])
100148
def test_mathtext_stix():
101149
matplotlib.rcParams['mathtext.fontset'] = 'stix'
102150

103-
fig = _run_all_tests()
151+
fig = _run_all_tests(math_tests)
104152
fig.savefig('mathtext_stix')
105153

106154
matplotlib.rcParams['mathtext.fontset'] = 'cm'
@@ -109,9 +157,30 @@ def test_mathtext_stix():
109157
def test_mathtext_stixsans():
110158
matplotlib.rcParams['mathtext.fontset'] = 'stixsans'
111159

112-
fig = _run_all_tests()
160+
fig = _run_all_tests(math_tests)
113161
fig.savefig('mathtext_stixsans')
114162

115163
matplotlib.rcParams['mathtext.fontset'] = 'cm'
116164

165+
@image_comparison(baseline_images=['mathtext_font'])
166+
def test_mathtext_font():
167+
fig = _run_all_tests(font_tests)
168+
fig.savefig('mathtext_font')
169+
170+
@image_comparison(baseline_images=['mathtext_font_stix'])
171+
def test_mathtext_font_stix():
172+
matplotlib.rcParams['mathtext.fontset'] = 'stix'
173+
174+
fig = _run_all_tests(font_tests)
175+
fig.savefig('mathtext_font_stix')
117176

177+
matplotlib.rcParams['mathtext.fontset'] = 'cm'
178+
179+
@image_comparison(baseline_images=['mathtext_font_stixsans'])
180+
def test_mathtext_font_stixsans():
181+
matplotlib.rcParams['mathtext.fontset'] = 'stixsans'
182+
183+
fig = _run_all_tests(font_tests)
184+
fig.savefig('mathtext_font_stixsans')
185+
186+
matplotlib.rcParams['mathtext.fontset'] = 'cm'

0 commit comments

Comments
 (0)
0