EmbarkStudios / spirt

SPIR-🇹: shader-focused IR to target, transform and translate from 🦀
Apache License 2.0
102 stars 9 forks source link

print: accurately track (fractional) line width, and raise the max width back to 120. #37

Closed eddyb closed 1 year ago

eddyb commented 1 year ago

Originally found/fixed during the #33/#34/#35/#36 series of pretty-printing PRs.

Before this PR, we were treating all text the same, regardless of style, but this PR introduces the concept of "fractional columns" (integer multiples of 0.1ch, because our font-sizes are always integer multiples of 0.1em).

The result is much more accurate, and so far appears to perfectly match browser behavior (i.e. the transition of MAX_LINE_WIDTH from N-1 to N, where multi-line layout gets replaced with single-line layout, results in a line that "tightly fits" in a max-width: Nch container, with no spurious gaps or overflows).

Note however that the increased accuracy makes the layout favor HTML over plaintext (and we don't have a plaintext-vs-HTML "simultaneous layout", nor a way to hint what the output of pretty layout will be used for), so the plaintext output may feel more inconsistent as a result (but its aesthetics are of dubious value anyway).