Skip to content

Commit 0fc9830

Browse files
committed
Fix font sizes when displaying SVGs with fonttype "none" or "svgfont" in Firefox. Closes matplotlib#510.
1 parent 4f71782 commit 0fc9830

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/matplotlib/backends/backend_svg.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _get_hatch(self, gc, rgbFace):
331331
else:
332332
_, oid = oid
333333
return oid
334-
334+
335335
def _write_hatches(self):
336336
if not len(self._hatchd):
337337
return
@@ -445,7 +445,7 @@ def _write_clips(self):
445445
writer.element('rect', x=str(x), y=str(y), width=str(w), height=str(h))
446446
writer.end('clipPath')
447447
writer.end('defs')
448-
448+
449449
def _write_svgfonts(self):
450450
if not rcParams['svg.fonttype'] == 'svgfont':
451451
return
@@ -926,7 +926,8 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath):
926926
fontstyle = prop.get_style()
927927

928928
attrib = {}
929-
style['font-size'] = str(fontsize)
929+
# Must add "px" to workaround a Firefox bug
930+
style['font-size'] = str(fontsize) + 'px'
930931
style['font-family'] = str(fontfamily)
931932
style['font-style'] = prop.get_style().lower()
932933
attrib['style'] = generate_css(style)
@@ -967,7 +968,8 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath):
967968
spans = {}
968969
for font, fontsize, thetext, new_x, new_y, metrics in svg_glyphs:
969970
style = generate_css({
970-
'font-size': str(fontsize),
971+
# Must add "px" to work around a Firefox bug
972+
'font-size': str(fontsize) + 'px',
971973
'font-family': font.family_name,
972974
'font-style': font.style_name.lower()})
973975
if thetext == 32:

0 commit comments

Comments
 (0)