MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / findSystemFonts

Function findSystemFonts

lib/matplotlib/font_manager.py:278–326  ·  view source on GitHub ↗

Find fonts in a search path, system paths, or some other platform-specific method. Parameters ---------- fontpaths : list of str, optional Search for fonts in these specified font paths. If no paths are given and the :envvar:`MPL_IGNORE_SYSTEM_FONTS` is not set, use

(fontpaths=None, fontext='ttf')

Source from the content-addressed store, hash-verified

276
277
278def findSystemFonts(fontpaths=None, fontext='ttf'):
279 """
280 Find fonts in a search path, system paths, or some other platform-specific method.
281
282 Parameters
283 ----------
284 fontpaths : list of str, optional
285 Search for fonts in these specified font paths. If no paths are given and the
286 :envvar:`MPL_IGNORE_SYSTEM_FONTS` is not set, use a standard set of system
287 paths, as well as the list of fonts tracked by fontconfig if fontconfig is
288 installed and available.
289 fontext : {'ttf', 'afm'}, default: 'ttf'
290 If 'ttf', search for TrueType fonts; if 'afm', search for with AFM fonts.
291
292 Returns
293 -------
294 list of str
295 A list of file paths with fonts of the given type.
296 """
297 fontfiles = set()
298 fontexts = get_fontext_synonyms(fontext)
299
300 if fontpaths is None:
301 if os.getenv('MPL_IGNORE_SYSTEM_FONTS'):
302 installed_fonts = []
303 fontpaths = []
304 elif sys.platform == 'win32':
305 installed_fonts = _get_win32_installed_fonts()
306 fontpaths = []
307 elif sys.platform == 'emscripten':
308 installed_fonts = []
309 fontpaths = []
310 else:
311 installed_fonts = _get_fontconfig_fonts()
312 if sys.platform == 'darwin':
313 installed_fonts += _get_macos_fonts()
314 fontpaths = [*X11FontDirectories, *OSXFontDirectories]
315 else:
316 fontpaths = X11FontDirectories
317 fontfiles.update(str(path) for path in installed_fonts
318 if path.suffix.lower()[1:] in fontexts)
319
320 elif isinstance(fontpaths, str):
321 fontpaths = [fontpaths]
322
323 for path in fontpaths:
324 fontfiles.update(map(os.path.abspath, list_fonts(path, fontexts)))
325
326 return [fname for fname in fontfiles if os.path.exists(fname)]
327
328
329# To maintain backwards-compatibility with the current code we need to continue to

Callers 4

test_user_fonts_linuxFunction · 0.90
test_user_fonts_win32Function · 0.90
test_get_font_namesFunction · 0.90
__init__Method · 0.85

Calls 6

get_fontext_synonymsFunction · 0.85
_get_fontconfig_fontsFunction · 0.85
_get_macos_fontsFunction · 0.85
list_fontsFunction · 0.85
updateMethod · 0.45

Tested by 3

test_user_fonts_linuxFunction · 0.72
test_user_fonts_win32Function · 0.72
test_get_font_namesFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…