mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Fix underline/strikeout position with larger fonts
This commit is contained in:
@ -346,13 +346,18 @@ fn calcMetrics(face: freetype.Face) Metrics {
|
|||||||
// The underline position. This is a value from the top where the
|
// The underline position. This is a value from the top where the
|
||||||
// underline should go.
|
// underline should go.
|
||||||
const underline_position = underline_pos: {
|
const underline_position = underline_pos: {
|
||||||
|
// The ascender is already scaled for scalable fonts, but the
|
||||||
|
// underline position is not.
|
||||||
|
const ascender_px = @intCast(i32, size_metrics.ascender) >> 6;
|
||||||
|
const declared_px = freetype.mulFix(
|
||||||
|
face.handle.*.underline_position,
|
||||||
|
@intCast(i32, face.handle.*.size.*.metrics.y_scale),
|
||||||
|
) >> 6;
|
||||||
|
|
||||||
// We use the declared underline position if its available
|
// We use the declared underline position if its available
|
||||||
const declared = fontUnitsToPxY(
|
const declared = ascender_px - declared_px;
|
||||||
face,
|
|
||||||
@intCast(i32, size_metrics.ascender) - face.handle.*.underline_position,
|
|
||||||
);
|
|
||||||
if (declared > 0)
|
if (declared > 0)
|
||||||
break :underline_pos declared;
|
break :underline_pos @intToFloat(f32, declared);
|
||||||
|
|
||||||
// If we have no declared underline position, we go slightly under the
|
// If we have no declared underline position, we go slightly under the
|
||||||
// cell height (mainly: non-scalable fonts, i.e. emoji)
|
// cell height (mainly: non-scalable fonts, i.e. emoji)
|
||||||
@ -369,10 +374,16 @@ fn calcMetrics(face: freetype.Face) Metrics {
|
|||||||
pos: f32,
|
pos: f32,
|
||||||
thickness: f32,
|
thickness: f32,
|
||||||
} = if (face.getSfntTable(.os2)) |os2| .{
|
} = if (face.getSfntTable(.os2)) |os2| .{
|
||||||
.pos = fontUnitsToPxY(face, @maximum(
|
.pos = pos: {
|
||||||
0,
|
// Ascender is scaled, strikeout pos is not
|
||||||
@intCast(i32, size_metrics.ascender) - os2.yStrikeoutPosition,
|
const ascender_px = @intCast(i32, size_metrics.ascender) >> 6;
|
||||||
)),
|
const declared_px = freetype.mulFix(
|
||||||
|
os2.yStrikeoutPosition,
|
||||||
|
@intCast(i32, face.handle.*.size.*.metrics.y_scale),
|
||||||
|
) >> 6;
|
||||||
|
|
||||||
|
break :pos @intToFloat(f32, ascender_px - declared_px);
|
||||||
|
},
|
||||||
.thickness = @maximum(1, fontUnitsToPxY(face, os2.yStrikeoutSize)),
|
.thickness = @maximum(1, fontUnitsToPxY(face, os2.yStrikeoutSize)),
|
||||||
} else .{
|
} else .{
|
||||||
.pos = cell_baseline * 0.6,
|
.pos = cell_baseline * 0.6,
|
||||||
|
Reference in New Issue
Block a user