MCPcopy
hub / github.com/matplotlib/matplotlib / findfont

Method findfont

lib/matplotlib/font_manager.py:1462–1532  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 15

defaultFontMethod · 0.95
_find_fonts_by_propsMethod · 0.95
_findfont_cachedMethod · 0.95
set_useMathTextMethod · 0.80
_to_fontspecFunction · 0.80
_get_font_afmMethod · 0.80
test_svg_font_stringFunction · 0.80
test_ttc_type3Function · 0.80
test_ttc_type42Function · 0.80
test_otf_font_smokeFunction · 0.80
test_ft2font_cm_attrsFunction · 0.80

Calls 2

_findfont_cachedMethod · 0.95
to_exceptionMethod · 0.80

Tested by 15

test_svg_font_stringFunction · 0.64
test_ttc_type3Function · 0.64
test_ttc_type42Function · 0.64
test_otf_font_smokeFunction · 0.64
test_ft2font_cm_attrsFunction · 0.64
test_ft2font_valid_argsFunction · 0.64
test_ft2font_face_indexFunction · 0.64
test_ft2font_clearFunction · 0.64
test_ft2font_set_sizeFunction · 0.64