mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
refactor: handle freetype load flags in face instead of renderer
This commit is contained in:
@ -305,7 +305,7 @@ const c = @cImport({
|
|||||||
/// * `autohint` - Use the freetype auto-hinter. Enabled by default.
|
/// * `autohint` - Use the freetype auto-hinter. Enabled by default.
|
||||||
///
|
///
|
||||||
/// Example: `hinting`, `no-hinting`, `force-autohint`, `no-force-autohint`
|
/// Example: `hinting`, `no-hinting`, `force-autohint`, `no-force-autohint`
|
||||||
@"freetype-load-flag": FreetypeLoadFlags = .{},
|
@"freetype-load-flags": FreetypeLoadFlags = .{},
|
||||||
|
|
||||||
/// A theme to use. If the theme is an absolute pathname, Ghostty will attempt
|
/// A theme to use. If the theme is an absolute pathname, Ghostty will attempt
|
||||||
/// to load that file as a theme. If that file does not exist or is inaccessible,
|
/// to load that file as a theme. If that file does not exist or is inaccessible,
|
||||||
@ -4586,7 +4586,7 @@ pub const GraphemeWidthMethod = enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// See freetype-load-flag
|
/// See freetype-load-flag
|
||||||
pub const FreetypeLoadFlags = packed struct {
|
pub const FreetypeLoadFlags = packed struct {
|
||||||
hinting: bool = true,
|
hinting: bool = true,
|
||||||
bitmap: bool = true,
|
bitmap: bool = true,
|
||||||
@"force-autohint": bool = false,
|
@"force-autohint": bool = false,
|
||||||
|
@ -452,6 +452,8 @@ pub const LoadOptions = struct {
|
|||||||
/// for this is owned by the user and is not freed by the collection.
|
/// for this is owned by the user and is not freed by the collection.
|
||||||
metric_modifiers: Metrics.ModifierSet = .{},
|
metric_modifiers: Metrics.ModifierSet = .{},
|
||||||
|
|
||||||
|
freetype_load_flags: config.Config.FreetypeLoadFlags = .{},
|
||||||
|
|
||||||
pub fn deinit(self: *LoadOptions, alloc: Allocator) void {
|
pub fn deinit(self: *LoadOptions, alloc: Allocator) void {
|
||||||
_ = self;
|
_ = self;
|
||||||
_ = alloc;
|
_ = alloc;
|
||||||
@ -462,6 +464,7 @@ pub const LoadOptions = struct {
|
|||||||
return .{
|
return .{
|
||||||
.size = self.size,
|
.size = self.size,
|
||||||
.metric_modifiers = &self.metric_modifiers,
|
.metric_modifiers = &self.metric_modifiers,
|
||||||
|
.freetype_load_flags = self.freetype_load_flags,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -168,6 +168,7 @@ fn collection(
|
|||||||
.library = self.font_lib,
|
.library = self.font_lib,
|
||||||
.size = size,
|
.size = size,
|
||||||
.metric_modifiers = key.metric_modifiers,
|
.metric_modifiers = key.metric_modifiers,
|
||||||
|
.freetype_load_flags = config.@"freetype-load-flags",
|
||||||
};
|
};
|
||||||
|
|
||||||
var c = Collection.init();
|
var c = Collection.init();
|
||||||
@ -427,6 +428,7 @@ pub const DerivedConfig = struct {
|
|||||||
@"adjust-strikethrough-position": ?Metrics.Modifier,
|
@"adjust-strikethrough-position": ?Metrics.Modifier,
|
||||||
@"adjust-strikethrough-thickness": ?Metrics.Modifier,
|
@"adjust-strikethrough-thickness": ?Metrics.Modifier,
|
||||||
@"adjust-cursor-thickness": ?Metrics.Modifier,
|
@"adjust-cursor-thickness": ?Metrics.Modifier,
|
||||||
|
@"freetype-load-flags": configpkg.Config.FreetypeLoadFlags,
|
||||||
|
|
||||||
/// Initialize a DerivedConfig. The config should be either a
|
/// Initialize a DerivedConfig. The config should be either a
|
||||||
/// config.Config or another DerivedConfig to clone from.
|
/// config.Config or another DerivedConfig to clone from.
|
||||||
@ -461,6 +463,7 @@ pub const DerivedConfig = struct {
|
|||||||
.@"adjust-strikethrough-position" = config.@"adjust-strikethrough-position",
|
.@"adjust-strikethrough-position" = config.@"adjust-strikethrough-position",
|
||||||
.@"adjust-strikethrough-thickness" = config.@"adjust-strikethrough-thickness",
|
.@"adjust-strikethrough-thickness" = config.@"adjust-strikethrough-thickness",
|
||||||
.@"adjust-cursor-thickness" = config.@"adjust-cursor-thickness",
|
.@"adjust-cursor-thickness" = config.@"adjust-cursor-thickness",
|
||||||
|
.@"freetype-load-flags" = config.@"freetype-load-flags",
|
||||||
|
|
||||||
// This must be last so the arena contains all our allocations
|
// This must be last so the arena contains all our allocations
|
||||||
// from above since Zig does assignment in order.
|
// from above since Zig does assignment in order.
|
||||||
@ -500,6 +503,8 @@ pub const Key = struct {
|
|||||||
/// font grid.
|
/// font grid.
|
||||||
font_size: DesiredSize = .{ .points = 12 },
|
font_size: DesiredSize = .{ .points = 12 },
|
||||||
|
|
||||||
|
load_flags: configpkg.Config.FreetypeLoadFlags = .{},
|
||||||
|
|
||||||
const style_offsets_len = std.enums.directEnumArrayLen(Style, 0);
|
const style_offsets_len = std.enums.directEnumArrayLen(Style, 0);
|
||||||
const StyleOffsets = [style_offsets_len]usize;
|
const StyleOffsets = [style_offsets_len]usize;
|
||||||
|
|
||||||
@ -618,6 +623,7 @@ pub const Key = struct {
|
|||||||
.codepoint_map = codepoint_map,
|
.codepoint_map = codepoint_map,
|
||||||
.metric_modifiers = metric_modifiers,
|
.metric_modifiers = metric_modifiers,
|
||||||
.font_size = font_size,
|
.font_size = font_size,
|
||||||
|
.load_flags = config.@"freetype-load-flags",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,6 +653,7 @@ pub const Key = struct {
|
|||||||
for (self.descriptors) |d| d.hash(hasher);
|
for (self.descriptors) |d| d.hash(hasher);
|
||||||
self.codepoint_map.hash(hasher);
|
self.codepoint_map.hash(hasher);
|
||||||
autoHash(hasher, self.metric_modifiers.count());
|
autoHash(hasher, self.metric_modifiers.count());
|
||||||
|
autoHash(hasher, self.load_flags);
|
||||||
if (self.metric_modifiers.count() > 0) {
|
if (self.metric_modifiers.count() > 0) {
|
||||||
inline for (@typeInfo(Metrics.Key).Enum.fields) |field| {
|
inline for (@typeInfo(Metrics.Key).Enum.fields) |field| {
|
||||||
const key = @field(Metrics.Key, field.name);
|
const key = @field(Metrics.Key, field.name);
|
||||||
|
@ -31,6 +31,7 @@ pub const default_dpi = if (builtin.os.tag == .macos) 72 else 96;
|
|||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
size: DesiredSize,
|
size: DesiredSize,
|
||||||
metric_modifiers: ?*const Metrics.ModifierSet = null,
|
metric_modifiers: ?*const Metrics.ModifierSet = null,
|
||||||
|
freetype_load_flags: FreetypeLoadFlags,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The desired size for loading a font.
|
/// The desired size for loading a font.
|
||||||
@ -91,8 +92,6 @@ pub const RenderOptions = struct {
|
|||||||
///
|
///
|
||||||
/// This only works with CoreText currently.
|
/// This only works with CoreText currently.
|
||||||
thicken: bool = false,
|
thicken: bool = false,
|
||||||
|
|
||||||
load_flags: FreetypeLoadFlags,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
@ -18,6 +18,7 @@ const Library = font.Library;
|
|||||||
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 quirks = @import("../../quirks.zig");
|
||||||
|
const FreetypeLoadFlags = @import("../../config/Config.zig").FreetypeLoadFlags;
|
||||||
|
|
||||||
const log = std.log.scoped(.font_face);
|
const log = std.log.scoped(.font_face);
|
||||||
|
|
||||||
@ -34,6 +35,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,
|
||||||
|
|
||||||
|
/// Metrics for this font face. These are useful for renderers.
|
||||||
|
load_flags: FreetypeLoadFlags,
|
||||||
|
|
||||||
/// Set quirks.disableDefaultFontFeatures
|
/// Set quirks.disableDefaultFontFeatures
|
||||||
quirks_disable_default_font_features: bool = false,
|
quirks_disable_default_font_features: bool = false,
|
||||||
|
|
||||||
@ -77,6 +81,7 @@ pub const Face = struct {
|
|||||||
.face = face,
|
.face = face,
|
||||||
.hb_font = hb_font,
|
.hb_font = hb_font,
|
||||||
.metrics = calcMetrics(face, opts.metric_modifiers),
|
.metrics = calcMetrics(face, opts.metric_modifiers),
|
||||||
|
.load_flags = opts.freetype_load_flags,
|
||||||
};
|
};
|
||||||
result.quirks_disable_default_font_features = quirks.disableDefaultFontFeatures(&result);
|
result.quirks_disable_default_font_features = quirks.disableDefaultFontFeatures(&result);
|
||||||
|
|
||||||
@ -318,13 +323,13 @@ pub const Face = struct {
|
|||||||
//
|
//
|
||||||
// This must be enabled for color faces though because those are
|
// This must be enabled for color faces though because those are
|
||||||
// often colored bitmaps, which we support.
|
// often colored bitmaps, which we support.
|
||||||
.no_bitmap = !self.face.hasColor() or !opts.load_flags.bitmap,
|
.no_bitmap = !self.face.hasColor() or !self.load_flags.bitmap,
|
||||||
|
|
||||||
// use options from config
|
// use options from config
|
||||||
.no_hinting = !opts.load_flags.hinting,
|
.no_hinting = !self.load_flags.hinting,
|
||||||
.force_autohint = !opts.load_flags.@"force-autohint",
|
.force_autohint = !self.load_flags.@"force-autohint",
|
||||||
.monochrome = !opts.load_flags.monochrome,
|
.monochrome = !self.load_flags.monochrome,
|
||||||
.no_autohint = !opts.load_flags.autohint,
|
.no_autohint = !self.load_flags.autohint,
|
||||||
});
|
});
|
||||||
const glyph = self.face.handle.*.glyph;
|
const glyph = self.face.handle.*.glyph;
|
||||||
|
|
||||||
|
@ -354,7 +354,6 @@ pub const DerivedConfig = struct {
|
|||||||
font_thicken: bool,
|
font_thicken: bool,
|
||||||
font_features: std.ArrayListUnmanaged([:0]const u8),
|
font_features: std.ArrayListUnmanaged([:0]const u8),
|
||||||
font_styles: font.CodepointResolver.StyleStatus,
|
font_styles: font.CodepointResolver.StyleStatus,
|
||||||
load_flags: configpkg.Config.FreetypeLoadFlags,
|
|
||||||
cursor_color: ?terminal.color.RGB,
|
cursor_color: ?terminal.color.RGB,
|
||||||
cursor_invert: bool,
|
cursor_invert: bool,
|
||||||
cursor_opacity: f64,
|
cursor_opacity: f64,
|
||||||
@ -400,14 +399,11 @@ pub const DerivedConfig = struct {
|
|||||||
|
|
||||||
const cursor_invert = config.@"cursor-invert-fg-bg";
|
const cursor_invert = config.@"cursor-invert-fg-bg";
|
||||||
|
|
||||||
const load_flags = config.@"freetype-load-flag";
|
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
|
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
|
||||||
.font_thicken = config.@"font-thicken",
|
.font_thicken = config.@"font-thicken",
|
||||||
.font_features = font_features,
|
.font_features = font_features,
|
||||||
.font_styles = font_styles,
|
.font_styles = font_styles,
|
||||||
.load_flags = load_flags,
|
|
||||||
|
|
||||||
.cursor_color = if (!cursor_invert and config.@"cursor-color" != null)
|
.cursor_color = if (!cursor_invert and config.@"cursor-color" != null)
|
||||||
config.@"cursor-color".?.toTerminalRGB()
|
config.@"cursor-color".?.toTerminalRGB()
|
||||||
@ -2723,7 +2719,6 @@ fn addUnderline(
|
|||||||
.{
|
.{
|
||||||
.cell_width = 1,
|
.cell_width = 1,
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2756,7 +2751,6 @@ fn addOverline(
|
|||||||
.{
|
.{
|
||||||
.cell_width = 1,
|
.cell_width = 1,
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2789,7 +2783,6 @@ fn addStrikethrough(
|
|||||||
.{
|
.{
|
||||||
.cell_width = 1,
|
.cell_width = 1,
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2829,7 +2822,6 @@ fn addGlyph(
|
|||||||
.{
|
.{
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.thicken = self.config.font_thicken,
|
.thicken = self.config.font_thicken,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2909,7 +2901,6 @@ fn addCursor(
|
|||||||
.{
|
.{
|
||||||
.cell_width = if (wide) 2 else 1,
|
.cell_width = if (wide) 2 else 1,
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error rendering cursor glyph err={}", .{err});
|
log.warn("error rendering cursor glyph err={}", .{err});
|
||||||
@ -2925,7 +2916,6 @@ fn addCursor(
|
|||||||
.{
|
.{
|
||||||
.cell_width = if (wide) 2 else 1,
|
.cell_width = if (wide) 2 else 1,
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error rendering cursor glyph err={}", .{err});
|
log.warn("error rendering cursor glyph err={}", .{err});
|
||||||
@ -2966,7 +2956,7 @@ fn addPreeditCell(
|
|||||||
@intCast(cp.codepoint),
|
@intCast(cp.codepoint),
|
||||||
.regular,
|
.regular,
|
||||||
.text,
|
.text,
|
||||||
.{ .grid_metrics = self.grid_metrics, .load_flags = self.config.load_flags },
|
.{ .grid_metrics = self.grid_metrics },
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error rendering preedit glyph err={}", .{err});
|
log.warn("error rendering preedit glyph err={}", .{err});
|
||||||
return;
|
return;
|
||||||
|
@ -289,7 +289,6 @@ pub const DerivedConfig = struct {
|
|||||||
font_thicken: bool,
|
font_thicken: bool,
|
||||||
font_features: std.ArrayListUnmanaged([:0]const u8),
|
font_features: std.ArrayListUnmanaged([:0]const u8),
|
||||||
font_styles: font.CodepointResolver.StyleStatus,
|
font_styles: font.CodepointResolver.StyleStatus,
|
||||||
load_flags: configpkg.Config.FreetypeLoadFlags,
|
|
||||||
cursor_color: ?terminal.color.RGB,
|
cursor_color: ?terminal.color.RGB,
|
||||||
cursor_invert: bool,
|
cursor_invert: bool,
|
||||||
cursor_text: ?terminal.color.RGB,
|
cursor_text: ?terminal.color.RGB,
|
||||||
@ -334,14 +333,11 @@ pub const DerivedConfig = struct {
|
|||||||
|
|
||||||
const cursor_invert = config.@"cursor-invert-fg-bg";
|
const cursor_invert = config.@"cursor-invert-fg-bg";
|
||||||
|
|
||||||
const load_flags = config.@"freetype-load-flag";
|
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
|
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
|
||||||
.font_thicken = config.@"font-thicken",
|
.font_thicken = config.@"font-thicken",
|
||||||
.font_features = font_features,
|
.font_features = font_features,
|
||||||
.font_styles = font_styles,
|
.font_styles = font_styles,
|
||||||
.load_flags = load_flags,
|
|
||||||
|
|
||||||
.cursor_color = if (!cursor_invert and config.@"cursor-color" != null)
|
.cursor_color = if (!cursor_invert and config.@"cursor-color" != null)
|
||||||
config.@"cursor-color".?.toTerminalRGB()
|
config.@"cursor-color".?.toTerminalRGB()
|
||||||
@ -1770,7 +1766,7 @@ fn addPreeditCell(
|
|||||||
@intCast(cp.codepoint),
|
@intCast(cp.codepoint),
|
||||||
.regular,
|
.regular,
|
||||||
.text,
|
.text,
|
||||||
.{ .grid_metrics = self.grid_metrics, .load_flags = self.config.load_flags },
|
.{ .grid_metrics = self.grid_metrics },
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error rendering preedit glyph err={}", .{err});
|
log.warn("error rendering preedit glyph err={}", .{err});
|
||||||
return;
|
return;
|
||||||
@ -1871,7 +1867,6 @@ fn addCursor(
|
|||||||
.{
|
.{
|
||||||
.cell_width = if (wide) 2 else 1,
|
.cell_width = if (wide) 2 else 1,
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error rendering cursor glyph err={}", .{err});
|
log.warn("error rendering cursor glyph err={}", .{err});
|
||||||
@ -1887,7 +1882,6 @@ fn addCursor(
|
|||||||
.{
|
.{
|
||||||
.cell_width = if (wide) 2 else 1,
|
.cell_width = if (wide) 2 else 1,
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
) catch |err| {
|
) catch |err| {
|
||||||
log.warn("error rendering cursor glyph err={}", .{err});
|
log.warn("error rendering cursor glyph err={}", .{err});
|
||||||
@ -1950,7 +1944,6 @@ fn addUnderline(
|
|||||||
.{
|
.{
|
||||||
.cell_width = 1,
|
.cell_width = 1,
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1992,7 +1985,6 @@ fn addOverline(
|
|||||||
.{
|
.{
|
||||||
.cell_width = 1,
|
.cell_width = 1,
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2034,7 +2026,6 @@ fn addStrikethrough(
|
|||||||
.{
|
.{
|
||||||
.cell_width = 1,
|
.cell_width = 1,
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -2083,7 +2074,6 @@ fn addGlyph(
|
|||||||
.{
|
.{
|
||||||
.grid_metrics = self.grid_metrics,
|
.grid_metrics = self.grid_metrics,
|
||||||
.thicken = self.config.font_thicken,
|
.thicken = self.config.font_thicken,
|
||||||
.load_flags = self.config.load_flags,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user