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')
| 276 | |
| 277 | |
| 278 | def 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 |
searching dependent graphs…