|
13 | 13 | from matplotlib.font_manager import (
|
14 | 14 | findfont, findSystemFonts, FontProperties, fontManager, json_dump,
|
15 | 15 | json_load, get_font, is_opentype_cff_font, MSUserFontDirectories,
|
16 |
| - _get_fontconfig_fonts) |
| 16 | + _get_fontconfig_fonts, ft2font, ttfFontProperty, cbook) |
17 | 17 | from matplotlib import pyplot as plt, rc_context
|
18 | 18 |
|
19 | 19 | has_fclist = shutil.which('fc-list') is not None
|
@@ -266,3 +266,22 @@ def test_fontcache_thread_safe():
|
266 | 266 | if proc.returncode:
|
267 | 267 | pytest.fail("The subprocess returned with non-zero exit status "
|
268 | 268 | f"{proc.returncode}.")
|
| 269 | + |
| 270 | + |
| 271 | +@pytest.mark.skipif(sys.platform == 'win32', reason='Linux or OS only') |
| 272 | +def test_get_font_names(): |
| 273 | + paths_mpl = [cbook._get_data_path('fonts', subdir) for subdir in ['ttf']] |
| 274 | + fonts_mpl = findSystemFonts(paths_mpl, fontext='ttf') |
| 275 | + fonts_system = findSystemFonts(fontext='ttf') |
| 276 | + ttf_fonts = [] |
| 277 | + for path in fonts_mpl + fonts_system: |
| 278 | + try: |
| 279 | + font = ft2font.FT2Font(path) |
| 280 | + prop = ttfFontProperty(font) |
| 281 | + ttf_fonts.append(prop.name) |
| 282 | + except: |
| 283 | + pass |
| 284 | + available_fonts = sorted(list(set(ttf_fonts))) |
| 285 | + mpl_font_names = sorted(fontManager.get_font_names()) |
| 286 | + assert len(available_fonts) == len(mpl_font_names) |
| 287 | + assert available_fonts == mpl_font_names |
0 commit comments