You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: problem with font property in text elements of svg figures #22528
Starting with 3.5.0, figures exported as SVG without font embedded in the file (i.e. “svg.fonttype” set to “none”) use the font CSS shorthand property.
The problem is that the font-family generic name is quoted and some viewers don’t like it (chrome for exemple). My understanding (reading https://developer.mozilla.org/en-US/docs/Web/CSS/font-family) is that only the family name should be quoted if it contains spaces.
In the text elements, the generic name of the font-family is quoted (here 'sans-serif') <text style="font: 10px 'sans-serif'; text-anchor: start" x="94.6" y="57.629812" transform="rotate(-0, 94.6, 57.629812)">test</text>
Expected outcome
The generic name of the font-family should not be quoted <text style="font: 10px sans-serif; text-anchor: start" x="94.6" y="57.629812" transform="rotate(-0, 94.6, 57.629812)">test</text>
Or something like this font_parts.append(f'{short_float_fmt(prop.get_size())}px') font_parts.append(", ".join([f'{prop.get_name()!r}'] + prop.get_family()))
Activity
[-][Bug]: [/-][+][Bug]: problem with font property in text elements of svg figures[/+]anntzer commentedon Feb 22, 2022
I agree with the report. The relevant code is at
matplotlib/lib/matplotlib/backends/backend_svg.py
Line 1124 in 81e9559
and I guess we simply need to hard-code the list of generic names that should not be quoted.
cderemble commentedon Feb 22, 2022
Or something like this
font_parts.append(f'{short_float_fmt(prop.get_size())}px')font_parts.append(", ".join([f'{prop.get_name()!r}'] + prop.get_family()))FIX: correctly handle generic font families in svg text-as-text mode
FIX: correctly handle generic font families in svg text-as-text mode
FIX: correctly handle generic font families in svg text-as-text mode
FIX: correctly handle generic font families in svg text-as-text mode
FIX: correctly handle generic font families in svg text-as-text mode
FIX: correctly handle generic font families in svg text-as-text mode
FIX: correctly handle generic font families in svg text-as-text mode
FIX: correctly handle generic font families in svg text-as-text mode
FIX: correctly handle generic font families in svg text-as-text mode
FIX: correctly handle generic font families in svg text-as-text mode