|
From: Ethan A M. <sf...@us...> - 2012-10-12 17:35:25
|
On Thursday, October 11, 2012 12:42:22 pm Allin Cottrell wrote: > I'm comparing the output of gnuplot's svg and pngcairo > drivers, with a thought of making greater use of SVG. But > there seems to be a slight problem with the placement of key > text in the SVG output. Here's a little test script > > set term svg font "Sans,8" size 680,400 > set output 'test.svg' > set key left top > plot sin(x) title "PRIME" w l, cos(x) title "UNEMP" w l > > In the PNG version the key is just fine, but in SVG the "U" of > "UNEMP" gets tangled up with the y-axis (more or less, > depending on the magnification). I'm looking at the SVG using > librsvg, and also via the Adobe NPSVG3 library. To show what > I'm talking about, > I'm attaching the SVG output as converted to PNG by rsvg-convert > (at 96dpi). ^^^^^^^^^^ That dpi setting turns out to be relevant. I went back to the SVG spec and learned the following: - you can specify font-size in either absolute or relative units - font-size="8pt" requests an 8 point font regardless of the display resolution or current scaling. That's what gnuplot does. In theory, if you view an SVG document in a viewer that allows you to rescale the figure, the font should display as the same size even after rescaling the plot. That is, if you shrink the figure the font does _not_ shrink with it. - font-size="8" or font-size="8px" requests a font size relative to the current display units. It will scale up or down as the figure is re-sized. - For a 95dpi display, 8pt is translated to 10px. That is, it is displayed 25% larger than gnuplot was expecting. This is probably at the heart of the problem. - You can confirm this by opening the output of your test command in inkscape and then saving it to a new *.svg file. The original gnuplot output contains text marked "font-size:8pt" but inkscape converts this to "font-size:10" (no units). I don't know what is the best thing to do here. Being able to specify an absolute font size makes sense in many cases, but not in all cases. Perhaps we need a gnuplot terminal option that controls whether gnuplot writes out absolute or relative units for the font size. I suppose the code that estimates text length would have to be aware of this also. Ethan |