Skip to content

Commit 3656bf9

Browse files
committed
Convert path to str in FontManager.addpath
1 parent 32fff69 commit 3656bf9

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/matplotlib/font_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,8 @@ def addfont(self, path):
10911091
----------
10921092
path : str or path-like
10931093
"""
1094+
path = str(path) # Convert to string in case of a path as
1095+
# afmFontProperty and FT2Font expect this
10941096
if Path(path).suffix.lower() == ".afm":
10951097
with open(path, "rb") as fh:
10961098
font = _afm.AFM(fh)

lib/matplotlib/tests/test_font_manager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ def test_user_fonts_linux(tmpdir, monkeypatch):
176176
_get_fontconfig_fonts.cache_clear()
177177

178178

179+
def test_addfont():
180+
font_test_file = 'mpltest.ttf'
181+
path = Path(__file__).parent / font_test_file
182+
# Add font using Path, which should not produce an error. See #22582
183+
fontManager.addfont(path)
184+
185+
179186
@pytest.mark.skipif(sys.platform != 'win32', reason='Windows only')
180187
def test_user_fonts_win32():
181188
if not (os.environ.get('APPVEYOR') or os.environ.get('TF_BUILD')):

0 commit comments

Comments
 (0)