|
15 | 15 | from matplotlib.font_manager import ( |
16 | 16 | findfont, findSystemFonts, FontEntry, FontProperties, fontManager, |
17 | 17 | json_dump, json_load, get_font, is_opentype_cff_font, |
18 | | - MSUserFontDirectories, _get_fontconfig_fonts, ttfFontProperty) |
| 18 | + MSUserFontDirectories, ttfFontProperty, |
| 19 | + _get_fontconfig_fonts, _normalize_weight) |
19 | 20 | from matplotlib import cbook, ft2font, pyplot as plt, rc_context, figure as mfigure |
20 | 21 | from matplotlib.testing import subprocess_run_helper, subprocess_run_for_testing |
21 | 22 |
|
@@ -407,3 +408,26 @@ def test_fontproperties_init_deprecation(): |
407 | 408 | # Since this case is not covered by docs, I've refrained from jumping |
408 | 409 | # extra hoops to detect this possible API misuse. |
409 | 410 | FontProperties(family="serif-24:style=oblique:weight=bold") |
| 411 | + |
| 412 | + |
| 413 | +def test_map_weights(): |
| 414 | + assert _normalize_weight('ultralight') == 100 |
| 415 | + assert _normalize_weight('light') == 200 |
| 416 | + assert _normalize_weight('normal') == 400 |
| 417 | + assert _normalize_weight('regular') == 400 |
| 418 | + assert _normalize_weight('book') == 400 |
| 419 | + assert _normalize_weight('medium') == 500 |
| 420 | + assert _normalize_weight('roman') == 500 |
| 421 | + assert _normalize_weight('semibold') == 600 |
| 422 | + assert _normalize_weight('demibold') == 600 |
| 423 | + assert _normalize_weight('demi') == 600 |
| 424 | + assert _normalize_weight('bold') == 700 |
| 425 | + assert _normalize_weight('heavy') == 800 |
| 426 | + assert _normalize_weight('extra bold') == 800 |
| 427 | + assert _normalize_weight('black') == 900 |
| 428 | + |
| 429 | + |
| 430 | +def test_font_match_warning(caplog): |
| 431 | + findfont(FontProperties(family=["DejaVu Sans"], weight=750)) |
| 432 | + logs = [rec.message for rec in caplog.records] |
| 433 | + assert 'findfont: Failed to find font weight 750, now using 700.' in logs |
0 commit comments