mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
font/coretext: face doesn't need harfbuzz font if we're not using it
This commit is contained in:
@ -13,8 +13,9 @@ pub const Face = struct {
|
||||
/// Our font face
|
||||
font: *macos.text.Font,
|
||||
|
||||
/// Harfbuzz font corresponding to this face.
|
||||
hb_font: harfbuzz.Font,
|
||||
/// Harfbuzz font corresponding to this face. We only use this
|
||||
/// if we're using Harfbuzz.
|
||||
hb_font: if (harfbuzz_shaper) harfbuzz.Font else void,
|
||||
|
||||
/// The presentation for this font.
|
||||
presentation: font.Presentation,
|
||||
@ -25,6 +26,10 @@ pub const Face = struct {
|
||||
/// Set quirks.disableDefaultFontFeatures
|
||||
quirks_disable_default_font_features: bool = false,
|
||||
|
||||
/// True if our build is using Harfbuzz. If we're not, we can avoid
|
||||
/// some Harfbuzz-specific code paths.
|
||||
const harfbuzz_shaper = font.Shaper == font.shape.harfbuzz.Shaper;
|
||||
|
||||
/// The matrix applied to a regular font to auto-italicize it.
|
||||
pub const italic_skew = macos.graphics.AffineTransform{
|
||||
.a = 1,
|
||||
@ -75,10 +80,6 @@ pub const Face = struct {
|
||||
/// Initialize a face with a CTFont. This will take ownership over
|
||||
/// the CTFont. This does NOT copy or retain the CTFont.
|
||||
pub fn initFont(ct_font: *macos.text.Font, opts: font.face.Options) !Face {
|
||||
var hb_font = try harfbuzz.coretext.createFont(ct_font);
|
||||
errdefer hb_font.destroy();
|
||||
hb_font.setScale(opts.size.pixels(), opts.size.pixels());
|
||||
|
||||
const traits = ct_font.getSymbolicTraits();
|
||||
const metrics = metrics: {
|
||||
var metrics = try calcMetrics(ct_font);
|
||||
@ -86,6 +87,13 @@ pub const Face = struct {
|
||||
break :metrics metrics;
|
||||
};
|
||||
|
||||
var hb_font = if (comptime harfbuzz_shaper) font: {
|
||||
var hb_font = try harfbuzz.coretext.createFont(ct_font);
|
||||
hb_font.setScale(opts.size.pixels(), opts.size.pixels());
|
||||
break :font hb_font;
|
||||
} else {};
|
||||
errdefer if (comptime harfbuzz_shaper) hb_font.destroy();
|
||||
|
||||
var result: Face = .{
|
||||
.font = ct_font,
|
||||
.hb_font = hb_font,
|
||||
@ -144,7 +152,7 @@ pub const Face = struct {
|
||||
|
||||
pub fn deinit(self: *Face) void {
|
||||
self.font.release();
|
||||
self.hb_font.destroy();
|
||||
if (comptime harfbuzz_shaper) self.hb_font.destroy();
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
const builtin = @import("builtin");
|
||||
const options = @import("main.zig").options;
|
||||
const harfbuzz = @import("shaper/harfbuzz.zig");
|
||||
const coretext = @import("shaper/coretext.zig");
|
||||
pub const harfbuzz = @import("shaper/harfbuzz.zig");
|
||||
pub const coretext = @import("shaper/coretext.zig");
|
||||
pub const web_canvas = @import("shaper/web_canvas.zig");
|
||||
pub usingnamespace @import("shaper/run.zig");
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const harfbuzz = @import("harfbuzz");
|
||||
const macos = @import("macos");
|
||||
const trace = @import("tracy").trace;
|
||||
const font = @import("../main.zig");
|
||||
|
Reference in New Issue
Block a user