8
8
9
9
from matplotlib import cbook
10
10
from matplotlib import rcParams
11
- import artist
12
- from artist import Artist
13
- from cbook import is_string_like , maxdict
14
- from font_manager import FontProperties
15
- from patches import bbox_artist , YAArrow , FancyBboxPatch , \
11
+ import matplotlib . artist as artist
12
+ from matplotlib . artist import Artist
13
+ from matplotlib . cbook import is_string_like , maxdict
14
+ from matplotlib . font_manager import FontProperties
15
+ from matplotlib . patches import bbox_artist , YAArrow , FancyBboxPatch , \
16
16
FancyArrowPatch , Rectangle
17
- import transforms as mtransforms
18
- from transforms import Affine2D , Bbox
19
- from lines import Line2D
17
+ import matplotlib . transforms as mtransforms
18
+ from matplotlib . transforms import Affine2D , Bbox
19
+ from matplotlib . lines import Line2D
20
20
21
21
import matplotlib .nxutils as nxutils
22
22
@@ -227,6 +227,11 @@ def update_from(self, other):
227
227
self ._linespacing = other ._linespacing
228
228
229
229
def _get_layout (self , renderer ):
230
+ """
231
+ return the extent (bbox) of the text together with
232
+ multile-alignment information. Note that it returns a extent
233
+ of a rotated text when necessary.
234
+ """
230
235
key = self .get_prop_tup ()
231
236
if key in self .cached : return self .cached [key ]
232
237
@@ -242,9 +247,9 @@ def _get_layout(self, renderer):
242
247
243
248
# Find full vertical extent of font,
244
249
# including ascenders and descenders:
245
- tmp , heightt , bl = renderer .get_text_width_height_descent (
250
+ tmp , lp_h , lp_bl = renderer .get_text_width_height_descent (
246
251
'lp' , self ._fontproperties , ismath = False )
247
- offsety = heightt * self ._linespacing
252
+ offsety = lp_h * self ._linespacing
248
253
249
254
baseline = None
250
255
for i , line in enumerate (lines ):
@@ -254,8 +259,22 @@ def _get_layout(self, renderer):
254
259
if baseline is None :
255
260
baseline = h - d
256
261
whs [i ] = w , h
257
- horizLayout [i ] = thisx , thisy , w , h
258
- thisy -= offsety
262
+
263
+ # For general multiline text, we will have a fixed spacing
264
+ # between the "baseline" of the upper line and "top" of
265
+ # the lower line (instead of the "bottom" of the upper
266
+ # line and "top" of the lower line)
267
+
268
+ # For multiline text, increase the line spacing when the
269
+ # text net-height(excluding baseline) is larger than that
270
+ # of a "l" (e.g., use of superscripts), which seems
271
+ # what TeX does.
272
+
273
+ d_yoffset = max (0 , (h - d )- (lp_h - lp_bl ))
274
+
275
+ horizLayout [i ] = thisx , thisy - (d + d_yoffset ), \
276
+ w , h
277
+ thisy -= offsety + d_yoffset
259
278
width = max (width , w )
260
279
261
280
ymin = horizLayout [- 1 ][1 ]
@@ -1688,3 +1707,4 @@ def draw(self, renderer):
1688
1707
1689
1708
1690
1709
artist .kwdocd ['Annotation' ] = Annotation .__init__ .__doc__
1710
+
0 commit comments