mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
font/coretext: split typographic leading equally when calculating cell height
This maybe is a robust way to get Monaspace fonts working. Previously, we used leading as part of the calculation in cell height. I don't remember why. It appears most popular monospace fonts (Fira Code, Berkeley Mono, JetBrains Mono, Monaco are the few I tested) have a value of 0 for leading, so this has no effect. But some fonts like Monaspace have a non-zero (positive) value, resulting in overly large cell heights. The issue is that we simply add leading to the height, without modifying ascent. Normally this is what you want (normal typesetting) but for terminals, we're trying to set text centered vertically in equally spaced grid cells. For this, we want to split the leading between the top and bottom.
This commit is contained in:
@ -466,10 +466,15 @@ pub const Face = struct {
|
|||||||
} = metrics: {
|
} = metrics: {
|
||||||
const ascent = @round(ct_font.getAscent());
|
const ascent = @round(ct_font.getAscent());
|
||||||
const descent = @round(ct_font.getDescent());
|
const descent = @round(ct_font.getDescent());
|
||||||
const leading = @round(ct_font.getLeading());
|
|
||||||
|
// Leading is the value between lines at the TOP of a line.
|
||||||
|
// Because we are rendering a fixed size terminal grid, we
|
||||||
|
// want the leading to be split equally between the top and bottom.
|
||||||
|
const leading = ct_font.getLeading();
|
||||||
|
|
||||||
break :metrics .{
|
break :metrics .{
|
||||||
.height = @floatCast(ascent + descent + leading),
|
.height = @floatCast(@round(ascent + descent + leading)),
|
||||||
.ascent = @floatCast(ascent),
|
.ascent = @floatCast(@round(ascent + (leading / 2))),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user