Skip to content

Ensure text metric calculation always uses the text cache #29907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,10 @@ def get_offset(self):
return self._offset

def get_bbox(self, renderer):
_, h_, d_ = renderer.get_text_width_height_descent(
"lp", self._text._fontproperties,
ismath="TeX" if self._text.get_usetex() else False)
_, h_, d_ = mtext._get_text_metrics_with_cache(
renderer, "lp", self._text._fontproperties,
ismath="TeX" if self._text.get_usetex() else False,
dpi=self.get_figure(root=True).dpi)

bbox, info, yd = self._text._get_layout(renderer)
w, h = bbox.size
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,10 @@ def _get_rendered_text_width(self, text):
Return the width of a given text string, in pixels.
"""

w, h, d = self._renderer.get_text_width_height_descent(
text,
self.get_fontproperties(),
cbook.is_math_text(text))
w, h, d = _get_text_metrics_with_cache(
self._renderer, text, self.get_fontproperties(),
cbook.is_math_text(text),
self.get_figure(root=True).dpi)
return math.ceil(w)

def _get_wrapped_text(self):
Expand Down
5 changes: 3 additions & 2 deletions lib/mpl_toolkits/axisartist/axis_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,9 @@ def get_texts_widths_heights_descents(self, renderer):
if not label.strip():
continue
clean_line, ismath = self._preprocess_math(label)
whd = renderer.get_text_width_height_descent(
clean_line, self._fontproperties, ismath=ismath)
whd = mtext._get_text_metrics_with_cache(
renderer, clean_line, self._fontproperties, ismath=ismath,
dpi=self.get_figure(root=True).dpi)
whd_list.append(whd)
return whd_list

Expand Down
Loading