Forum › Bugs

Difference in line-height: normal rendering in Prince 16

0xhc
Hello Prince team,

I’m running Prince 16 and I’ve noticed a difference in how `line-height: normal` is resolved compared to web browsers.

Compared with the browser (I use Chromium version 133.0.6835.0), Prince renders the text with slightly shorter line boxes. The difference per line is very small but consistent, so it accumulates over many lines and becomes noticeable in longer documents.

The issue disappears when I use an explicit numeric line-height (for example, 1.4) instead of `normal`. With the same content, `line-height: normal` produces a noticeable gap at the bottom of the page, while an explicit line-height produces the same overall height in the browser and Prince, filling the page without a gap.

This makes me think the issue is specific to how `line-height: normal` is resolved in Prince.

I’ve attached a minimal example that reproduces the issue.

Could you please let me know if this behavior is expected, or if it could be considered a rendering discrepancy?

Best regards
  1. test-line-height.html‎ 266.2 kB
  2. test-line-height.pdf‎ 33.7 kB
pjrm
Thank you for pointing out this difference. I've now built scripts to compare line height between web browsers and Prince across a thousand fonts, and I see the following:
* The main difference is in rounding: web browsers were designed around low-resolution output displays, and round to integer coordinates even in their pdf output, whereas Prince was designed for resolution-independent pdf from the start, and uses essentially exact coordinates.
* Interestingly, Firefox's pdf output rounds not to multiples of 1px but to multiples of 0.5pt.
* At larger font sizes (where rounding is less significant), there is more difference between Firefox & Chromium than between Prince & Chromium: Prince and Chromium are with 1px of each other in line height, other than for the 2 fonts described below, whereas Firefox & Chromium differ in underlying calculations for some fonts.
* For the 2 fonts (out of >1000) whose 'hhea' lineGap field is negative, both Chromium and Firefox treat lineGap as zero, while Prince honours it. Apparently, distrusting a negative lineGap was considered the right choice a couple of decades ago when the ancestors of Firefox and Chromium were written, but most software today honours the field. (Honouring seems likely to be the right choice for the 2 Zapfino fonts in question; though it was only slightly negative.)

If you want consistent line height, then set 'line-height' to a fixed length rather than relying on 'normal'; this will also increase consistency between web browsers. The length should be a whole number of px. If you want consistency with Firefox's pdf output too, then make it an even number of px (as 2px = 1.5pt, a multiple of 0.5pt).

If using a number (like 1.4) rather than a length, then note that Chromium sometimes uses a font-size slightly different from what was requested. So I'd suggest making the font-size be a whole number of px (or even number of px), and using a number that would result in a whole (or even) number of px: e.g. if you want roughly 1.4 with a 16px font, then that's a line-height of 22.4px; so round that to 22px, and use the number 22÷16 = 1.375.