MCPcopy
hub / github.com/matplotlib/matplotlib / _find_fonts_by_props

Method _find_fonts_by_props

lib/matplotlib/font_manager.py:1538–1626  ·  view source on GitHub ↗

Find the paths to the font files most closely matching the given properties. Parameters ---------- prop : str or `~matplotlib.font_manager.FontProperties` The font properties to search for. This can be either a `.FontProperties` object or a s

(self, prop, fontext='ttf', directory=None,
                             fallback_to_default=True, rebuild_if_missing=True)

Source from the content-addressed store, hash-verified

1536 return list({font.name for font in self.ttflist})
1537
1538 def _find_fonts_by_props(self, prop, fontext='ttf', directory=None,
1539 fallback_to_default=True, rebuild_if_missing=True):
1540 """
1541 Find the paths to the font files most closely matching the given properties.
1542
1543 Parameters
1544 ----------
1545 prop : str or `~matplotlib.font_manager.FontProperties`
1546 The font properties to search for. This can be either a
1547 `.FontProperties` object or a string defining a
1548 `fontconfig patterns`_.
1549
1550 fontext : {'ttf', 'afm'}, default: 'ttf'
1551 The extension of the font file:
1552
1553 - 'ttf': TrueType and OpenType fonts (.ttf, .ttc, .otf)
1554 - 'afm': Adobe Font Metrics (.afm)
1555
1556 directory : str, optional
1557 If given, only search this directory and its subdirectories.
1558
1559 fallback_to_default : bool
1560 If True, will fall back to the default font family (usually
1561 "DejaVu Sans" or "Helvetica") if none of the families were found.
1562
1563 rebuild_if_missing : bool
1564 Whether to rebuild the font cache and search again if the first
1565 match appears to point to a nonexisting font (i.e., the font cache
1566 contains outdated entries).
1567
1568 Returns
1569 -------
1570 list[FontPath]
1571 The paths of the fonts found.
1572
1573 Notes
1574 -----
1575 This is an extension/wrapper of the original findfont API, which only
1576 returns a single font for given font properties. Instead, this API
1577 returns a list of filepaths of multiple fonts which closely match the
1578 given font properties. Since this internally uses the original API,
1579 there's no change to the logic of performing the nearest neighbor
1580 search. See `findfont` for more details.
1581 """
1582
1583 prop = FontProperties._from_any(prop)
1584
1585 fpaths = []
1586 for family in prop.get_family():
1587 cprop = prop.copy()
1588 cprop.set_family(family) # set current prop's family
1589
1590 try:
1591 fpaths.append(
1592 self.findfont(
1593 cprop, fontext, directory,
1594 fallback_to_default=False, # don't fallback to default
1595 rebuild_if_missing=rebuild_if_missing,

Callers 7

_get_layoutMethod · 0.80
_get_fontMethod · 0.80
fontNameMethod · 0.80
_prepare_fontMethod · 0.80
_get_font_ttfMethod · 0.80
test__layoutFunction · 0.80

Calls 7

findfontMethod · 0.95
_expand_aliasesMethod · 0.95
_from_anyMethod · 0.80
get_familyMethod · 0.80
set_familyMethod · 0.80
joinMethod · 0.80
copyMethod · 0.45

Tested by 2

test__layoutFunction · 0.64