@@ -1099,15 +1099,18 @@ def score_family(self, families, family2):
1099
1099
Returns a match score between the list of font families in
1100
1100
*families* and the font family name *family2*.
1101
1101
1102
- An exact match anywhere in the list returns 0.0.
1102
+ An exact match at the head of the list returns 0.0.
1103
1103
1104
- A match by generic font name will return 0. 1.
1104
+ A match further down the list will return between 0 and 1.
1105
1105
1106
1106
No match will return 1.0.
1107
1107
"""
1108
1108
if not isinstance (families , (list , tuple )):
1109
1109
families = [families ]
1110
+ elif len (families ) == 0 :
1111
+ return 1.0
1110
1112
family2 = family2 .lower ()
1113
+ step = 1 / len (families )
1111
1114
for i , family1 in enumerate (families ):
1112
1115
family1 = family1 .lower ()
1113
1116
if family1 in font_family_aliases :
@@ -1117,12 +1120,11 @@ def score_family(self, families, family2):
1117
1120
options = [x .lower () for x in options ]
1118
1121
if family2 in options :
1119
1122
idx = options .index (family2 )
1120
- return ((0.1 * (idx / len (options ))) *
1121
- ((i + 1 ) / len (families )))
1123
+ return (i + (idx / len (options ))) * step
1122
1124
elif family1 == family2 :
1123
1125
# The score should be weighted by where in the
1124
1126
# list the font was found.
1125
- return i / len ( families )
1127
+ return i * step
1126
1128
return 1.0
1127
1129
1128
1130
def score_style (self , style1 , style2 ):
0 commit comments