sile-typesetter / sile

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

Monospace fonts should disable stretchy spaces #936

Open alerque opened 4 years ago

alerque commented 4 years ago

Ignoring for the moment the egregiously long space stretch happening here because parfillskip didn't kick in, the monospaced \code bit of this line shouldn't have allowed spaces to stretch:

image

I know how to disable this myself, but it seems like their should be a less verbose way to do it. Either monospace fonts should be detected and this should happen automatically or there should me a much simpler way to set this as part of \font or something.

ctrlcctrlv commented 3 years ago

@alerque How do I disable it?

alerque commented 3 years ago

There are two possible mechanisms depending on how your document is setup. The legacy one can be disabled like this:

SILE.settings.set("document.spaceskip", SILE.length("1spc"))

Since not specifying any stretch or shrink on a SILE length defaults them to zero this will suppress that behavior. The newer one can be suppressed like this:

SILE.settings.set("shaper.spacestretchfactor",  0)
SILE.settings.set("shaper.spaceshrinkfactor",  0)

The obvious problem (and hence this issue) is that it's scoped to the document (or shaper), not the duration of the font, so you need to retrieve the value, stash it, then disable it, then restore it when your thing goes out of scope.

Omikhleia commented 7 hours ago

For well-made Latin OpenType fonts, the fact it's intended to be a "monospace" font can be deduced from one of the PANOSE properties in the OS/2 table. We could therefore easily detect this and consider using a fixed inter-word space in this case...

Here is a quick demonstration monospace.diff.txt (diff against SILE 0.15.5).

But playing with it, in situation where the surrounding context gets all sorts of space stretching or shrinking for justification, you would quickly realize that it's not probably what you expected for nice typography....

That is to say, this 4-year old enhancement idea is very interesting, but likely needs a more thoughtful specification.