Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3835c3e

Browse files
authored
Merge pull request #23663 from anntzer/ffbp
Small cleanups to _find_fonts_by_props.
2 parents 9ff060e + 1220bbd commit 3835c3e

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

lib/matplotlib/font_manager.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,44 +1396,32 @@ def _find_fonts_by_props(self, prop, fontext='ttf', directory=None,
13961396
which closely match the given font properties. Since this internally
13971397
uses the original API, there's no change to the logic of performing the
13981398
nearest neighbor search. See `findfont` for more details.
1399-
14001399
"""
14011400

1402-
rc_params = tuple(tuple(rcParams[key]) for key in [
1403-
"font.serif", "font.sans-serif", "font.cursive", "font.fantasy",
1404-
"font.monospace"])
1405-
14061401
prop = FontProperties._from_any(prop)
14071402

14081403
fpaths = []
14091404
for family in prop.get_family():
14101405
cprop = prop.copy()
1406+
cprop.set_family(family) # set current prop's family
14111407

1412-
# set current prop's family
1413-
cprop.set_family(family)
1414-
1415-
# do not fall back to default font
14161408
try:
14171409
fpaths.append(
1418-
self._findfont_cached(
1410+
self.findfont(
14191411
cprop, fontext, directory,
1420-
fallback_to_default=False,
1412+
fallback_to_default=False, # don't fallback to default
14211413
rebuild_if_missing=rebuild_if_missing,
1422-
rc_params=rc_params,
14231414
)
14241415
)
14251416
except ValueError:
14261417
if family in font_family_aliases:
14271418
_log.warning(
14281419
"findfont: Generic family %r not found because "
14291420
"none of the following families were found: %s",
1430-
family,
1431-
", ".join(self._expand_aliases(family))
1421+
family, ", ".join(self._expand_aliases(family))
14321422
)
14331423
else:
1434-
_log.warning(
1435-
'findfont: Font family \'%s\' not found.', family
1436-
)
1424+
_log.warning("findfont: Font family %r not found.", family)
14371425

14381426
# only add default family if no other font was found and
14391427
# fallback_to_default is enabled
@@ -1443,16 +1431,15 @@ def _find_fonts_by_props(self, prop, fontext='ttf', directory=None,
14431431
cprop = prop.copy()
14441432
cprop.set_family(dfamily)
14451433
fpaths.append(
1446-
self._findfont_cached(
1434+
self.findfont(
14471435
cprop, fontext, directory,
14481436
fallback_to_default=True,
14491437
rebuild_if_missing=rebuild_if_missing,
1450-
rc_params=rc_params,
14511438
)
14521439
)
14531440
else:
14541441
raise ValueError("Failed to find any font, and fallback "
1455-
"to the default font was disabled.")
1442+
"to the default font was disabled")
14561443

14571444
return fpaths
14581445

0 commit comments

Comments
 (0)