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)
| 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 |
no test coverage detected