refactor: define FreetypeLoadFlags struct and default in font.face

This commit is contained in:
Nadir Fejzic
2024-11-09 11:55:29 +01:00
parent e7f286d83f
commit 83c4d0077b
5 changed files with 19 additions and 39 deletions

View File

@ -11,18 +11,6 @@ pub const url = @import("config/url.zig");
pub const FileFormatter = formatter.FileFormatter; pub const FileFormatter = formatter.FileFormatter;
pub const entryFormatter = formatter.entryFormatter; pub const entryFormatter = formatter.entryFormatter;
pub const formatEntry = formatter.formatEntry; pub const formatEntry = formatter.formatEntry;
pub const FreetypeLoadFlags = switch (options.backend) {
.freetype,
.fontconfig_freetype,
.coretext_freetype,
=> Config.FreetypeLoadFlags,
.coretext,
.coretext_harfbuzz,
.coretext_noshape,
.web_canvas,
=> void,
};
// Field types // Field types
pub const ClipboardAccess = Config.ClipboardAccess; pub const ClipboardAccess = Config.ClipboardAccess;

View File

@ -452,18 +452,7 @@ 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.FreetypeLoadFlags = switch (font.options.backend) { freetype_load_flags: font.face.FreetypeLoadFlags = font.face.freetype_load_flags_default,
.freetype,
.fontconfig_freetype,
.coretext_freetype,
=> .{},
.coretext,
.coretext_harfbuzz,
.coretext_noshape,
.web_canvas,
=> {},
},
pub fn deinit(self: *LoadOptions, alloc: Allocator) void { pub fn deinit(self: *LoadOptions, alloc: Allocator) void {
_ = self; _ = self;

View File

@ -428,7 +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.FreetypeLoadFlags, @"freetype-load-flags": font.face.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.
@ -514,18 +514,7 @@ pub const Key = struct {
/// font grid. /// font grid.
font_size: DesiredSize = .{ .points = 12 }, font_size: DesiredSize = .{ .points = 12 },
load_flags: configpkg.FreetypeLoadFlags = switch (font.options.backend) { load_flags: configpkg.FreetypeLoadFlags = font.face.freetype_load_flags_default,
.freetype,
.fontconfig_freetype,
.coretext_freetype,
=> .{},
.coretext,
.coretext_harfbuzz,
.coretext_noshape,
.web_canvas,
=> {},
},
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;

View File

@ -27,11 +27,25 @@ pub const Face = switch (options.backend) {
/// using whatever platform method you can. /// using whatever platform method you can.
pub const default_dpi = if (builtin.os.tag == .macos) 72 else 96; pub const default_dpi = if (builtin.os.tag == .macos) 72 else 96;
pub const FreetypeLoadFlags = switch (options.backend) {
.freetype,
.fontconfig_freetype,
.coretext_freetype,
=> config.Config.FreetypeLoadFlags,
.coretext,
.coretext_harfbuzz,
.coretext_noshape,
.web_canvas,
=> void,
};
pub const freetype_load_flags_default = if (options.backend.hasFreetype()) .{} else {};
/// Options for initializing a font face. /// Options for initializing a font face.
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: config.FreetypeLoadFlags, freetype_load_flags: FreetypeLoadFlags,
}; };
/// The desired size for loading a font. /// The desired size for loading a font.

View File

@ -36,7 +36,7 @@ pub const Face = struct {
metrics: font.face.Metrics, metrics: font.face.Metrics,
/// Freetype load flags for this font face. /// Freetype load flags for this font face.
load_flags: config.FreetypeLoadFlags, load_flags: font.face.FreetypeLoadFlags,
/// Set quirks.disableDefaultFontFeatures /// Set quirks.disableDefaultFontFeatures
quirks_disable_default_font_features: bool = false, quirks_disable_default_font_features: bool = false,