asciidoctor / asciidoctor-pdf

:page_with_curl: Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
https://docs.asciidoctor.org/pdf-converter/latest/
MIT License
1.14k stars 500 forks source link

Revisit how font metrics are handled #263

Closed mojavelinux closed 2 years ago

mojavelinux commented 9 years ago

Fonts in Asciidoctor PDF are tricky.

  1. We take for granted how much the browser does to give us a sane baseline for fonts with broken or nonsensical metrics. We take it for granted because we don't get that benefit in Asciidoctor PDF.
  2. The TTF library that Prawn uses (ttfunk) has some...caveats. It doesn't always read the font information correctly (or doesn't do the magic that the browser does). As a result, font metrics can get miscalculated (or, at the very least, not consistent from one font to another).

Prawn also doesn't provide a basic “line height” abstraction, so we had to shoehorn something into Asciidoctor PDF that mostly works. See: https://github.com/asciidoctor/asciidoctor-pdf/blob/master/lib/asciidoctor-pdf/prawn_ext/extensions.rb#L262-L283

I point these things out so there's an understanding that “font-size” and “line-height” in Asciidoctor PDF are a little kludgy at the moment.

I'd like to step back and do an analysis of how fonts and font metrics are being handled so that we can arrive at something a bit more sane that doesn't leak into the theme.

The easiest way to see the problem is to set the font-height to 1 and print some paragraphs in different fonts where the theme allows this control (paragraph, sidebar, example block, etc). You'll see that different fonts will leave different amounts of space between the lines. Atm, the default theme just “adjusts” to make due with these differences. But we can do better.

mojavelinux commented 2 years ago

Experience has shown us that the abstractions in the converter are sufficient. At this point, we're not going to change it as it would have a rippling effect both on the behavior of the converter and the documents it produces. Plus, we were able to resolve the top padding on the line height when text is split across pages in 2.0.0.