Fix issues with slices in font loading functions (#47)

This commit is contained in:
Not-Nik 2023-07-18 12:20:01 +02:00
parent 4bb6b605e4
commit c08e5f51c2
No known key found for this signature in database
GPG Key ID: 08BB71E672DB3BFD
3 changed files with 23 additions and 11 deletions

View File

@ -238,7 +238,7 @@ def parse_header(header_name: str, output_file: str, ext_file: str, prefix: str,
zig_arguments = ", ".join(zig_arguments) zig_arguments = ", ".join(zig_arguments)
zig_call_args = ", ".join(zig_call_args) zig_call_args = ", ".join(zig_call_args)
if func_name in ["TextFormat", "LoadShader", "LoadShaderFromMemory"]: if func_name in ["TextFormat", "LoadShader", "LoadShaderFromMemory", "LoadFontFromMemory"]:
continue continue
zig_return = ziggify_type(func_name, return_type) zig_return = ziggify_type(func_name, return_type)

View File

@ -958,10 +958,18 @@ pub fn loadImagePalette(image: Image, maxPaletteSize: i32) []Color {
return res; return res;
} }
pub fn loadFontData(fileData: []const u8, dataSize: i32, fontSize: i32, fontChars: []i32, glyphCount: i32, ty: i32) []GlyphInfo { pub fn loadFontFromMemory(fileType: []const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font {
var fileDataFinal = @as([*c]const u8, 0);
if (fileData) |fileDataSure| {
fileDataFinal = @ptrCast([*c]const u8, fileDataSure);
}
return cdef.LoadFontFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileDataFinal), @as(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, fontChars.len));
}
pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: i32) []GlyphInfo {
var res: []GlyphInfo = undefined; var res: []GlyphInfo = undefined;
res.ptr = @ptrCast([*]GlyphInfo, cdef.LoadFontData(@ptrCast([*c]const u8, fileData), @as(c_int, dataSize), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, glyphCount), @as(c_int, ty))); res.ptr = @ptrCast([*]GlyphInfo, cdef.LoadFontData(@ptrCast([*c]const u8, fileData), @as(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, fontChars.len), @as(c_int, ty)));
res.len = @intCast(usize, glyphCount); res.len = @intCast(usize, fontChars.len);
return res; return res;
} }

View File

@ -958,10 +958,18 @@ pub fn loadImagePalette(image: Image, maxPaletteSize: i32) []Color {
return res; return res;
} }
pub fn loadFontData(fileData: []const u8, dataSize: i32, fontSize: i32, fontChars: []i32, glyphCount: i32, ty: i32) []GlyphInfo { pub fn loadFontFromMemory(fileType: []const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font {
var fileDataFinal = @as([*c]const u8, 0);
if (fileData) |fileDataSure| {
fileDataFinal = @ptrCast([*c]const u8, fileDataSure);
}
return cdef.LoadFontFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileDataFinal), @as(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, fontChars.len));
}
pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: i32) []GlyphInfo {
var res: []GlyphInfo = undefined; var res: []GlyphInfo = undefined;
res.ptr = @ptrCast([*]GlyphInfo, cdef.LoadFontData(@ptrCast([*c]const u8, fileData), @as(c_int, dataSize), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, glyphCount), @as(c_int, ty))); res.ptr = @ptrCast([*]GlyphInfo, cdef.LoadFontData(@ptrCast([*c]const u8, fileData), @as(c_int, fileData.len), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, fontChars.len), @as(c_int, ty)));
res.len = @intCast(usize, glyphCount); res.len = @intCast(usize, fontChars.len);
return res; return res;
} }
@ -2343,10 +2351,6 @@ pub fn loadFontFromImage(image: Image, key: Color, firstChar: i32) Font {
return cdef.LoadFontFromImage(image, key, @as(c_int, firstChar)); return cdef.LoadFontFromImage(image, key, @as(c_int, firstChar));
} }
pub fn loadFontFromMemory(fileType: []const u8, fileData: []const u8, dataSize: i32, fontSize: i32, fontChars: []i32, glyphCount: i32) Font {
return cdef.LoadFontFromMemory(@ptrCast([*c]const u8, fileType), @ptrCast([*c]const u8, fileData), @as(c_int, dataSize), @as(c_int, fontSize), @ptrCast([*c]c_int, fontChars), @as(c_int, glyphCount));
}
pub fn genImageFontAtlas(chars: []const GlyphInfo, recs: [][]Rectangle, glyphCount: i32, fontSize: i32, padding: i32, packMethod: i32) Image { pub fn genImageFontAtlas(chars: []const GlyphInfo, recs: [][]Rectangle, glyphCount: i32, fontSize: i32, padding: i32, packMethod: i32) Image {
return cdef.GenImageFontAtlas(@ptrCast([*c]const GlyphInfo, chars), @ptrCast([*c][*c]Rectangle, recs), @as(c_int, glyphCount), @as(c_int, fontSize), @as(c_int, padding), @as(c_int, packMethod)); return cdef.GenImageFontAtlas(@ptrCast([*c]const GlyphInfo, chars), @ptrCast([*c][*c]Rectangle, recs), @as(c_int, glyphCount), @as(c_int, fontSize), @as(c_int, padding), @as(c_int, packMethod));
} }