diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index a697b6c19d3e..eaa0f9e0c58b 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -1027,11 +1027,12 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None): font.set_text(s, 0.0, flags=LOAD_NO_HINTING) attrib = {} - # Must add "px" to workaround a Firefox bug - style['font-size'] = short_float_fmt(prop.get_size()) + 'px' style['font-family'] = str(font.family_name) - style['font-style'] = prop.get_style().lower() style['font-weight'] = str(prop.get_weight()).lower() + style['font-stretch'] = str(prop.get_stretch()).lower() + style['font-style'] = prop.get_style().lower() + # Must add "px" to workaround a Firefox bug + style['font-size'] = short_float_fmt(prop.get_size()) + 'px' attrib['style'] = generate_css(style) if mtext and (angle == 0 or mtext.get_rotation_mode() == "anchor"): diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py index 5c27149b725d..1000cf02295d 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -141,6 +141,8 @@ def test_svgnone_with_data_coordinates(): buf = fd.read().decode() assert expected in buf + for prop in ["family", "weight", "stretch", "style", "size"]: + assert f"font-{prop}:" in buf def test_gid():