Skip to content

Commit a1abdb3

Browse files
committed
Fix baseline-alignment on multi-line text. (Reported by Olle Engdegård)
svn path=/trunk/matplotlib/; revision=8393
1 parent e9cbe1b commit a1abdb3

File tree

6 files changed

+99
-6
lines changed

6 files changed

+99
-6
lines changed

lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_005.svg

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

lib/matplotlib/tests/test_text.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ def test_font_styles():
6464

6565
fig.savefig('font_styles')
6666

67+
@image_comparison(baseline_images=['multiline'])
68+
def test_multiline():
69+
fig = plt.figure()
70+
ax = plt.subplot( 1, 1, 1 )
71+
ax.set_title("multiline\ntext alignment")
72+
73+
ax.set_xticks([])
74+
ax.set_yticks([])
75+
76+
fig.savefig('multiline')

lib/matplotlib/text.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def get_text_width_height_descent(*kl, **kwargs):
298298
ismath=False)
299299
offsety = lp_h * self._linespacing
300300

301-
baseline = None
301+
baseline = 0
302302
for i, line in enumerate(lines):
303303
clean_line, ismath = self.is_math_text(line)
304304
if clean_line:
@@ -308,8 +308,6 @@ def get_text_width_height_descent(*kl, **kwargs):
308308
else:
309309
w, h, d = 0, 0, 0
310310

311-
if baseline is None:
312-
baseline = h - d
313311
whs[i] = w, h
314312

315313
# For general multiline text, we will have a fixed spacing
@@ -326,9 +324,11 @@ def get_text_width_height_descent(*kl, **kwargs):
326324

327325
horizLayout[i] = thisx, thisy-(d + d_yoffset), \
328326
w, h
327+
baseline = (h - d) - thisy
329328
thisy -= offsety + d_yoffset
330329
width = max(width, w)
331330

331+
332332
ymin = horizLayout[-1][1]
333333
ymax = horizLayout[0][1] + horizLayout[0][3]
334334
height = ymax-ymin

0 commit comments

Comments
 (0)