Find the path to the font file most closely matching the given font properties. Parameters ---------- prop : str or `~matplotlib.font_manager.FontProperties` The font properties to search for. This can be either a `.FontProperties` object or
(self, prop, fontext='ttf', directory=None,
fallback_to_default=True, rebuild_if_missing=True)
| 1460 | return abs(sizeval1 - sizeval2) / 72 |
| 1461 | |
| 1462 | def findfont(self, prop, fontext='ttf', directory=None, |
| 1463 | fallback_to_default=True, rebuild_if_missing=True): |
| 1464 | """ |
| 1465 | Find the path to the font file most closely matching the given font properties. |
| 1466 | |
| 1467 | Parameters |
| 1468 | ---------- |
| 1469 | prop : str or `~matplotlib.font_manager.FontProperties` |
| 1470 | The font properties to search for. This can be either a |
| 1471 | `.FontProperties` object or a string defining a |
| 1472 | `fontconfig patterns`_. |
| 1473 | |
| 1474 | fontext : {'ttf', 'afm'}, default: 'ttf' |
| 1475 | The extension of the font file: |
| 1476 | |
| 1477 | - 'ttf': TrueType and OpenType fonts (.ttf, .ttc, .otf) |
| 1478 | - 'afm': Adobe Font Metrics (.afm) |
| 1479 | |
| 1480 | directory : str, optional |
| 1481 | If given, only search this directory and its subdirectories. |
| 1482 | If :envvar:`MPL_IGNORE_SYSTEM_FONTS` is set, then this defaults to |
| 1483 | Matplotlib's internal font directory. |
| 1484 | |
| 1485 | fallback_to_default : bool |
| 1486 | If True, will fall back to the default font family (usually |
| 1487 | "DejaVu Sans" or "Helvetica") if the first lookup hard-fails. |
| 1488 | |
| 1489 | rebuild_if_missing : bool |
| 1490 | Whether to rebuild the font cache and search again if the first |
| 1491 | match appears to point to a nonexisting font (i.e., the font cache |
| 1492 | contains outdated entries). |
| 1493 | |
| 1494 | Returns |
| 1495 | ------- |
| 1496 | FontPath |
| 1497 | The filename of the best matching font. |
| 1498 | |
| 1499 | Notes |
| 1500 | ----- |
| 1501 | This performs a nearest neighbor search. Each font is given a |
| 1502 | similarity score to the target font properties. The first font with |
| 1503 | the highest score is returned. If no matches below a certain |
| 1504 | threshold are found, the default font (usually DejaVu Sans) is |
| 1505 | returned. |
| 1506 | |
| 1507 | The result is cached, so subsequent lookups don't have to |
| 1508 | perform the O(n) nearest neighbor search. |
| 1509 | |
| 1510 | See the `W3C Cascading Style Sheet, Level 1 |
| 1511 | <http://www.w3.org/TR/1998/REC-CSS2-19980512/>`_ documentation |
| 1512 | for a description of the font finding algorithm. |
| 1513 | |
| 1514 | .. _fontconfig patterns: |
| 1515 | https://www.freedesktop.org/software/fontconfig/fontconfig-user.html |
| 1516 | """ |
| 1517 | # Pass the relevant rcParams (and the font manager, as `self`) to |
| 1518 | # _findfont_cached so to prevent using a stale cache entry after an |
| 1519 | # rcParam was changed. |