15
15
findfont , findSystemFonts , FontEntry , FontProperties , fontManager ,
16
16
json_dump , json_load , get_font , is_opentype_cff_font ,
17
17
MSUserFontDirectories , _get_fontconfig_fonts , ft2font ,
18
- ttfFontProperty , cbook )
19
- from matplotlib import pyplot as plt , rc_context
18
+ ttfFontProperty , cbook , _load_fontmanager )
19
+ from matplotlib import pyplot as plt , rc_context , get_cachedir
20
20
21
21
has_fclist = shutil .which ('fc-list' ) is not None
22
22
@@ -297,18 +297,24 @@ def test_fontentry_dataclass_invalid_path():
297
297
298
298
@pytest .mark .skipif (sys .platform == 'win32' , reason = 'Linux or OS only' )
299
299
def test_get_font_names ():
300
+ # Ensure fonts like 'mpltest' are not in cache
301
+ new_fm = _load_fontmanager (try_read_cache = False )
302
+ mpl_font_names = sorted (new_fm .get_font_names ())
303
+
300
304
paths_mpl = [cbook ._get_data_path ('fonts' , subdir ) for subdir in ['ttf' ]]
301
305
fonts_mpl = findSystemFonts (paths_mpl , fontext = 'ttf' )
302
306
fonts_system = findSystemFonts (fontext = 'ttf' )
307
+ # TTF extracted and cached from TTC
308
+ cached_fonts = findSystemFonts (get_cachedir (), fontext = 'ttf' )
303
309
ttf_fonts = []
304
- for path in fonts_mpl + fonts_system :
310
+ for path in fonts_mpl + fonts_system + cached_fonts :
305
311
try :
306
312
font = ft2font .FT2Font (path )
307
313
prop = ttfFontProperty (font )
308
314
ttf_fonts .append (prop .name )
309
315
except :
310
316
pass
311
317
available_fonts = sorted (list (set (ttf_fonts )))
312
- mpl_font_names = sorted ( fontManager . get_font_names ())
318
+
313
319
assert len (available_fonts ) == len (mpl_font_names )
314
320
assert available_fonts == mpl_font_names
0 commit comments