mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 08:16:13 +03:00
renderer/metal: re-enable preedit rendering
This commit is contained in:
@ -199,7 +199,38 @@ pub const Render = struct {
|
|||||||
presentation: Presentation,
|
presentation: Presentation,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Render a glyph. This automatically determines the correct texture
|
/// Render a codepoint. This uses the first font index that has the codepoint
|
||||||
|
/// and matches the presentation requested. If the codepoint cannot be found
|
||||||
|
/// in any font, an null render is returned.
|
||||||
|
pub fn renderCodepoint(
|
||||||
|
self: *SharedGrid,
|
||||||
|
alloc: Allocator,
|
||||||
|
cp: u32,
|
||||||
|
style: Style,
|
||||||
|
p: ?Presentation,
|
||||||
|
opts: RenderOptions,
|
||||||
|
) !?Render {
|
||||||
|
// Note: we could optimize the below to use way less locking, but
|
||||||
|
// at the time of writing this codepath is only called for preedit
|
||||||
|
// text which is relatively rare and almost non-existent in multiple
|
||||||
|
// surfaces at the same time.
|
||||||
|
|
||||||
|
// Get the font that has the codepoint
|
||||||
|
const index = try self.getIndex(alloc, cp, style, p) orelse return null;
|
||||||
|
|
||||||
|
// Get the glyph for the font
|
||||||
|
const glyph_index = glyph_index: {
|
||||||
|
self.lock.lockShared();
|
||||||
|
defer self.lock.unlockShared();
|
||||||
|
const face = try self.resolver.collection.getFace(index);
|
||||||
|
break :glyph_index face.glyphIndex(cp) orelse return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Render
|
||||||
|
return try self.renderGlyph(alloc, index, glyph_index, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render a glyph index. This automatically determines the correct texture
|
||||||
/// atlas to use and caches the result.
|
/// atlas to use and caches the result.
|
||||||
pub fn renderGlyph(
|
pub fn renderGlyph(
|
||||||
self: *SharedGrid,
|
self: *SharedGrid,
|
||||||
|
@ -2033,39 +2033,25 @@ fn addPreeditCell(
|
|||||||
x: usize,
|
x: usize,
|
||||||
y: usize,
|
y: usize,
|
||||||
) !void {
|
) !void {
|
||||||
if (true) @panic("TODO"); // TODO(fontmem)
|
|
||||||
|
|
||||||
// Preedit is rendered inverted
|
// Preedit is rendered inverted
|
||||||
const bg = self.foreground_color;
|
const bg = self.foreground_color;
|
||||||
const fg = self.background_color;
|
const fg = self.background_color;
|
||||||
|
|
||||||
// Get the font for this codepoint.
|
// Render the glyph for our preedit text
|
||||||
const font_index = if (self.font_group.indexForCodepoint(
|
const render_ = self.font_grid.renderCodepoint(
|
||||||
self.alloc,
|
self.alloc,
|
||||||
@intCast(cp.codepoint),
|
@intCast(cp.codepoint),
|
||||||
.regular,
|
.regular,
|
||||||
.text,
|
.text,
|
||||||
)) |index| index orelse return else |_| return;
|
|
||||||
|
|
||||||
// Get the font face so we can get the glyph
|
|
||||||
const face = self.font_group.group.faceFromIndex(font_index) catch |err| {
|
|
||||||
log.warn("error getting face for font_index={} err={}", .{ font_index, err });
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Use the face to now get the glyph index
|
|
||||||
const glyph_index = face.glyphIndex(@intCast(cp.codepoint)) orelse return;
|
|
||||||
|
|
||||||
// Render the glyph for our preedit text
|
|
||||||
const glyph = self.font_group.renderGlyph(
|
|
||||||
self.alloc,
|
|
||||||
font_index,
|
|
||||||
glyph_index,
|
|
||||||
.{ .grid_metrics = self.grid_metrics },
|
.{ .grid_metrics = self.grid_metrics },
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error rendering preedit glyph err={}", .{err});
|
log.warn("error rendering preedit glyph err={}", .{err});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
const render = render_ orelse {
|
||||||
|
log.warn("failed to find font for preedit codepoint={X}", .{cp.codepoint});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
// Add our opaque background cell
|
// Add our opaque background cell
|
||||||
self.cells_bg.appendAssumeCapacity(.{
|
self.cells_bg.appendAssumeCapacity(.{
|
||||||
@ -2083,9 +2069,9 @@ fn addPreeditCell(
|
|||||||
.cell_width = if (cp.wide) 2 else 1,
|
.cell_width = if (cp.wide) 2 else 1,
|
||||||
.color = .{ fg.r, fg.g, fg.b, 255 },
|
.color = .{ fg.r, fg.g, fg.b, 255 },
|
||||||
.bg_color = .{ bg.r, bg.g, bg.b, 255 },
|
.bg_color = .{ bg.r, bg.g, bg.b, 255 },
|
||||||
.glyph_pos = .{ glyph.atlas_x, glyph.atlas_y },
|
.glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y },
|
||||||
.glyph_size = .{ glyph.width, glyph.height },
|
.glyph_size = .{ render.glyph.width, render.glyph.height },
|
||||||
.glyph_offset = .{ glyph.offset_x, glyph.offset_y },
|
.glyph_offset = .{ render.glyph.offset_x, render.glyph.offset_y },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user