Skip to content

Commit 4e264da

Browse files
committed
TST: Fix pdf_use14corefonts by manually splitting lines
Since Helvetica may or may not be installed, the line height measurement may differ between systems, so multi-line text as in this test may change. This test doesn't care about line heights, but is about using PDF's "standard" fonts, so we'll just manually place the lines. Unfortunately, since text placement still depends on the exact split of ascent/descent, we still need to add some increased tolerance here. This will be fixed when all backends correctly apply font metrics for line height, and PDF can arrange to use our bundled core 14 font metrics for that.
1 parent 2f8c518 commit 4e264da

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
Binary file not shown.

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
from matplotlib.testing._markers import needs_usetex
2323

2424

25-
@image_comparison(['pdf_use14corefonts.pdf'])
25+
# TODO: Reduce this tolerance when all backends load font metrics for line height.
26+
@image_comparison(['pdf_use14corefonts.pdf'], tol=9.939)
2627
def test_use14corefonts():
2728
rcParams['pdf.use14corefonts'] = True
2829
rcParams['font.family'] = 'sans-serif'
@@ -32,13 +33,16 @@ def test_use14corefonts():
3233

3334
text = '''A three-line text positioned just above a blue line
3435
and containing some French characters and the euro symbol:
35-
"Merci pépé pour les 10 €"'''
36+
"Merci pépé pour les 10 €"'''.splitlines()
3637

3738
fig, ax = plt.subplots()
3839
ax.set_title('Test PDF backend with option use14corefonts=True')
39-
ax.text(0.5, 0.5, text, horizontalalignment='center',
40-
verticalalignment='bottom',
41-
fontsize=14)
40+
for i, line in enumerate(reversed(text)):
41+
# As Helvetica may or may not be installed, we place these lines manually, or
42+
# else they will move vertically depending on which font we measure for its
43+
# line height.
44+
ax.text(0.5, 0.5 + i * 0.05, line, fontsize=14, linespacing=1.2,
45+
horizontalalignment='center', verticalalignment='bottom')
4246
ax.axhline(0.5, linewidth=0.5)
4347

4448

0 commit comments

Comments
 (0)