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

Skip to content

Commit beec11a

Browse files
committed
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
1 parent a0eb716 commit beec11a

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

lib/matplotlib/backends/backend_svg.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,11 +1027,12 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
10271027
font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
10281028

10291029
attrib = {}
1030-
# Must add "px" to workaround a Firefox bug
1031-
style['font-size'] = short_float_fmt(prop.get_size()) + 'px'
10321030
style['font-family'] = str(font.family_name)
1033-
style['font-style'] = prop.get_style().lower()
10341031
style['font-weight'] = str(prop.get_weight()).lower()
1032+
style['font-stretch'] = str(prop.get_stretch()).lower()
1033+
style['font-style'] = prop.get_style().lower()
1034+
# Must add "px" to workaround a Firefox bug
1035+
style['font-size'] = short_float_fmt(prop.get_size()) + 'px'
10351036
attrib['style'] = generate_css(style)
10361037

10371038
if mtext and (angle == 0 or mtext.get_rotation_mode() == "anchor"):

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ def test_svgnone_with_data_coordinates():
141141
buf = fd.read().decode()
142142

143143
assert expected in buf
144+
for prop in ["family", "weight", "stretch", "style", "size"]:
145+
assert f"font-{prop}:" in buf
144146

145147

146148
def test_gid():

0 commit comments

Comments
 (0)