freetype: fix type for C string args
Propagate the correct string type required by Freetype to the Zig layer. Previously, passing non zero-terminated strings caused runtime errors.
This commit is contained in:
parent
959c20d38b
commit
762a2074ee
4 changed files with 7 additions and 5 deletions
|
|
@ -58,7 +58,7 @@ pub fn deinit(self: Face) void {
|
||||||
_ = c.FT_Done_Face(self.handle);
|
_ = c.FT_Done_Face(self.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn attachFile(self: Face, path: []const u8) Error!void {
|
pub fn attachFile(self: Face, path: [*:0]const u8) Error!void {
|
||||||
return self.attachStream(.{
|
return self.attachStream(.{
|
||||||
.flags = .{ .path = true },
|
.flags = .{ .path = true },
|
||||||
.data = .{ .path = path },
|
.data = .{ .path = path },
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ pub fn deinit(self: Library) void {
|
||||||
_ = c.FT_Done_FreeType(self.handle);
|
_ = c.FT_Done_FreeType(self.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createFace(self: Library, path: []const u8, face_index: i32) Error!Face {
|
pub fn createFace(self: Library, path: [*:0]const u8, face_index: i32) Error!Face {
|
||||||
return self.openFace(.{
|
return self.openFace(.{
|
||||||
.flags = .{ .path = true },
|
.flags = .{ .path = true },
|
||||||
.data = .{ .path = path },
|
.data = .{ .path = path },
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ pub const OpenArgs = struct {
|
||||||
flags: OpenFlags,
|
flags: OpenFlags,
|
||||||
data: union(enum) {
|
data: union(enum) {
|
||||||
memory: []const u8,
|
memory: []const u8,
|
||||||
path: []const u8,
|
path: [*:0]const u8,
|
||||||
stream: c.FT_Stream,
|
stream: c.FT_Stream,
|
||||||
driver: c.FT_Module,
|
driver: c.FT_Module,
|
||||||
params: []const c.FT_Parameter,
|
params: []const c.FT_Parameter,
|
||||||
|
|
@ -173,7 +173,9 @@ pub const OpenArgs = struct {
|
||||||
oa.memory_base = d.ptr;
|
oa.memory_base = d.ptr;
|
||||||
oa.memory_size = @intCast(u31, d.len);
|
oa.memory_size = @intCast(u31, d.len);
|
||||||
},
|
},
|
||||||
.path => |*d| oa.pathname = @intToPtr(*u8, @ptrToInt(d.ptr)),
|
// The Freetype API requires a mutable string.
|
||||||
|
// This is an oversight, Freetype actually never writes to this string.
|
||||||
|
.path => |d| oa.pathname = @constCast(d),
|
||||||
.stream => |d| oa.stream = d,
|
.stream => |d| oa.stream = d,
|
||||||
.driver => |d| oa.driver = d,
|
.driver => |d| oa.driver = d,
|
||||||
.params => |*d| {
|
.params => |*d| {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ const std = @import("std");
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const ft = @import("freetype.zig");
|
const ft = @import("freetype.zig");
|
||||||
|
|
||||||
fn sdkPath(comptime suffix: []const u8) []const u8 {
|
fn sdkPath(comptime suffix: [*:0]const u8) [*:0]const u8 {
|
||||||
if (suffix[0] != '/') @compileError("suffix must be an absolute path");
|
if (suffix[0] != '/') @compileError("suffix must be an absolute path");
|
||||||
return comptime blk: {
|
return comptime blk: {
|
||||||
const root_dir = std.fs.path.dirname(@src().file) orelse ".";
|
const root_dir = std.fs.path.dirname(@src().file) orelse ".";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue