Skip to content

Comments

Remove mpl.text._get_textbox.#31179

Open
anntzer wants to merge 1 commit intomatplotlib:text-overhaulfrom
anntzer:tglgt
Open

Remove mpl.text._get_textbox.#31179
anntzer wants to merge 1 commit intomatplotlib:text-overhaulfrom
anntzer:tglgt

Conversation

@anntzer
Copy link
Contributor

@anntzer anntzer commented Feb 19, 2026

Consider a multiline Text object with nonzero rotation. Text._get_layout performs the layouting of the individual lines. Previously, it would return (among other things) the axes-aligned bbox of the whole Text (which can be much bigger than the rotated bbox), as well as the metrics of each individual line. mpl.text._get_layout would then take these individual metrics and unrotate their positions (to horizontal lines) to compute the size of the rotated bbox of the text (and its position as well); this is used solely when drawing a (text-aligned) bbox around the text (plt.text(..., bbox=...)).

The back-and-forth rotation seems a bit complicated; one can instead simply return the relevant info in Text._get_layout as well: the rotated bbox size is already available (in the variable previously named corners_horiz), and getting its position is also simple. Do that, and get rid of mpl.text._get_textbox (and also adjust the callers of Text._get_layout accordingly). Also add some additional drive-by reformatting of Text._get_layout.

Note: This would result in merge conflicts with @scottshambaugh's #31001, but the two PRs target different branches (this one is on text-overhaul because it goes on top of the "fix ascent/height confusion" PR). I don't mind rebasing this on top of #31001 if (the text-related parts of) that one also get retargeted to text-overhaul.

PR summary

PR checklist

Consider a multiline Text object with nonzero rotation.
Text._get_layout performs the layouting of the individual lines.
Previously, it would return (among other things) the axes-aligned bbox
of the whole Text (which can be much bigger than the rotated bbox),
as well as the metrics of each individual line. mpl.text._get_layout
would then take these individual metrics and unrotate their positions
(to horizontal lines) to compute the size of the *rotated* bbox of the
text (and its position as well); this is used solely when drawing a
(text-aligned) bbox around the text (`plt.text(..., bbox=...)`).

The back-and-forth rotation seems a bit complicated; one can instead
simply return the relevant info in Text._get_layout as well: the rotated
bbox size is already available (in the variable previously named
`corners_horiz`), and getting its position is also simple.  Do that,
and get rid of mpl.text._get_textbox (and also adjust the callers of
Text._get_layout accordingly).  Also add some additional drive-by
reformatting of Text._get_layout.
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a bit weird that we use the one or other set of return values exclusively, I.e.
bbox, info, _ and _, _, (…) but that’s maybe as it is. In theory this could be two separate functions, but the implementation overlap is large. Maybe there’s a clearer way (I haven’t dug deep to see whether e.g. one could build on the other), but it’s good enough for now.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 21, 2026

You would need to have another helper function that returns some common info that allows computing the end results, but disentangling the calculations would require a bit more work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants