mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00
macos/text: FontTraits
This commit is contained in:
@ -87,27 +87,104 @@ pub const FontAttribute = enum {
|
|||||||
.style_name => *foundation.String,
|
.style_name => *foundation.String,
|
||||||
.traits => *foundation.Dictionary,
|
.traits => *foundation.Dictionary,
|
||||||
.variation => *foundation.Dictionary,
|
.variation => *foundation.Dictionary,
|
||||||
.size => *anyopaque, // CFNumber
|
.size => *foundation.Number,
|
||||||
.matrix => *anyopaque, // CFDataRef
|
.matrix => *anyopaque, // CFDataRef
|
||||||
.cascade_list => *foundation.Array,
|
.cascade_list => *foundation.Array,
|
||||||
.character_set => *anyopaque, // CFCharacterSetRef
|
.character_set => *anyopaque, // CFCharacterSetRef
|
||||||
.languages => *foundation.Array,
|
.languages => *foundation.Array,
|
||||||
.baseline_adjust => *anyopaque, // CFNumber
|
.baseline_adjust => *foundation.Number,
|
||||||
.macintosh_encodings => *anyopaque, // CFNumber
|
.macintosh_encodings => *foundation.Number,
|
||||||
.features => *foundation.Array,
|
.features => *foundation.Array,
|
||||||
.feature_settings => *foundation.Array,
|
.feature_settings => *foundation.Array,
|
||||||
.fixed_advance => *anyopaque, // CFNumber
|
.fixed_advance => *foundation.Number,
|
||||||
.orientation => *anyopaque, // CFNumber
|
.orientation => *foundation.Number,
|
||||||
.format => *anyopaque, // CFNumber
|
.format => *foundation.Number,
|
||||||
.registration_scope => *anyopaque, // CFNumber
|
.registration_scope => *foundation.Number,
|
||||||
.priority => *anyopaque, // CFNumber
|
.priority => *foundation.Number,
|
||||||
.enabled => *anyopaque, // CFNumber
|
.enabled => *foundation.Number,
|
||||||
.downloadable => *anyopaque, // CFBoolean
|
.downloadable => *anyopaque, // CFBoolean
|
||||||
.downloaded => *anyopaque, // CFBoolean
|
.downloaded => *anyopaque, // CFBoolean
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const FontTraitKey = enum {
|
||||||
|
symbolic,
|
||||||
|
weight,
|
||||||
|
width,
|
||||||
|
slant,
|
||||||
|
|
||||||
|
pub fn key(self: FontTraitKey) *foundation.String {
|
||||||
|
return @intToPtr(*foundation.String, @ptrToInt(switch (self) {
|
||||||
|
.symbolic => c.kCTFontSymbolicTrait,
|
||||||
|
.weight => c.kCTFontWeightTrait,
|
||||||
|
.width => c.kCTFontWidthTrait,
|
||||||
|
.slant => c.kCTFontFontSlantTrait,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn Value(self: FontTraitKey) type {
|
||||||
|
return switch (self) {
|
||||||
|
.symbolic => *foundation.Number,
|
||||||
|
.weight => *foundation.Number,
|
||||||
|
.width => *foundation.Number,
|
||||||
|
.slant => *foundation.Number,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const FontSymbolicTraits = packed struct {
|
||||||
|
italic: bool = false,
|
||||||
|
bold: bool = false,
|
||||||
|
_unused1: u3 = 0,
|
||||||
|
expanded: bool = false,
|
||||||
|
condensed: bool = false,
|
||||||
|
_unused2: u3 = 0,
|
||||||
|
monospace: bool = false,
|
||||||
|
vertical: bool = false,
|
||||||
|
ui_optimized: bool = false,
|
||||||
|
color_glyphs: bool = false,
|
||||||
|
composite: bool = false,
|
||||||
|
_padding: u17 = 0,
|
||||||
|
|
||||||
|
pub fn init(num: *foundation.Number) FontSymbolicTraits {
|
||||||
|
var raw: i32 = undefined;
|
||||||
|
_ = num.getValue(.sint32, &raw);
|
||||||
|
return @bitCast(FontSymbolicTraits, raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
try std.testing.expectEqual(
|
||||||
|
@bitSizeOf(c.CTFontSymbolicTraits),
|
||||||
|
@bitSizeOf(FontSymbolicTraits),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "bitcast" {
|
||||||
|
const actual: c.CTFontSymbolicTraits = c.kCTFontTraitMonoSpace | c.kCTFontTraitExpanded;
|
||||||
|
const expected: FontSymbolicTraits = .{
|
||||||
|
.monospace = true,
|
||||||
|
.expanded = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
try std.testing.expectEqual(actual, @bitCast(c.CTFontSymbolicTraits, expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
test "number" {
|
||||||
|
const raw: i32 = c.kCTFontTraitMonoSpace | c.kCTFontTraitExpanded;
|
||||||
|
const num = try foundation.Number.create(.sint32, &raw);
|
||||||
|
defer num.release();
|
||||||
|
|
||||||
|
const expected: FontSymbolicTraits = .{ .monospace = true, .expanded = true };
|
||||||
|
const actual = FontSymbolicTraits.init(num);
|
||||||
|
try std.testing.expect(std.meta.eql(expected, actual));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
test {
|
||||||
|
@import("std").testing.refAllDecls(@This());
|
||||||
|
}
|
||||||
|
|
||||||
test "descriptor" {
|
test "descriptor" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user