freetype: support compiling with stage2 (-fno-stage1)

This commit is contained in:
PiergiorgioZagaria 2022-07-06 11:59:28 +02:00 committed by Stephen Gutekanst
parent d3b03901fb
commit b4ac18ec57
10 changed files with 61 additions and 29 deletions

View file

@ -123,7 +123,7 @@ pub fn getCharIndex(self: Face, char: u32) ?u32 {
}
pub fn getNameIndex(self: Face, name: [:0]const u8) ?u32 {
const i = c.FT_Get_Name_Index(self.handle, name);
const i = c.FT_Get_Name_Index(self.handle, name.ptr);
return if (i == 0) null else i;
}
@ -146,7 +146,7 @@ pub fn getGlyphName(self: Face, index: u32, name_buf: *[30]u8) Error![]const u8
pub fn getPostscriptName(self: Face) ?[:0]const u8 {
return if (c.FT_Get_Postscript_Name(self.handle)) |face_name|
std.mem.span(face_name)
std.mem.span(@ptrCast([*:0]const u8, face_name))
else
null;
}
@ -185,21 +185,21 @@ pub fn getCharVariantIsDefault(self: Face, char: u32, variant_selector: u32) ?bo
pub fn getVariantSelectors(self: Face) ?[]u32 {
return if (c.FT_Face_GetVariantSelectors(self.handle)) |chars|
@ptrCast([]u32, std.mem.sliceTo(chars, 0))
@ptrCast([]u32, std.mem.sliceTo(@ptrCast([*:0]u32, chars), 0))
else
null;
}
pub fn getVariantsOfChar(self: Face, char: u32) ?[]u32 {
return if (c.FT_Face_GetVariantsOfChar(self.handle, char)) |variants|
@ptrCast([]u32, std.mem.sliceTo(variants, 0))
@ptrCast([]u32, std.mem.sliceTo(@ptrCast([*:0]u32, variants), 0))
else
null;
}
pub fn getCharsOfVariant(self: Face, variant_selector: u32) ?[]u32 {
return if (c.FT_Face_GetCharsOfVariant(self.handle, variant_selector)) |chars|
@ptrCast([]u32, std.mem.sliceTo(chars, 0))
@ptrCast([]u32, std.mem.sliceTo(@ptrCast([*:0]u32, chars), 0))
else
null;
}
@ -288,14 +288,14 @@ pub fn numGlyphs(self: Face) u32 {
pub fn familyName(self: Face) ?[:0]const u8 {
return if (self.handle.*.family_name) |family|
std.mem.span(family)
std.mem.span(@ptrCast([*:0]const u8, family))
else
null;
}
pub fn styleName(self: Face) ?[:0]const u8 {
return if (self.handle.*.style_name) |style_name|
std.mem.span(style_name)
std.mem.span(@ptrCast([*:0]const u8, style_name))
else
null;
}
@ -316,7 +316,7 @@ pub fn numCharmaps(self: Face) u32 {
}
pub fn charmaps(self: Face) []const CharMap {
return @ptrCast([]const CharMap, self.handle.*.charmaps[0..self.numCharmaps()]);
return @ptrCast([*]const CharMap, self.handle.*.charmaps)[0..self.numCharmaps()];
}
pub fn bbox(self: Face) BBox {

View file

@ -1,4 +1,5 @@
const c = @import("c");
const builtin = @import("builtin");
const intToError = @import("error.zig").intToError;
const errorToInt = @import("error.zig").errorToInt;
const Error = @import("error.zig").Error;
@ -46,10 +47,10 @@ pub fn bbox(self: Outline) Error!BBox {
pub fn Funcs(comptime Context: type) type {
return struct {
move_to: fn (ctx: Context, to: Vector) Error!void,
line_to: fn (ctx: Context, to: Vector) Error!void,
conic_to: fn (ctx: Context, control: Vector, to: Vector) Error!void,
cubic_to: fn (ctx: Context, control_0: Vector, control_1: Vector, to: Vector) Error!void,
move_to: if (builtin.zig_backend == .stage1 or builtin.zig_backend == .other) fn (ctx: Context, to: Vector) Error!void else *const fn (ctx: Context, to: Vector) Error!void,
line_to: if (builtin.zig_backend == .stage1 or builtin.zig_backend == .other) fn (ctx: Context, to: Vector) Error!void else *const fn (ctx: Context, to: Vector) Error!void,
conic_to: if (builtin.zig_backend == .stage1 or builtin.zig_backend == .other) fn (ctx: Context, control: Vector, to: Vector) Error!void else *const fn (ctx: Context, control: Vector, to: Vector) Error!void,
cubic_to: if (builtin.zig_backend == .stage1 or builtin.zig_backend == .other) fn (ctx: Context, control_0: Vector, control_1: Vector, to: Vector) Error!void else *const fn (ctx: Context, control_0: Vector, control_1: Vector, to: Vector) Error!void,
shift: i32,
delta: i32,
};
@ -121,7 +122,7 @@ pub fn decompose(self: Outline, ctx: anytype, callbacks: Funcs(@TypeOf(ctx))) Er
var wrapper = FuncsWrapper(@TypeOf(ctx)){ .ctx = ctx, .callbacks = callbacks };
try intToError(c.FT_Outline_Decompose(
self.handle,
&.{
&c.FT_Outline_Funcs{
.move_to = @TypeOf(wrapper).move_to,
.line_to = @TypeOf(wrapper).line_to,
.conic_to = @TypeOf(wrapper).conic_to,

View file

@ -333,7 +333,7 @@ pub const Buffer = struct {
pub fn getGlyphPositions(self: Buffer) ?[]Position {
return if (hb_buffer_get_glyph_positions(self.handle, null)) |positions|
positions[0..self.getLength()]
@ptrCast([*]Position, positions)[0..self.getLength()]
else
null;
}

View file

@ -13,7 +13,7 @@ pub const Direction = enum(u3) {
}
pub fn toString(self: Direction) [:0]const u8 {
return std.mem.span(c.hb_direction_to_string(@enumToInt(self)));
return std.mem.span(@ptrCast([*:0]const u8, c.hb_direction_to_string(@enumToInt(self))));
}
};
@ -210,7 +210,7 @@ pub const Language = struct {
}
pub fn toString(self: Language) [:0]const u8 {
return std.mem.span(c.hb_language_to_string(self.handle));
return std.mem.span(@ptrCast([*:0]const u8, c.hb_language_to_string(self.handle)));
}
pub fn getDefault() Language {

View file

@ -11,8 +11,9 @@ pub const ListShapers = struct {
pub fn next(self: *ListShapers) ?[:0]const u8 {
self.index += 1;
return std.mem.span(
return std.mem.span(@ptrCast(
?[*:0]const u8,
self.list[self.index - 1] orelse return null,
);
));
}
};

View file

@ -68,7 +68,7 @@ pub const ShapePlan = struct {
}
pub fn getShaper(self: ShapePlan) [:0]const u8 {
return std.mem.span(c.hb_shape_plan_get_shaper(self.handle));
return std.mem.span(@ptrCast([*:0]const u8, c.hb_shape_plan_get_shaper(self.handle)));
}
};