@@ -1335,8 +1335,8 @@ def get_font_names(self):
1335
1335
"""Return the list of available fonts."""
1336
1336
return list (set ([font .name for font in self .ttflist ]))
1337
1337
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 ):
1340
1340
"""
1341
1341
Find font families that most closely matches the given properties.
1342
1342
@@ -1387,29 +1387,29 @@ def find_fontsprop(self, prop, fontext='ttf', directory=None,
1387
1387
"font.monospace" ])
1388
1388
1389
1389
prop = FontProperties ._from_any (prop )
1390
- ffamily = prop .get_family ()
1391
1390
1392
1391
fpaths = OrderedDict ()
1393
- for fidx in range ( len
10000
( ffamily ) ):
1392
+ for family in prop . get_family ( ):
1394
1393
cprop = prop .copy ()
1395
1394
1396
1395
# set current prop's family
1397
- cprop .set_family (ffamily [ fidx ] )
1396
+ cprop .set_family (family )
1398
1397
1399
1398
# do not fall back to default font
1400
1399
fpath = self ._findfontsprop_cached (
1401
- ffamily [ fidx ] , cprop , fontext , directory ,
1400
+ family , cprop , fontext , directory ,
1402
1401
False , rebuild_if_missing , rc_params
1403
1402
)
1404
1403
if fpath :
1405
- fpaths [ffamily [ fidx ] ] = fpath
1404
+ fpaths [family ] = fpath
1406
1405
1407
1406
# only add default family if no other font was found
1408
1407
# and fallback_to_default is enabled
1409
1408
if not fpaths :
1410
1409
if fallback_to_default :
1411
1410
dfamily = self .defaultFamily [fontext ]
1412
- cprop = prop .copy ().set_family (dfamily )
1411
+ cprop = prop .copy ()
1412
+ cprop .set_family (dfamily )
1413
1413
fpath = self ._findfontsprop_cached (
1414
1414
dfamily , cprop , fontext , directory ,
1415
1415
True , rebuild_if_missing , rc_params
@@ -1539,20 +1539,17 @@ def is_opentype_cff_font(filename):
1539
1539
1540
1540
@lru_cache (64 )
1541
1541
def _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 (
1551
1543
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
+ ],
1553
1551
_kerning_factor = _kerning_factor
1554
1552
)
1555
- return ft2font_object
1556
1553
1557
1554
1558
1555
# FT2Font objects cannot be used across fork()s because they reference the same
@@ -1600,4 +1597,4 @@ def _load_fontmanager(*, try_read_cache=True):
1600
1597
fontManager = _load_fontmanager ()
1601
1598
findfont = fontManager .findfont
1602
1599
get_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