mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
addGlyph returns glyph
This commit is contained in:
@ -112,7 +112,7 @@ pub fn getGlyph(self: FontAtlas, v: anytype) ?*Glyph {
|
|||||||
|
|
||||||
/// Add a glyph to the font atlas. The codepoint can be either a u8 or
|
/// Add a glyph to the font atlas. The codepoint can be either a u8 or
|
||||||
/// []const u8 depending on if you know it is ASCII or must be UTF-8 decoded.
|
/// []const u8 depending on if you know it is ASCII or must be UTF-8 decoded.
|
||||||
pub fn addGlyph(self: *FontAtlas, alloc: Allocator, v: anytype) !void {
|
pub fn addGlyph(self: *FontAtlas, alloc: Allocator, v: anytype) !*Glyph {
|
||||||
assert(self.ft_face != null);
|
assert(self.ft_face != null);
|
||||||
|
|
||||||
// We need a UTF32 codepoint for freetype
|
// We need a UTF32 codepoint for freetype
|
||||||
@ -120,7 +120,7 @@ pub fn addGlyph(self: *FontAtlas, alloc: Allocator, v: anytype) !void {
|
|||||||
|
|
||||||
// If we have this glyph loaded already then we're done.
|
// If we have this glyph loaded already then we're done.
|
||||||
const gop = try self.glyphs.getOrPut(alloc, utf32);
|
const gop = try self.glyphs.getOrPut(alloc, utf32);
|
||||||
if (gop.found_existing) return;
|
if (gop.found_existing) return gop.value_ptr;
|
||||||
errdefer _ = self.glyphs.remove(utf32);
|
errdefer _ = self.glyphs.remove(utf32);
|
||||||
|
|
||||||
const glyph_index = ftc.FT_Get_Char_Index(self.ft_face, utf32);
|
const glyph_index = ftc.FT_Get_Char_Index(self.ft_face, utf32);
|
||||||
@ -164,6 +164,7 @@ pub fn addGlyph(self: *FontAtlas, alloc: Allocator, v: anytype) !void {
|
|||||||
assert(region.height == tgt_h);
|
assert(region.height == tgt_h);
|
||||||
self.atlas.set(region, buffer);
|
self.atlas.set(region, buffer);
|
||||||
|
|
||||||
|
// Store glyph metadata
|
||||||
gop.value_ptr.* = .{
|
gop.value_ptr.* = .{
|
||||||
.width = tgt_w,
|
.width = tgt_w,
|
||||||
.height = tgt_h,
|
.height = tgt_h,
|
||||||
@ -177,6 +178,8 @@ pub fn addGlyph(self: *FontAtlas, alloc: Allocator, v: anytype) !void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
log.debug("loaded glyph codepoint={} glyph={}", .{ utf32, gop.value_ptr.* });
|
log.debug("loaded glyph codepoint={} glyph={}", .{ utf32, gop.value_ptr.* });
|
||||||
|
|
||||||
|
return gop.value_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert 26.6 pixel format to f32
|
/// Convert 26.6 pixel format to f32
|
||||||
|
@ -33,8 +33,8 @@ pub fn init(alloc: std.mem.Allocator) !TextRenderer {
|
|||||||
|
|
||||||
// Load all visible ASCII characters.
|
// Load all visible ASCII characters.
|
||||||
var i: u8 = 32;
|
var i: u8 = 32;
|
||||||
while (i < 127) : (i += 1) {
|
while (i <= 126) : (i += 1) {
|
||||||
try font.addGlyph(alloc, i);
|
_ = try font.addGlyph(alloc, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build our texture
|
// Build our texture
|
||||||
@ -133,7 +133,7 @@ pub fn render(
|
|||||||
const s1 = glyph.s1;
|
const s1 = glyph.s1;
|
||||||
const t1 = glyph.t1;
|
const t1 = glyph.t1;
|
||||||
|
|
||||||
std.log.info("CHAR ch={} x0={} y0={} x1={} y1={}", .{ c, x0, y0, x1, y1 });
|
//std.log.info("CHAR ch={} x0={} y0={} x1={} y1={}", .{ c, x0, y0, x1, y1 });
|
||||||
|
|
||||||
const vert = [4][9]f32{
|
const vert = [4][9]f32{
|
||||||
.{ x0, y0, 0, s0, t0, r, g, b, a },
|
.{ x0, y0, 0, s0, t0, r, g, b, a },
|
||||||
|
Reference in New Issue
Block a user