freetype/harfbuzz: make Feature and Variation externed

to be used as actual type, not a handler
This commit is contained in:
root 2022-06-17 16:35:56 +04:30 committed by Stephen Gutekanst
parent 158d8a6c43
commit 09a8b1afac

View file

@ -218,64 +218,52 @@ pub const Language = struct {
} }
}; };
pub const Feature = struct { pub const Feature = extern struct {
handle: c.hb_feature_t, tag: c.hb_tag_t,
value: u32,
start: c_uint,
end: c_uint,
pub fn fromString(str: []const u8) ?Feature { pub fn fromString(str: []const u8) ?Feature {
var f: c.hb_feature_t = undefined; var f: Feature = undefined;
return if (c.hb_feature_from_string(str.ptr, @intCast(c_int, str.len), &f) > 1) return if (hb_feature_from_string(str.ptr, @intCast(c_int, str.len), &f) > 1)
Feature{ .handle = f } f
else else
null; null;
} }
pub fn toString(self: *Feature, buf: []u8) void { pub fn toString(self: *Feature, buf: []u8) void {
c.hb_feature_to_string(&self.handle, buf.ptr, @intCast(c_uint, buf.len)); hb_feature_to_string(self, buf.ptr, @intCast(c_uint, buf.len));
}
pub fn tag(self: Feature) Tag {
return .{ .handle = self.handle.tag };
}
pub fn value(self: Feature) u32 {
return self.handle.value;
}
pub fn start(self: Feature) u32 {
return self.handle.start;
}
pub fn end(self: Feature) u32 {
return self.handle.end;
} }
}; };
pub const Variation = struct { pub const Variation = extern struct {
handle: c.hb_variation_t, tag: u32,
value: f32,
pub fn fromString(str: []const u8) ?Variation { pub fn fromString(str: []const u8) ?Variation {
var v: c.hb_variation_t = undefined; var v: Variation = undefined;
return if (c.hb_variation_from_string(str.ptr, @intCast(c_int, str.len), &v) > 1) return if (hb_variation_from_string(str.ptr, @intCast(c_int, str.len), &v) > 1)
Variation{ .handle = v } v
else else
null; null;
} }
pub fn toString(self: *Variation, buf: []u8) void { pub fn toString(self: *Variation, buf: []u8) void {
c.hb_variation_to_string(&self.handle, buf.ptr, @intCast(c_uint, buf.len)); hb_variation_to_string(self, buf.ptr, @intCast(c_uint, buf.len));
} }
pub fn tag(self: Feature) Tag { pub fn tag(self: Variation) Tag {
return .{ .handle = self.handle.tag }; return .{ .handle = self.tag };
} }
pub fn value(self: Feature) u32 { pub fn value(self: Variation) f32 {
return self.handle.value; return self.value;
} }
}; };
pub const Tag = struct { pub const Tag = struct {
handle: c.hb_tag_t, handle: u32,
pub fn fromString(str: []const u8) Tag { pub fn fromString(str: []const u8) Tag {
return .{ .handle = c.hb_tag_from_string(str.ptr, @intCast(c_int, str.len)) }; return .{ .handle = c.hb_tag_from_string(str.ptr, @intCast(c_int, str.len)) };
@ -287,3 +275,8 @@ pub const Tag = struct {
return &str; return &str;
} }
}; };
pub extern fn hb_feature_from_string(str: [*c]const u8, len: c_int, feature: [*c]Feature) u8;
pub extern fn hb_feature_to_string(feature: [*c]Feature, buf: [*c]u8, size: c_uint) void;
pub extern fn hb_variation_from_string(str: [*c]const u8, len: c_int, variation: [*c]Variation) u8;
pub extern fn hb_variation_to_string(variation: [*c]Variation, buf: [*c]u8, size: c_uint) void;