font: determine quirks modes on font face load

This commit is contained in:
Mitchell Hashimoto
2023-08-25 14:44:16 -07:00
parent b51ef704f4
commit f4738210e1
3 changed files with 15 additions and 4 deletions

View File

@ -4,6 +4,7 @@ const Allocator = std.mem.Allocator;
const macos = @import("macos");
const harfbuzz = @import("harfbuzz");
const font = @import("../main.zig");
const quirks = @import("../../quirks.zig");
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: font.face.Metrics,
/// Set quirks.disableDefaultFontFeatures
quirks_disable_default_font_features: bool = false,
/// The matrix applied to a regular font to auto-italicize it.
pub const italic_skew = macos.graphics.AffineTransform{
.a = 1,
@ -65,12 +69,14 @@ pub const Face = struct {
const traits = ct_font.getSymbolicTraits();
return Face{
var result: Face = .{
.font = ct_font,
.hb_font = hb_font,
.presentation = if (traits.color_glyphs) .emoji else .text,
.metrics = try calcMetrics(ct_font),
};
result.quirks_disable_default_font_features = quirks.disableDefaultFontFeatures(&result);
return result;
}
pub fn deinit(self: *Face) void {

View File

@ -18,6 +18,7 @@ const Library = font.Library;
const Presentation = font.Presentation;
const convert = @import("freetype_convert.zig");
const fastmem = @import("../../fastmem.zig");
const quirks = @import("../../quirks.zig");
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: font.face.Metrics,
/// Set quirks.disableDefaultFontFeatures
quirks_disable_default_font_features: bool = false,
/// 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 {
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);
errdefer hb_font.destroy();
return Face{
var result: Face = .{
.face = face,
.hb_font = hb_font,
.presentation = if (face.hasColor()) .emoji else .text,
.metrics = calcMetrics(face),
};
result.quirks_disable_default_font_features = quirks.disableDefaultFontFeatures(&result);
return result;
}
pub fn deinit(self: *Face) void {

View File

@ -12,7 +12,6 @@ const Library = font.Library;
const Style = font.Style;
const Presentation = font.Presentation;
const terminal = @import("../../terminal/main.zig");
const quirks = @import("../../quirks.zig");
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.
if (run.font_index.special() == null) {
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
// our features by the hardcoded items because always
// add those at the beginning.