@@ -1335,8 +1335,8 @@ def get_font_names(self):
13351335 """Return the list of available fonts."""
13361336 return list (set ([font .name for font in self .ttflist ]))
13371337
1338- def find_fontsprop (self , prop , fontext = 'ttf' , directory = None ,
1339- fallback_to_default = True , rebuild_if_missing = True ):
1338+ def find_fonts_by_props (self , prop , fontext = 'ttf' , directory = None ,
1339+ fallback_to_default = True , rebuild_if_missing = True ):
13401340 """
13411341 Find font families that most closely matches the given properties.
13421342
@@ -1387,29 +1387,29 @@ def find_fontsprop(self, prop, fontext='ttf', directory=None,
13871387 "font.monospace" ])
13881388
13891389 prop = FontProperties ._from_any (prop )
1390- ffamily = prop .get_family ()
13911390
13921391 fpaths = OrderedDict ()
1393- for fidx in range ( len ( ffamily ) ):
1392+ for family in prop . get_family ( ):
13941393 cprop = prop .copy ()
13951394
13961395 # set current prop's family
1397- cprop .set_family (ffamily [ fidx ] )
1396+ cprop .set_family (family )
13981397
13991398 # do not fall back to default font
14001399 fpath = self ._findfontsprop_cached (
1401- ffamily [ fidx ] , cprop , fontext , directory ,
1400+ family , cprop , fontext , directory ,
14021401 False , rebuild_if_missing , rc_params
14031402 )
14041403 if fpath :
1405- fpaths [ffamily [ fidx ] ] = fpath
1404+ fpaths [family ] = fpath
14061405
14071406 # only add default family if no other font was found
14081407 # and fallback_to_default is enabled
14091408 if not fpaths :
14101409 if fallback_to_default :
14111410 dfamily = self .defaultFamily [fontext ]
1412- cprop = prop .copy ().set_family (dfamily )
1411+ cprop = prop .copy ()
1412+ cprop .set_family (dfamily )
14131413 fpath = self ._findfontsprop_cached (
14141414 dfamily , cprop , fontext , directory ,
14151415 True , rebuild_if_missing , rc_params
@@ -1539,20 +1539,17 @@ def is_opentype_cff_font(filename):
15391539
15401540@lru_cache (64 )
15411541def _get_font (fpaths , hinting_factor , * , _kerning_factor , thread_id ):
1542- ftobjects = []
1543- for fpath in fpaths [1 :]:
1544- ftobject = ft2font .FT2Font (
1545- fpath , hinting_factor ,
1546- _kerning_factor = _kerning_factor
1547- )
1548- ftobjects .append (ftobject )
1549-
1550- ft2font_object = ft2font .FT2Font (
1542+ return ft2font .FT2Font (
15511543 fpaths [0 ], hinting_factor ,
1552- _fallback_list = ftobjects ,
1544+ _fallback_list = [
1545+ ft2font .FT2Font (
1546+ fpath , hinting_factor ,
1547+ _kerning_factor = _kerning_factor
1548+ )
1549+ for fpath in fpaths [1 :]
1550+ ],
15531551 _kerning_factor = _kerning_factor
15541552 )
1555- return ft2font_object
15561553
15571554
15581555# FT2Font objects cannot be used across fork()s because they reference the same
@@ -1600,4 +1597,4 @@ def _load_fontmanager(*, try_read_cache=True):
16001597fontManager = _load_fontmanager ()
16011598findfont = fontManager .findfont
16021599get_font_names = fontManager .get_font_names
1603- find_fontsprop = fontManager .find_fontsprop
1600+ find_fonts_by_props = fontManager .find_fonts_by_props
0 commit comments