reddit / emacs

Increasing line height globally

xsrvmy · 2022-09-17 23:12
Is there a way to increase the line height globally, so that if font fallback chooses a taller font, it doesn't shift the rest of the text downwards? My use case is that if I add Chinese text for any reason, the fallback font Noto Sans CJK is slightly taller than my coding font Iosevka which causes every line to shift down. Before anyone suggests this, changing line spacing does not address my issue. Luckily I probably can work around this by compiling the font with additional vertical spacing myself, but I'd rather just not have to do that every time the font updates.
eli-zaretskii · 2022-09-18 06:36
Try using `face-font-rescale-alist`. It isn't ideal, but that's all we have. The only alternative is to carefully choose the fonts you use so that their height matches.
xsrvmy · 2022-09-18 07:04
Yeah that defeats the point of using iosevka (it's exactly half width) Honestly I'm surprised there is no min line height override in 2022.
eli-zaretskii · 2022-09-18 07:51
Doing so is problematic with the current Emacs architecture of drawing text: we rely on font back-ends to draw characters, and they draw series of characters from the same font in one go, and obey the font metrics while at that. Emacs's display engine was designed on the assumption that variable-size fonts are expected and welcome, and that the requirement of having a uniform grid of characters is not important when variable-size fonts are used. It is strange for me to hear in the year 2022 that people still want the TTY-style fixed grid of characters on display.
xsrvmy · 2022-09-18 08:18
I did not say I wanted fixed grid display. I said I wanted a way to specify a minimum line height that is potentially higher than the default font metrics. I can see graphics, subscripts, larger section fonts, etc. raising the line height, but I think it is quite reasonable to expect that a normal run of text doesn't change the line height.
eli-zaretskii · 2022-09-18 13:07
"Normal" run of text doesn't. It's just that you consider text displayed by a different font to be "normal", and I don't. I also don't understand what's the problem with having lines of different height as need, but I repeat myself...
big_lentil · 2022-09-18 15:27
>and they draw series of characters from the same font in one go The behavior of "shift down preceding text in same line if a bunch of text exceeds existing line height" indicates to me that text rendering may be happening line by line though. If that's correct I'd assume it should be possible to track down where current line height is added to the sum of existing line heights to introduce some sort of minimum bound. Maybe not though IDK but I'm getting the feeling that this is the kind of issue where a solution could be hacked by changing a single line in C.
xsrvmy · 2022-09-18 15:27
Mainly because odd Chinese spacing. I think I'm just gonna switch to a different Chinese font without this leading issue. I have to figure out how to do it anyways cuz emacs defaulted to Korean. Or I'll build Iosevka with increased spacing. Update: I configured fallback to use unifont for now so shouldn't have any more issues for the time being.
eli-zaretskii · 2022-09-19 16:10
> The behavior of "shift down preceding text in same line if a bunch of text exceeds existing line height" indicates to me that text rendering may be happening line by line though. It's not. It's just that, by the time we call the GUI backend to actually draw on the glass, we have already figured out the maximum height of all the characters on that screen line, so we know where to put its baseline. > it should be possible to track down where current line height is added to the sum of existing line heights to introduce some sort of minimum bound. As I explained, the accumulation of glyph heights and actual drawing of glyphs are done in two separate places, and trying to "fix" font glyph metrics in our own code is a very bad idea -- we delegate the drawing to special libraries for a good reason. But feel free to submit patches to do this if you can find a way. I tried and failed, but I may have missed something.