freetype: init harfbuzz binding

This commit is contained in:
Ali Chraghi 2022-06-07 18:16:48 +04:30 committed by Stephen Gutekanst
parent 04a0a79ef6
commit 82e1990009
18 changed files with 111 additions and 31 deletions

View file

@ -1,45 +0,0 @@
const std = @import("std");
pub fn structToBitFields(comptime IntType: type, comptime EnumDataType: type, flags: anytype) IntType {
var value: IntType = 0;
inline for (comptime std.meta.fieldNames(EnumDataType)) |field_name| {
if (@field(flags, field_name)) {
value |= @enumToInt(@field(EnumDataType, field_name));
}
}
return value;
}
pub fn bitFieldsToStruct(comptime StructType: type, comptime EnumDataType: type, flags: anytype) StructType {
var value = std.mem.zeroes(StructType);
inline for (comptime std.meta.fieldNames(EnumDataType)) |field_name| {
if (flags & (@enumToInt(@field(EnumDataType, field_name))) != 0) {
@field(value, field_name) = true;
}
}
return value;
}
const TestEnum = enum(u16) {
filed_1 = (1 << 1),
filed_2 = (1 << 2),
filed_3 = (1 << 3),
};
const TestStruct = packed struct {
filed_1: bool = false,
filed_2: bool = false,
filed_3: bool = false,
};
test "struct fields to bit fields" {
try std.testing.expectEqual(@as(u16, (1 << 1) | (1 << 3)), structToBitFields(u16, TestEnum, TestStruct{
.filed_1 = true,
.filed_3 = true,
}));
try std.testing.expectEqual(@as(u16, 0), structToBitFields(u16, TestEnum, TestStruct{}));
}
test "bit fields to struct" {
try std.testing.expectEqual(TestStruct{ .filed_1 = true, .filed_2 = true, .filed_3 = false }, bitFieldsToStruct(TestStruct, TestEnum, (1 << 1) | (1 << 2)));
}