From 5d480c5a0232979ee73ac95f2b8ccc8faf2ceb41 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 1 Jun 2023 10:36:25 +0200 Subject: [PATCH] Better document the semantics of get_text_width_height_descent. Including whitespace seems to be the current behavior for agg and makes right-alignment works as it does. It is also necessary to make e.g. the currently PR'ed rainbow_text (based on `annotation(..., xycoords=textobj)` implementation work. Documenting the behavior is in particular useful for third-party backend implementers (mplcairo got this wrong previously). --- lib/matplotlib/backend_bases.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index d0ff3fec9c4d..6520b1d83ee3 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -636,9 +636,10 @@ def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath): def get_text_width_height_descent(self, s, prop, ismath): """ - Get the width, height, and descent (offset from the bottom - to the baseline), in display coords, of the string *s* with - `.FontProperties` *prop*. + Get the width, height, and descent (offset from the bottom to the baseline), in + display coords, of the string *s* with `.FontProperties` *prop*. + + Whitespace at the start and the end of *s* is included in the reported width. """ fontsize = prop.get_size_in_points()