Skip to content

Commit 063e60f

Browse files
committed
Merge pull request matplotlib#2771 from mdboom/fonts/fix-lookup-mechanism
Fix font family lookup calculation
2 parents 4edc4c2 + 0a761ed commit 063e60f

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/matplotlib/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,7 @@ def tk_window_focus():
13281328
'matplotlib.tests.test_dates',
13291329
'matplotlib.tests.test_delaunay',
13301330
'matplotlib.tests.test_figure',
1331+
'matplotlib.tests.test_font_manager',
13311332
'matplotlib.tests.test_gridspec',
13321333
'matplotlib.tests.test_image',
13331334
'matplotlib.tests.test_legend',

lib/matplotlib/font_manager.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1070,12 +1070,12 @@ def score_family(self, families, family2):
10701070
options = [x.lower() for x in options]
10711071
if family2 in options:
10721072
idx = options.index(family2)
1073-
return ((0.1 * (float(idx) / len(options))) *
1074-
(float(i) / float(len(families))))
1073+
return ((0.1 * (idx / len(options))) *
1074+
((i + 1) / len(families)))
10751075
elif family1 == family2:
10761076
# The score should be weighted by where in the
10771077
# list the font was found.
1078-
return float(i) / float(len(families))
1078+
return i / len(families)
10791079
return 1.0
10801080

10811081
def score_style(self, style1, style2):
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
from nose.tools import assert_equal
5+
import six
6+
7+
import os
8+
9+
from matplotlib.font_manager import findfont, FontProperties
10+
from matplotlib import rc_context
11+
12+
13+
def test_font_priority():
14+
with rc_context(rc={
15+
'font.sans-serif':
16+
['cmmi10', 'Bitstream Vera Sans']}):
17+
font = findfont(
18+
FontProperties(family=["sans-serif"]))
19+
assert_equal(os.path.basename(font), 'cmmi10.ttf')

0 commit comments

Comments
 (0)