Forum Bugs

SVG Font-Size

pestafo
After switching to Prince 9.0 rev 4 we discovered, that text in SVG is rendered one third larger than before.

In the attached example the expected font-size for the axis labels is 6pt but in the generated PDF document the font-size is 8pt.
  1. svg.html8.2 kB
    The xhtml input file
  2. svg.pdf20.1 kB
    The resulting pdf file
mikeday
Units in SVG are relative to pixels, not absolute. Prince assumes a normal conversion factor of 96dpi, the same as web browsers, so 6pt in SVG will become 8px. The width of the SVG is 86.5mm, and the viewbox width is 245.19, giving approximately 72px per inch. So 8px in this SVG will be equivalent to 8pt in the final output. And that is how 6pt becomes 8pt.

Since this is terribly confusing, it makes more sense to imagine what will happen if the width/height of the SVG are increased, but the font size remains 6pt. If you try this, you will see that the text expands as well, staying in proportion with the rest of the image. Similarly, if you shrink the image really small, the text will also get smaller.

If you want 6pt text, you could specify 8pt or 6px; with the current 72dpi viewbox it will work out right. Alternatively, you could change the viewbox to be 96dpi, and specify 6pt. Or you could override the normal DPI value for pt/px conversions with the undocumented command-line option --css-dpi=72.

Sorry for the confusion! Using absolute units inside images that can scale up or down smashes coordinate systems together in complex ways. This is why it took us until Prince 9 to get it right. :)