|
From: Ethan A M. <sf...@us...> - 2012-10-11 23:16:01
|
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
> set term pngcairo font "Sans,8" size 680,400
> set output 'test.png'
> replot
>
> 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).
The underlying issue is that for SVG, like PostScript, gnuplot has
to guess at the font properties for a font that will not actually
be selected until the file is later viewed in another program.
Here is the relevant code snippet from svg.trm:
/* since we cannot interrogate SVG about text properties and according
* to SVG 1.0 W3C Candidate Recommendation 2 August 2000 the
* "line-height" of the 'text' element is defined to be equal to the
* 'font-size' (!), we have to to define font properties in a less
* than optimal way */
SVG_fontAscent = (int) (SVG_fontSizeCur * 1.00 * SVG_SCALE);
SVG_fontDescent = (int) (SVG_fontSizeCur * 0.25 * SVG_SCALE);
SVG_fontLeading = (int) (SVG_fontSizeCur * 0.25 * SVG_SCALE);
SVG_fontAvWidth = (int) (SVG_fontSizeCur * 0.70 * SVG_SCALE);
Apparently for the font your viewer is choosing in response to a
request for "Sans", the average character width is greater than
70% of the nominal font size. It would be easy enough to bump
SVG_fontAvWidth up to 0.8 or something, but I imagine that in
turn might be too wide for other viewer+font+text combinations.
Contributing to the problem in your particular example is that fact that
the title is in all caps, and capital letters are wider than the "average"
letter in most proportionally-spaced fonts. We might be able to address
this part of the problem by modifying gnuplot's string width estimator
to bump up the estimate if there are many capital letters in the string.
Ethan
> 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).
>
>
|