mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-29 20:07:55 +00:00
font: Face initializes a hb_font alongside every face
This commit is contained in:
@@ -8,6 +8,7 @@ const Face = @This();
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const freetype = @import("freetype");
|
||||
const harfbuzz = @import("harfbuzz");
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
const Allocator = std.mem.Allocator;
|
||||
@@ -20,6 +21,9 @@ const log = std.log.scoped(.font_face);
|
||||
/// Our font face.
|
||||
face: freetype.Face,
|
||||
|
||||
/// Harfbuzz font corresponding to this face.
|
||||
hb_font: harfbuzz.Font,
|
||||
|
||||
/// If a DPI can't be calculated, this DPI is used. This is probably
|
||||
/// wrong on modern devices so it is highly recommended you get the DPI
|
||||
/// using whatever platform method you can.
|
||||
@@ -48,11 +52,15 @@ pub fn init(lib: Library, source: [:0]const u8, size: DesiredSize) !Face {
|
||||
try face.selectCharmap(.unicode);
|
||||
try setSize_(face, size);
|
||||
|
||||
return Face{ .face = face };
|
||||
const hb_font = try harfbuzz.freetype.createFont(face.handle);
|
||||
errdefer hb_font.destroy();
|
||||
|
||||
return Face{ .face = face, .hb_font = hb_font };
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Face) void {
|
||||
self.face.deinit();
|
||||
self.hb_font.destroy();
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,6 @@ test "run iterator" {
|
||||
count += 1;
|
||||
|
||||
// All runs should be exactly length 1
|
||||
std.log.warn("YES", .{});
|
||||
try testing.expectEqual(@as(u32, 1), shaper.hb_buf.getLength());
|
||||
}
|
||||
try testing.expectEqual(@as(usize, 3), count);
|
||||
|
||||
Reference in New Issue
Block a user