diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 91fe97e128f4..a0a695bf268e 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -1099,15 +1099,18 @@ def score_family(self, families, family2): Returns a match score between the list of font families in *families* and the font family name *family2*. - An exact match anywhere in the list returns 0.0. + An exact match at the head of the list returns 0.0. - A match by generic font name will return 0.1. + A match further down the list will return between 0 and 1. No match will return 1.0. """ if not isinstance(families, (list, tuple)): families = [families] + elif len(families) == 0: + return 1.0 family2 = family2.lower() + step = 1 / len(families) for i, family1 in enumerate(families): family1 = family1.lower() if family1 in font_family_aliases: @@ -1117,12 +1120,11 @@ def score_family(self, families, family2): options = [x.lower() for x in options] if family2 in options: idx = options.index(family2) - return ((0.1 * (idx / len(options))) * - ((i + 1) / len(families))) + return (i + (idx / len(options))) * step elif family1 == family2: # The score should be weighted by where in the # list the font was found. - return i / len(families) + return i * step return 1.0 def score_style(self, style1, style2):