mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Merge pull request #1079 from mitchellh/unadjusted-box
font/sprite: manually determine which box codepoints are unadjusted
This commit is contained in:
@ -79,6 +79,19 @@ pub fn renderGlyph(
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns true if this codepoint should be rendered with the
|
||||
/// width/height set to unadjusted values.
|
||||
pub fn unadjustedCodepoint(cp: u32) bool {
|
||||
return switch (cp) {
|
||||
@intFromEnum(Sprite.cursor_rect),
|
||||
@intFromEnum(Sprite.cursor_hollow_rect),
|
||||
@intFromEnum(Sprite.cursor_bar),
|
||||
=> true,
|
||||
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
fn draw(self: Box, alloc: Allocator, canvas: *font.sprite.Canvas, cp: u32) !void {
|
||||
switch (cp) {
|
||||
0x2500 => self.draw_light_horizontal(canvas),
|
||||
|
@ -68,30 +68,38 @@ pub fn renderGlyph(
|
||||
// Safe to ".?" because of the above assertion.
|
||||
return switch (Kind.init(cp).?) {
|
||||
.box => box: {
|
||||
// For box fonts, we want to adjust the height of the box
|
||||
// based on the original cell height, not the adjusted height.
|
||||
// This is because adjusted cell height doesn't change font size.
|
||||
const height, const offset = metrics: {
|
||||
const metrics = opts.grid_metrics orelse break :metrics .{ self.height, 0 };
|
||||
const height = metrics.original_cell_height orelse break :metrics .{ self.height, 0 };
|
||||
|
||||
// If our height shrunk, then we use the original adjusted
|
||||
// height because we don't want to overflow the cell.
|
||||
if (height >= self.height) break :metrics .{ self.height, 0 };
|
||||
|
||||
// The offset is divided by two because it is vertically
|
||||
// centered.
|
||||
break :metrics .{ height, (self.height - height) / 2 };
|
||||
};
|
||||
|
||||
const f: Box = .{
|
||||
const f: Box, const y_offset: u32 = face: {
|
||||
// Expected, usual values.
|
||||
var f: Box = .{
|
||||
.width = width,
|
||||
.height = height,
|
||||
.height = self.height,
|
||||
.thickness = self.thickness,
|
||||
};
|
||||
|
||||
// If the codepoint is unadjusted then we want to adjust
|
||||
// (heh) the width/height to the proper size and also record
|
||||
// an offset to apply to our final glyph so it renders in the
|
||||
// correct place because renderGlyph assumes full size.
|
||||
var y_offset: u32 = 0;
|
||||
if (Box.unadjustedCodepoint(cp)) unadjust: {
|
||||
const metrics = opts.grid_metrics orelse break :unadjust;
|
||||
const height = metrics.original_cell_height orelse break :unadjust;
|
||||
|
||||
// If our height shrunk, then we use the original adjusted
|
||||
// height because we don't want to overflow the cell.
|
||||
if (height >= self.height) break :unadjust;
|
||||
|
||||
// The offset is divided by two because it is vertically
|
||||
// centered.
|
||||
y_offset = (self.height - height) / 2;
|
||||
f.height = height;
|
||||
}
|
||||
|
||||
break :face .{ f, y_offset };
|
||||
};
|
||||
|
||||
var g = try f.renderGlyph(alloc, atlas, cp);
|
||||
g.offset_y += @intCast(offset);
|
||||
g.offset_y += @intCast(y_offset);
|
||||
break :box g;
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user