mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
font: determine quirks modes on font face load
This commit is contained in:
@ -4,6 +4,7 @@ const Allocator = std.mem.Allocator;
|
|||||||
const macos = @import("macos");
|
const macos = @import("macos");
|
||||||
const harfbuzz = @import("harfbuzz");
|
const harfbuzz = @import("harfbuzz");
|
||||||
const font = @import("../main.zig");
|
const font = @import("../main.zig");
|
||||||
|
const quirks = @import("../../quirks.zig");
|
||||||
|
|
||||||
const log = std.log.scoped(.font_face);
|
const log = std.log.scoped(.font_face);
|
||||||
|
|
||||||
@ -20,6 +21,9 @@ pub const Face = struct {
|
|||||||
/// Metrics for this font face. These are useful for renderers.
|
/// Metrics for this font face. These are useful for renderers.
|
||||||
metrics: font.face.Metrics,
|
metrics: font.face.Metrics,
|
||||||
|
|
||||||
|
/// Set quirks.disableDefaultFontFeatures
|
||||||
|
quirks_disable_default_font_features: bool = false,
|
||||||
|
|
||||||
/// The matrix applied to a regular font to auto-italicize it.
|
/// The matrix applied to a regular font to auto-italicize it.
|
||||||
pub const italic_skew = macos.graphics.AffineTransform{
|
pub const italic_skew = macos.graphics.AffineTransform{
|
||||||
.a = 1,
|
.a = 1,
|
||||||
@ -65,12 +69,14 @@ pub const Face = struct {
|
|||||||
|
|
||||||
const traits = ct_font.getSymbolicTraits();
|
const traits = ct_font.getSymbolicTraits();
|
||||||
|
|
||||||
return Face{
|
var result: Face = .{
|
||||||
.font = ct_font,
|
.font = ct_font,
|
||||||
.hb_font = hb_font,
|
.hb_font = hb_font,
|
||||||
.presentation = if (traits.color_glyphs) .emoji else .text,
|
.presentation = if (traits.color_glyphs) .emoji else .text,
|
||||||
.metrics = try calcMetrics(ct_font),
|
.metrics = try calcMetrics(ct_font),
|
||||||
};
|
};
|
||||||
|
result.quirks_disable_default_font_features = quirks.disableDefaultFontFeatures(&result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Face) void {
|
pub fn deinit(self: *Face) void {
|
||||||
|
@ -18,6 +18,7 @@ const Library = font.Library;
|
|||||||
const Presentation = font.Presentation;
|
const Presentation = font.Presentation;
|
||||||
const convert = @import("freetype_convert.zig");
|
const convert = @import("freetype_convert.zig");
|
||||||
const fastmem = @import("../../fastmem.zig");
|
const fastmem = @import("../../fastmem.zig");
|
||||||
|
const quirks = @import("../../quirks.zig");
|
||||||
|
|
||||||
const log = std.log.scoped(.font_face);
|
const log = std.log.scoped(.font_face);
|
||||||
|
|
||||||
@ -35,6 +36,9 @@ pub const Face = struct {
|
|||||||
/// Metrics for this font face. These are useful for renderers.
|
/// Metrics for this font face. These are useful for renderers.
|
||||||
metrics: font.face.Metrics,
|
metrics: font.face.Metrics,
|
||||||
|
|
||||||
|
/// Set quirks.disableDefaultFontFeatures
|
||||||
|
quirks_disable_default_font_features: bool = false,
|
||||||
|
|
||||||
/// Initialize a new font face with the given source in-memory.
|
/// Initialize a new font face with the given source in-memory.
|
||||||
pub fn initFile(lib: Library, path: [:0]const u8, index: i32, size: font.face.DesiredSize) !Face {
|
pub fn initFile(lib: Library, path: [:0]const u8, index: i32, size: font.face.DesiredSize) !Face {
|
||||||
const face = try lib.lib.initFace(path, index);
|
const face = try lib.lib.initFace(path, index);
|
||||||
@ -56,12 +60,14 @@ pub const Face = struct {
|
|||||||
const hb_font = try harfbuzz.freetype.createFont(face.handle);
|
const hb_font = try harfbuzz.freetype.createFont(face.handle);
|
||||||
errdefer hb_font.destroy();
|
errdefer hb_font.destroy();
|
||||||
|
|
||||||
return Face{
|
var result: Face = .{
|
||||||
.face = face,
|
.face = face,
|
||||||
.hb_font = hb_font,
|
.hb_font = hb_font,
|
||||||
.presentation = if (face.hasColor()) .emoji else .text,
|
.presentation = if (face.hasColor()) .emoji else .text,
|
||||||
.metrics = calcMetrics(face),
|
.metrics = calcMetrics(face),
|
||||||
};
|
};
|
||||||
|
result.quirks_disable_default_font_features = quirks.disableDefaultFontFeatures(&result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Face) void {
|
pub fn deinit(self: *Face) void {
|
||||||
|
@ -12,7 +12,6 @@ const Library = font.Library;
|
|||||||
const Style = font.Style;
|
const Style = font.Style;
|
||||||
const Presentation = font.Presentation;
|
const Presentation = font.Presentation;
|
||||||
const terminal = @import("../../terminal/main.zig");
|
const terminal = @import("../../terminal/main.zig");
|
||||||
const quirks = @import("../../quirks.zig");
|
|
||||||
|
|
||||||
const log = std.log.scoped(.font_shaper);
|
const log = std.log.scoped(.font_shaper);
|
||||||
|
|
||||||
@ -108,7 +107,7 @@ pub const Shaper = struct {
|
|||||||
// fonts, the codepoint == glyph_index so we don't need to run any shaping.
|
// fonts, the codepoint == glyph_index so we don't need to run any shaping.
|
||||||
if (run.font_index.special() == null) {
|
if (run.font_index.special() == null) {
|
||||||
const face = try run.group.group.faceFromIndex(run.font_index);
|
const face = try run.group.group.faceFromIndex(run.font_index);
|
||||||
const i = if (!quirks.disableDefaultFontFeatures(face)) 0 else i: {
|
const i = if (!face.quirks_disable_default_font_features) 0 else i: {
|
||||||
// If we are disabling default font features we just offset
|
// If we are disabling default font features we just offset
|
||||||
// our features by the hardcoded items because always
|
// our features by the hardcoded items because always
|
||||||
// add those at the beginning.
|
// add those at the beginning.
|
||||||
|
Reference in New Issue
Block a user