88
99from matplotlib import cbook
1010from 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 , \
1616 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
2020
2121import matplotlib .nxutils as nxutils
2222
@@ -227,6 +227,11 @@ def update_from(self, other):
227227 self ._linespacing = other ._linespacing
228228
229229 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+ """
230235 key = self .get_prop_tup ()
231236 if key in self .cached : return self .cached [key ]
232237
@@ -242,9 +247,9 @@ def _get_layout(self, renderer):
242247
243248 # Find full vertical extent of font,
244249 # 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 (
246251 'lp' , self ._fontproperties , ismath = False )
247- offsety = heightt * self ._linespacing
252+ offsety = lp_h * self ._linespacing
248253
249254 baseline = None
250255 for i , line in enumerate (lines ):
@@ -254,8 +259,22 @@ def _get_layout(self, renderer):
254259 if baseline is None :
255260 baseline = h - d
256261 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
259278 width = max (width , w )
260279
261280 ymin = horizLayout [- 1 ][1 ]
@@ -1688,3 +1707,4 @@ def draw(self, renderer):
16881707
16891708
16901709artist .kwdocd ['Annotation' ] = Annotation .__init__ .__doc__
1710+
0 commit comments