diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index 7ac89450c813..6a3a122fc3e7 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -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 diff --git a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout10.png b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout10.png index 8dc29f4cbc36..2f0998c5e66c 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout10.png and b/lib/matplotlib/tests/baseline_images/test_constrainedlayout/constrained_layout10.png differ diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 4a9457bb18c3..3b0de58814d9 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -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): diff --git a/lib/mpl_toolkits/axisartist/axis_artist.py b/lib/mpl_toolkits/axisartist/axis_artist.py index ae8d5338affa..9ba6f6075844 100644 --- a/lib/mpl_toolkits/axisartist/axis_artist.py +++ b/lib/mpl_toolkits/axisartist/axis_artist.py @@ -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