From 997b69ea46f1acfbc94d33a17725753e16fea02a Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 4 Oct 2021 22:41:18 +0200 Subject: [PATCH] Clear findfont cache when calling addfont(). ... as new fonts may invalidate previous searches (e.g. a previous findfont may have chosen to return an approximate match, whereas the newly added font is an exact match). No test, as there is no machinery to *remove* a font from FontManager yet so we add a font just temporarily within the test. --- lib/matplotlib/font_manager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 9d45575eb13d..9716e72b5330 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -1092,6 +1092,7 @@ def addfont(self, path): font = ft2font.FT2Font(path) prop = ttfFontProperty(font) self.ttflist.append(prop) + self._findfont_cached.cache_clear() @property def defaultFont(self):