Skip to content

Commit 5cf6533

Browse files
committed
created _repr_html_ for FontEntry objects
1 parent 6f1be17 commit 5cf6533

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/matplotlib/font_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
395395
A class for storing Font properties.
396396
397397
It is used when populating the font lookup dictionary.
398-
"""})
398+
""",
399+
'_repr_html_': lambda self: f"<span style='font-family:{self.name}'>{self.name}</span>", # noqa: E501
400+
}
401+
)
399402

400403

401404
def ttfFontProperty(font):

lib/matplotlib/tests/test_font_manager.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pytest
1212

1313
from matplotlib.font_manager import (
14-
findfont, findSystemFonts, FontProperties, fontManager, json_dump,
14+
findfont, findSystemFonts, FontEntry, FontProperties, fontManager, json_dump,
1515
json_load, get_font, is_opentype_cff_font, MSUserFontDirectories,
1616
_get_fontconfig_fonts)
1717
from matplotlib import pyplot as plt, rc_context
@@ -266,3 +266,10 @@ def test_fontcache_thread_safe():
266266
if proc.returncode:
267267
pytest.fail("The subprocess returned with non-zero exit status "
268268
f"{proc.returncode}.")
269+
270+
271+
def test_fontentry_dataclass():
272+
entry = FontEntry(name="font-name")
273+
274+
assert type(entry.__doc__) == str
275+
assert entry._repr_html_() == "<span style='font-family:font-name'>font-name</span>"

0 commit comments

Comments
 (0)