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

Skip to content

Commit 57d66df

Browse files
committed
Merge pull request #4689 from chadawagner/patch-1
Update to score_family in font_manager.py
2 parents 5a23a21 + 673feb0 commit 57d66df

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/matplotlib/font_manager.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,15 +1099,18 @@ def score_family(self, families, family2):
10991099
Returns a match score between the list of font families in
11001100
*families* and the font family name *family2*.
11011101
1102-
An exact match anywhere in the list returns 0.0.
1102+
An exact match at the head of the list returns 0.0.
11031103
1104-
A match by generic font name will return 0.1.
1104+
A match further down the list will return between 0 and 1.
11051105
11061106
No match will return 1.0.
11071107
"""
11081108
if not isinstance(families, (list, tuple)):
11091109
families = [families]
1110+
elif len(families) == 0:
1111+
return 1.0
11101112
family2 = family2.lower()
1113+
step = 1 / len(families)
11111114
for i, family1 in enumerate(families):
11121115
family1 = family1.lower()
11131116
if family1 in font_family_aliases:
@@ -1117,12 +1120,11 @@ def score_family(self, families, family2):
11171120
options = [x.lower() for x in options]
11181121
if family2 in options:
11191122
idx = options.index(family2)
1120-
return ((0.1 * (idx / len(options))) *
1121-
((i + 1) / len(families)))
1123+
return (i + (idx / len(options))) * step
11221124
elif family1 == family2:
11231125
# The score should be weighted by where in the
11241126
# list the font was found.
1125-
return i / len(families)
1127+
return i * step
11261128
return 1.0
11271129

11281130
def score_style(self, style1, style2):

0 commit comments

Comments
 (0)