Fonts rendered are 25% larger than requested on SVG backend #1528

Closed
kghose opened this Issue Nov 23, 2012 · 5 comments

Comments

Projects
None yet
3 participants

kghose commented Nov 23, 2012

Problem The text painted with the 'text' function and any other lettering on the axes is 25% larger than requested

To reproduce

Here is a small example program that will reproduce the problem:

import matplotlib as mpl
mpl.use('Agg')
mpl.rcParams['svg.fonttype'] = 'none'
mpl.rcParams['font.sans-serif'] = ['Arial']
import pylab

pylab.figure(figsize=(3,1))
for f in xrange(5):
  pylab.text(f,0,f+10,fontsize=f+10)
pylab.setp(pylab.gca(),'xlim',[0,6],'ylim',[-1,1])
pylab.savefig('test.svg')

Opening up test.svg in inkscape will have all fontsizes larger by 25% (x 1.25)

Platform

Matplotlib version 1.2.0

Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

Member

dmcdougall commented Dec 3, 2012

Are you also using tex? The reason I ask is because I just found this line and this line in another PR. This may be a red herring, but I thought I would point it out so someone could look into it at some point.

kghose commented Dec 3, 2012

Hi dmcdougall: that's an important thought, but no. This is regular text.

Owner

mdboom commented Dec 4, 2012

This is a tricky problem. There are seemingly differences of opinion about how font size units are handled in SVG. Chrome, Firefox and Inkscape handle them all differently. What we have now works with Chrome and Firefox and is at least the "correct" size in Inkscape, even though it isn't displayed as such. And it's a hack -- the size of the image is specified in points, which causes 1 pixel === 1 point in user space, and then the font size is specified in pixels. Inkscape gets confused because it wants to display the fontsize in points in its UI. This can be fixed to work as expected in Inkscape, (by specifying all units in pixels, but not all in points, interestingly enough) but then the output doesn't display correctly on Chrome or Firefox. This could be made a user option, but I'm wary of adding more obscure user options. SVG standards compliance is not the greatest ;(

Member

dmcdougall commented Dec 4, 2012

@mdboom Interesting! I hadn't realised standards compliance was so shoddy.

I think it's reasonable to label this as WONTFIX, for the very reason of standards compliance.

@kghose Have you tried creating a pdf or eps file and using a third-party tool to convert to SVG? There may be third-party solutions that allow the user to adjust certain elements of the file, e.g. font size.

Member

dmcdougall commented Mar 29, 2013

Since this appears to be an issue of different browsers implementing different standards, I've labelled this as 'wontfix' and I'm going to close it. If somebody feels there is a way to fix this then please feel free to reopen it.

dmcdougall closed this Mar 29, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment