diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index e66c7d4a6fa6..08447fc28260 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1322,6 +1322,7 @@ def tk_window_focus(): 'matplotlib.tests.test_dates', 'matplotlib.tests.test_delaunay', 'matplotlib.tests.test_figure', + 'matplotlib.tests.test_font_manager', 'matplotlib.tests.test_gridspec', 'matplotlib.tests.test_image', 'matplotlib.tests.test_legend', diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 5b5b558dc2a9..9bc5ee9ee712 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -1070,12 +1070,12 @@ def score_family(self, families, family2): options = [x.lower() for x in options] if family2 in options: idx = options.index(family2) - return ((0.1 * (float(idx) / len(options))) * - (float(i) / float(len(families)))) + return ((0.1 * (idx / len(options))) * + ((i + 1) / len(families))) elif family1 == family2: # The score should be weighted by where in the # list the font was found. - return float(i) / float(len(families)) + return i / len(families) return 1.0 def score_style(self, style1, style2): diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py new file mode 100644 index 000000000000..df2675219023 --- /dev/null +++ b/lib/matplotlib/tests/test_font_manager.py @@ -0,0 +1,19 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) + +from nose.tools import assert_equal +import six + +import os + +from matplotlib.font_manager import findfont, FontProperties +from matplotlib import rc_context + + +def test_font_priority(): + with rc_context(rc={ + 'font.sans-serif': + ['cmmi10', 'Bitstream Vera Sans']}): + font = findfont( + FontProperties(family=["sans-serif"])) + assert_equal(os.path.basename(font), 'cmmi10.ttf')