mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Merge pull request #1111 from mitchellh/adjust-width
font: center text when adjust-cell-width is used
This commit is contained in:
@ -384,11 +384,11 @@ pub const Face = struct {
|
||||
};
|
||||
atlas.set(region, buf);
|
||||
|
||||
const metrics = opts.grid_metrics orelse self.metrics;
|
||||
const offset_y: i32 = offset_y: {
|
||||
// Our Y coordinate in 3D is (0, 0) bottom left, +y is UP.
|
||||
// We need to calculate our baseline from the bottom of a cell.
|
||||
//const baseline_from_bottom: f64 = @floatFromInt(self.metrics.cell_baseline);
|
||||
const metrics = opts.grid_metrics orelse self.metrics;
|
||||
const baseline_from_bottom: f64 = @floatFromInt(metrics.cell_baseline);
|
||||
|
||||
// Next we offset our baseline by the bearing in the font. We
|
||||
@ -398,6 +398,21 @@ pub const Face = struct {
|
||||
break :offset_y @intFromFloat(@ceil(baseline_with_offset));
|
||||
};
|
||||
|
||||
const offset_x: i32 = offset_x: {
|
||||
var result: i32 = @intFromFloat(render_x);
|
||||
|
||||
// If our cell was resized to be wider then we center our
|
||||
// glyph in the cell.
|
||||
if (metrics.original_cell_width) |original_width| {
|
||||
if (original_width < metrics.cell_width) {
|
||||
const diff = (metrics.cell_width - original_width) / 2;
|
||||
result += @intCast(diff);
|
||||
}
|
||||
}
|
||||
|
||||
break :offset_x result;
|
||||
};
|
||||
|
||||
// Get our advance
|
||||
var advances: [glyphs.len]macos.graphics.Size = undefined;
|
||||
_ = self.font.getAdvancesForGlyphs(.horizontal, &glyphs, &advances);
|
||||
@ -417,7 +432,7 @@ pub const Face = struct {
|
||||
return .{
|
||||
.width = width,
|
||||
.height = height,
|
||||
.offset_x = @intFromFloat(render_x),
|
||||
.offset_x = offset_x,
|
||||
.offset_y = offset_y,
|
||||
.atlas_x = region.x,
|
||||
.atlas_y = region.y,
|
||||
|
@ -430,6 +430,21 @@ pub const Face = struct {
|
||||
break :offset_y glyph_metrics.bitmap_top + @as(c_int, @intCast(metrics.cell_baseline));
|
||||
};
|
||||
|
||||
const offset_x: i32 = offset_x: {
|
||||
var result: i32 = glyph_metrics.bitmap_left;
|
||||
|
||||
// If our cell was resized to be wider then we center our
|
||||
// glyph in the cell.
|
||||
if (metrics.original_cell_width) |original_width| {
|
||||
if (original_width < metrics.cell_width) {
|
||||
const diff = (metrics.cell_width - original_width) / 2;
|
||||
result += @intCast(diff);
|
||||
}
|
||||
}
|
||||
|
||||
break :offset_x result;
|
||||
};
|
||||
|
||||
// log.warn("renderGlyph width={} height={} offset_x={} offset_y={} glyph_metrics={}", .{
|
||||
// tgt_w,
|
||||
// tgt_h,
|
||||
@ -442,7 +457,7 @@ pub const Face = struct {
|
||||
return Glyph{
|
||||
.width = tgt_w,
|
||||
.height = tgt_h,
|
||||
.offset_x = glyph_metrics.bitmap_left,
|
||||
.offset_x = offset_x,
|
||||
.offset_y = offset_y,
|
||||
.atlas_x = region.x,
|
||||
.atlas_y = region.y,
|
||||
|
Reference in New Issue
Block a user