MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / _get_layout

Method _get_layout

site-packages/matplotlib/text.py:280–431  ·  view source on GitHub ↗

return the extent (bbox) of the text together with multiple-alignment information. Note that it returns an extent of a rotated text when necessary.

(self, renderer)

Source from the content-addressed store, hash-verified

278 self.stale = True
279
280 def _get_layout(self, renderer):
281 """
282 return the extent (bbox) of the text together with
283 multiple-alignment information. Note that it returns an extent
284 of a rotated text when necessary.
285 """
286 key = self.get_prop_tup(renderer=renderer)
287 if key in self._cached:
288 return self._cached[key]
289
290 horizLayout = []
291
292 thisx, thisy = 0.0, 0.0
293 xmin, ymin = 0.0, 0.0
294 width, height = 0.0, 0.0
295 lines = self.get_text().split('\n')
296
297 whs = np.zeros((len(lines), 2))
298 horizLayout = np.zeros((len(lines), 4))
299
300 # Find full vertical extent of font,
301 # including ascenders and descenders:
302 tmp, lp_h, lp_bl = renderer.get_text_width_height_descent('lp',
303 self._fontproperties,
304 ismath=False)
305 offsety = (lp_h - lp_bl) * self._linespacing
306
307 baseline = 0
308 for i, line in enumerate(lines):
309 clean_line, ismath = self.is_math_text(line, self.get_usetex())
310 if clean_line:
311 w, h, d = renderer.get_text_width_height_descent(clean_line,
312 self._fontproperties,
313 ismath=ismath)
314 else:
315 w, h, d = 0, 0, 0
316
317 # For multiline text, increase the line spacing when the
318 # text net-height(excluding baseline) is larger than that
319 # of a "l" (e.g., use of superscripts), which seems
320 # what TeX does.
321 h = max(h, lp_h)
322 d = max(d, lp_bl)
323
324 whs[i] = w, h
325
326 baseline = (h - d) - thisy
327 thisy -= max(offsety, (h - d) * self._linespacing)
328 horizLayout[i] = thisx, thisy, w, h
329 thisy -= d
330 width = max(width, w)
331 descent = d
332
333 ymin = horizLayout[-1][1]
334 ymax = horizLayout[0][1] + horizLayout[0][3]
335 height = ymax - ymin
336 xmax = xmin + width
337

Callers 4

get_window_extentMethod · 0.95
_get_textboxFunction · 0.80
drawMethod · 0.80
get_extentMethod · 0.80

Calls 15

get_prop_tupMethod · 0.95
get_textMethod · 0.95
is_math_textMethod · 0.95
get_usetexMethod · 0.95
get_rotationMethod · 0.95
_get_multialignmentMethod · 0.95
get_rotation_modeMethod · 0.95
Affine2DClass · 0.90
maxFunction · 0.85
rotate_degMethod · 0.80
from_boundsMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected