sile-typesetter / sile

The SILE Typesetter — Simon’s Improved Layout Engine
https://sile-typesetter.org
MIT License
1.63k stars 96 forks source link

\font[style=Italic] not working with one font #1824

Open someplaceguy opened 1 year ago

someplaceguy commented 1 year ago

I had a SILE document and was trying to see how it would look with a different font (Roboto Slab).

Surprisingly, the \em{} portions of the document stopped being italicized.

I figured that Roboto Slab was missing an Italic version, but I tried italicizing a Robot Slab paragraph in LibreOffice and (also) surprisingly it seemed to work fine.

I know almost nothing about fonts but ChatGPT told me that LibreOffice might be using synthetic styling and after digging a bit more, it seems that the harfbuzz library (which both SILE and LibreOffice seem to use?) seems to have some synthetic slant functionality, which perhaps could be used to artificially italicize a font?

However, I don't know whether this is possible to do in SILE right now. Any ideas?

For the record, I'm using SILE 0.14.5 (with harfbuzz 5.2.0) but can't easily upgrade to SILE 0.14.9 because the latter requires a newer harfbuzz library and it's difficult for me to upgrade it right now without affecting other packages.

Thanks!

someplaceguy commented 1 year ago

Also, SILE didn't output any warnings even though it couldn't italicize the font.

In this case I think it would have been helpful for SILE to have generated such warnings because if I hadn't looked carefully at the document, I could have missed the wrong styling being generated.

Omikhleia commented 1 year ago

So let's recap, there are two (different) things at stakes, which could eventually be split.

  1. No warning when the font does not have italics
  2. No "faked" italics (synthetic slant)

In my understanding, though it's a bit beyond my current knowledge, several components play a different role here. Finding and resolve fonts corresponding to the specification (fontconfig on Linux), then shaping characters (harfbuzz by default, though other "shapers" could be used), and outputting something, possibly with embedded fonts (libtexpdf by default for PDF). The whole picture probably involves all of them and might not be obvious.

Omikhleia commented 7 months ago

Interesting discovery today regarding synthetic slant and bold.

Just stumbled on that comment: https://github.com/sile-typesetter/sile/blob/master/src/justenoughlibtexpdf.c#L118-L120

Quick hack in outputters/libtexpdf.lua's method outputter:setFont, just before the pdf.loadfont call:

  font.slant = 30000
  font.embolden = 2

I don't know how the values are to be interpreted (trying to read the code, apparently some scale ratio as an integer / 65536 for the slant, and anything non-zero for embolden, but we have a dubious FIXME in libtexpdf's pdfdev.c where this is used...)

But it "somehow" works out of the box indeed:

image

So there could be a way to expose this nicely. We'd still need to detect the font does not have true italics or bold (EDIT:) and is not variable. Here I dunno ;)

alerque commented 7 months ago

Interesting indeed. I know that code was around but I didn't know it was so close to the surface so to speak.

Personally I don't think we should wire it up too smart. I would rather the choice to use fake slant/embolden options be a very deliberate thing, probably even in a package dedicated to the affair. Meanwhile the usual Italic mechanism can go on failing just like it is if the font doesn't support it. For user convenience we can throw a warning if we detect the font doesn't support something it is being asked to do, but I don't want to wire up the failure to load a real Italic variant directly to the fake slant mechanism.