From beec11aee229ecd5b104f0179e5b31d5c2178cd9 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 13 Feb 2020 01:02:17 +0100 Subject: [PATCH] Don't forget to set stretch when exporting font as svg reference. Also reordered properties to match the css standard https://drafts.csswg.org/css-fonts-3/#basic-font-props --- lib/matplotlib/backends/backend_svg.py | 7 ++++--- lib/matplotlib/tests/test_backend_svg.py | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) 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():