@@ -1113,6 +1113,12 @@ def set_default_weight(self, weight):
1113
1113
"""
1114
1114
self .__default_weight = weight
1115
1115
1116
+ @staticmethod
1117
+ def _expand_aliases (family ):
1118
+ if family in ('sans' , 'sans serif' ):
1119
+ family = 'sans-serif'
1120
+ return rcParams ['font.' + family ]
1121
+
1116
1122
# Each of the scoring functions below should return a value between
1117
1123
# 0.0 (perfect match) and 1.0 (terrible match)
1118
1124
def score_family (self , families , family2 ):
@@ -1135,10 +1141,7 @@ def score_family(self, families, family2):
1135
1141
for i , family1 in enumerate (families ):
1136
1142
family1 = family1 .lower ()
1137
1143
if family1 in font_family_aliases :
1138
- if family1 in ('sans' , 'sans serif' ):
1139
- family1 = 'sans-serif'
1140
- options = rcParams ['font.' + family1 ]
1141
- options = [x .lower () for x in options ]
1144
+ options = [* map (str .lower , self ._expand_aliases (family1 ))]
1142
1145
if family2 in options :
1143
1146
idx = options .index (family2 )
1144
1147
return (i + (idx / len (options ))) * step
@@ -1341,6 +1344,12 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
1341
1344
_log .warning (
1342
1345
'findfont: Font family %s not found. Falling back to %s.' ,
1343
1346
prop .get_family (), self .defaultFamily [fontext ])
1347
+ for family in map (str .lower , prop .get_family ()):
1348
+ if family in font_family_aliases :
1349
+ _log .warning (
1350
+ "findfont: Generic family %r not found because "
1351
+ "none of the following families were found: %s" ,
1352
+ family , ", " .join (self ._expand_aliases (family )))
1344
1353
default_prop = prop .copy ()
1345
1354
default_prop .set_family (self .defaultFamily [fontext ])
1346
1355
return self .findfont (default_prop , fontext , directory ,
0 commit comments