mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
font: Face initializes a hb_font alongside every face
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const freetypepkg = @import("../freetype/build.zig");
|
||||||
|
|
||||||
/// Directories with our includes.
|
/// Directories with our includes.
|
||||||
const root = thisDir() ++ "../../../vendor/harfbuzz/";
|
const root = thisDir() ++ "../../../vendor/harfbuzz/";
|
||||||
@ -9,6 +10,7 @@ pub const include_paths = .{include_path};
|
|||||||
pub const pkg = std.build.Pkg{
|
pub const pkg = std.build.Pkg{
|
||||||
.name = "harfbuzz",
|
.name = "harfbuzz",
|
||||||
.source = .{ .path = thisDir() ++ "/main.zig" },
|
.source = .{ .path = thisDir() ++ "/main.zig" },
|
||||||
|
.dependencies = &.{freetypepkg.pkg},
|
||||||
};
|
};
|
||||||
|
|
||||||
fn thisDir() []const u8 {
|
fn thisDir() []const u8 {
|
||||||
|
@ -7,7 +7,7 @@ pub usingnamespace @import("face.zig");
|
|||||||
pub usingnamespace @import("font.zig");
|
pub usingnamespace @import("font.zig");
|
||||||
pub usingnamespace @import("shape.zig");
|
pub usingnamespace @import("shape.zig");
|
||||||
pub usingnamespace @import("version.zig");
|
pub usingnamespace @import("version.zig");
|
||||||
pub const Freetype = @import("freetype.zig");
|
pub const freetype = @import("freetype.zig");
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@import("std").testing.refAllDecls(@This());
|
@import("std").testing.refAllDecls(@This());
|
||||||
|
@ -8,6 +8,7 @@ const Face = @This();
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const freetype = @import("freetype");
|
const freetype = @import("freetype");
|
||||||
|
const harfbuzz = @import("harfbuzz");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
@ -20,6 +21,9 @@ const log = std.log.scoped(.font_face);
|
|||||||
/// Our font face.
|
/// Our font face.
|
||||||
face: freetype.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
|
/// 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
|
/// wrong on modern devices so it is highly recommended you get the DPI
|
||||||
/// using whatever platform method you can.
|
/// 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 face.selectCharmap(.unicode);
|
||||||
try setSize_(face, size);
|
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 {
|
pub fn deinit(self: *Face) void {
|
||||||
self.face.deinit();
|
self.face.deinit();
|
||||||
|
self.hb_font.destroy();
|
||||||
self.* = undefined;
|
self.* = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,6 @@ test "run iterator" {
|
|||||||
count += 1;
|
count += 1;
|
||||||
|
|
||||||
// All runs should be exactly length 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(u32, 1), shaper.hb_buf.getLength());
|
||||||
}
|
}
|
||||||
try testing.expectEqual(@as(usize, 3), count);
|
try testing.expectEqual(@as(usize, 3), count);
|
||||||
|
Reference in New Issue
Block a user