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

Skip to content

Fix font family lookup calculation #2771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops. Was this to speed up the travis run? 😄
Once this is removed, I think we can merge this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Yeah -- I was trying to get to the bottom of why Travis was failing -- there seems to be some bad interaction with other tests run in parallel, so I thought I'd try the test in isolation.

'matplotlib.tests.test_gridspec',
'matplotlib.tests.test_image',
'matplotlib.tests.test_legend',
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
19 changes: 19 additions & 0 deletions lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
@@ -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')