Skip to content

Commit 1840d9b

Browse files
committed
Ensure text metric calculation always uses the text cache
These locations outside of `Text` were calling `Renderer.get_text_width_height_descent` directly which meant that 1. they were not cached, and 2. the `text_placeholders` fixture did not catch their use. Fortunately, this only affected one test figure.
1 parent b9da4fd commit 1840d9b

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

lib/matplotlib/offsetbox.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,10 @@ def get_offset(self):
794794
return self._offset
795795

796796
def get_bbox(self, renderer):
797-
_, h_, d_ = renderer.get_text_width_height_descent(
798-
"lp", self._text._fontproperties,
799-
ismath="TeX" if self._text.get_usetex() else False)
797+
_, h_, d_ = mtext._get_text_metrics_with_cache(
798+
renderer, "lp", self._text._fontproperties,
799+
ismath="TeX" if self._text.get_usetex() else False,
800+
dpi=self.get_figure(root=True).dpi)
800801

801802
bbox, info, yd = self._text._get_layout(renderer)
802803
w, h = bbox.size
Loading

lib/matplotlib/text.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,10 @@ def _get_rendered_text_width(self, text):
694694
Return the width of a given text string, in pixels.
695695
"""
696696

697-
w, h, d = self._renderer.get_text_width_height_descent(
698-
text,
699-
self.get_fontproperties(),
700-
cbook.is_math_text(text))
697+
w, h, d = _get_text_metrics_with_cache(
698+
self._renderer, text, self.get_fontproperties(),
699+
cbook.is_math_text(text),
700+
self.get_figure(root=True).dpi)
701701
return math.ceil(w)
702702

703703
def _get_wrapped_text(self):

lib/mpl_toolkits/axisartist/axis_artist.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,9 @@ def get_texts_widths_heights_descents(self, renderer):
588588
if not label.strip():
589589
continue
590590
clean_line, ismath = self._preprocess_math(label)
591-
whd = renderer.get_text_width_height_descent(
592-
clean_line, self._fontproperties, ismath=ismath)
591+
whd = mtext._get_text_metrics_with_cache(
592+
renderer, clean_line, self._fontproperties, ismath=ismath,
593+
dpi=self.get_figure(root=True).dpi)
593594
whd_list.append(whd)
594595
return whd_list
595596

0 commit comments

Comments
 (0)