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

Skip to content
5 changes: 4 additions & 1 deletion lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
A class for storing Font properties.

It is used when populating the font lookup dictionary.
"""})
""",
'_repr_html_': lambda self: f"<span style='font-family:{self.name}'>{self.name}</span>", # noqa: E501
}
)


def ttfFontProperty(font):
Expand Down
14 changes: 11 additions & 3 deletions lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import pytest

from matplotlib.font_manager import (
findfont, findSystemFonts, FontProperties, fontManager, json_dump,
json_load, get_font, is_opentype_cff_font, MSUserFontDirectories,
_get_fontconfig_fonts, ft2font, ttfFontProperty, cbook)
findfont, findSystemFonts, FontEntry, FontProperties, fontManager,
json_dump, json_load, get_font, is_opentype_cff_font,
MSUserFontDirectories, _get_fontconfig_fonts, ft2font,
ttfFontProperty, cbook)
from matplotlib import pyplot as plt, rc_context

has_fclist = shutil.which('fc-list') is not None
Expand Down Expand Up @@ -268,6 +269,13 @@ def test_fontcache_thread_safe():
f"{proc.returncode}.")


def test_fontentry_dataclass():
entry = FontEntry(name="font-name")

assert type(entry.__doc__) == str
assert entry._repr_html_() == "<span style='font-family:font-name'>font-name</span>" # noqa: E501


@pytest.mark.skipif(sys.platform == 'win32', reason='Linux or OS only')
def test_get_font_names():
paths_mpl = [cbook._get_data_path('fonts', subdir) for subdir in ['ttf']]
Expand Down