mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 16:26:08 +03:00
fix offset for box glyphs
This commit is contained in:
@ -11,6 +11,8 @@ const pixman = @import("pixman");
|
|||||||
const font = @import("main.zig");
|
const font = @import("main.zig");
|
||||||
const Atlas = @import("../Atlas.zig");
|
const Atlas = @import("../Atlas.zig");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.box_font);
|
||||||
|
|
||||||
/// The cell width and height because the boxes are fit perfectly
|
/// The cell width and height because the boxes are fit perfectly
|
||||||
/// into a cell so that they all properly connect with zero spacing.
|
/// into a cell so that they all properly connect with zero spacing.
|
||||||
width: u32,
|
width: u32,
|
||||||
@ -49,11 +51,13 @@ pub fn renderGlyph(
|
|||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
atlas: *Atlas,
|
atlas: *Atlas,
|
||||||
cp: u32,
|
cp: u32,
|
||||||
|
font_size: font.face.DesiredSize,
|
||||||
) !font.Glyph {
|
) !font.Glyph {
|
||||||
assert(atlas.format == .greyscale);
|
assert(atlas.format == .greyscale);
|
||||||
|
|
||||||
// TODO: render depending on cp
|
// TODO: render depending on cp
|
||||||
_ = cp;
|
_ = cp;
|
||||||
|
_ = font_size;
|
||||||
|
|
||||||
// Determine the config for our image buffer. The images we draw
|
// Determine the config for our image buffer. The images we draw
|
||||||
// for boxes are always 8bpp
|
// for boxes are always 8bpp
|
||||||
@ -114,11 +118,16 @@ pub fn renderGlyph(
|
|||||||
atlas.set(region, buffer);
|
atlas.set(region, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Our coordinates start at the BOTTOM for our renderers so we have to
|
||||||
|
// specify an offset of the full height because we rendered a full size
|
||||||
|
// cell.
|
||||||
|
const offset_y = @intCast(i32, self.height);
|
||||||
|
|
||||||
return font.Glyph{
|
return font.Glyph{
|
||||||
.width = self.width,
|
.width = self.width,
|
||||||
.height = self.height,
|
.height = self.height,
|
||||||
.offset_x = 0,
|
.offset_x = 0,
|
||||||
.offset_y = 0,
|
.offset_y = offset_y,
|
||||||
.atlas_x = region.x,
|
.atlas_x = region.x,
|
||||||
.atlas_y = region.y,
|
.atlas_y = region.y,
|
||||||
.advance_x = @intToFloat(f32, self.width),
|
.advance_x = @intToFloat(f32, self.width),
|
||||||
@ -130,8 +139,8 @@ fn draw_box_drawings_light_horizontal(self: BoxFont, img: *pixman.Image) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn hline_middle(self: BoxFont, img: *pixman.Image, thickness: Thickness) void {
|
fn hline_middle(self: BoxFont, img: *pixman.Image, thickness: Thickness) void {
|
||||||
const height = thickness.height(self.thickness);
|
const thick_px = thickness.height(self.thickness);
|
||||||
self.hline(img, 0, self.width, (self.height - height) / 2, height);
|
self.hline(img, 0, self.width, (self.height - thick_px) / 2, thick_px);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hline(
|
fn hline(
|
||||||
@ -162,7 +171,12 @@ test "all" {
|
|||||||
defer atlas_greyscale.deinit(alloc);
|
defer atlas_greyscale.deinit(alloc);
|
||||||
|
|
||||||
const face: BoxFont = .{ .width = 18, .height = 36, .thickness = 2 };
|
const face: BoxFont = .{ .width = 18, .height = 36, .thickness = 2 };
|
||||||
const glyph = try face.renderGlyph(alloc, &atlas_greyscale, 0x2500);
|
const glyph = try face.renderGlyph(
|
||||||
|
alloc,
|
||||||
|
&atlas_greyscale,
|
||||||
|
0x2500,
|
||||||
|
.{ .points = 12 },
|
||||||
|
);
|
||||||
try testing.expectEqual(@as(u32, face.width), glyph.width);
|
try testing.expectEqual(@as(u32, face.width), glyph.width);
|
||||||
try testing.expectEqual(@as(u32, face.height), glyph.height);
|
try testing.expectEqual(@as(u32, face.height), glyph.height);
|
||||||
}
|
}
|
||||||
|
@ -282,6 +282,7 @@ pub fn renderGlyph(
|
|||||||
alloc,
|
alloc,
|
||||||
atlas,
|
atlas,
|
||||||
glyph_index,
|
glyph_index,
|
||||||
|
self.size,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -958,7 +958,6 @@ pub fn updateCell(
|
|||||||
// If the cell has a character, draw it
|
// If the cell has a character, draw it
|
||||||
if (cell.char > 0) {
|
if (cell.char > 0) {
|
||||||
// Render
|
// Render
|
||||||
const face = try self.font_group.group.faceFromIndex(shaper_run.font_index);
|
|
||||||
const glyph = try self.font_group.renderGlyph(
|
const glyph = try self.font_group.renderGlyph(
|
||||||
self.alloc,
|
self.alloc,
|
||||||
shaper_run.font_index,
|
shaper_run.font_index,
|
||||||
@ -967,8 +966,11 @@ pub fn updateCell(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// If we're rendering a color font, we use the color atlas
|
// If we're rendering a color font, we use the color atlas
|
||||||
var mode: GPUCellMode = .fg;
|
const presentation = try self.font_group.group.presentationFromIndex(shaper_run.font_index);
|
||||||
if (face.presentation == .emoji) mode = .fg_color;
|
var mode: GPUCellMode = switch (presentation) {
|
||||||
|
.text => .fg,
|
||||||
|
.emoji => .fg_color,
|
||||||
|
};
|
||||||
|
|
||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
.mode = mode,
|
.mode = mode,
|
||||||
|
Reference in New Issue
Block a user