mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-08 19:47:28 +00:00
Make fontChars optional in loadFontFromMemory (#153)
Fixed loadFontFromMemory and Font.fromMemory not allowing null for fontChars
This commit is contained in:
parent
d7d9e41863
commit
87e18ab398
@ -17,7 +17,7 @@ pub const RaylibError = error{
|
||||
LoadFontData,
|
||||
LoadCodepoints,
|
||||
LoadMaterials,
|
||||
LoadModelAnimations
|
||||
LoadModelAnimations,
|
||||
};
|
||||
|
||||
pub const Vector2 = extern struct {
|
||||
@ -1292,7 +1292,7 @@ pub const Font = extern struct {
|
||||
}
|
||||
|
||||
/// Load font from memory buffer, fileType refers to extension: i.e. '.ttf'
|
||||
pub fn fromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font {
|
||||
pub fn fromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: ?[]i32) Font {
|
||||
return rl.loadFontFromMemory(fileType, fileData, fontSize, fontChars);
|
||||
}
|
||||
|
||||
@ -2107,14 +2107,15 @@ pub fn loadFontEx(fileName: [*:0]const u8, fontSize: i32, fontChars: ?[]i32) Fon
|
||||
}
|
||||
|
||||
/// Load font from memory buffer, fileType refers to extension: i.e. '.ttf'
|
||||
pub fn loadFontFromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font {
|
||||
pub fn loadFontFromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: ?[]i32) Font {
|
||||
var fileDataFinal = @as([*c]const u8, 0);
|
||||
var fileDataLen: i32 = 0;
|
||||
if (fileData) |fileDataSure| {
|
||||
fileDataFinal = @as([*c]const u8, @ptrCast(fileDataSure));
|
||||
fileDataLen = @as(i32, @intCast(fileDataSure.len));
|
||||
}
|
||||
return cdef.LoadFontFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileDataFinal)), @as(c_int, @intCast(fileDataLen)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len)));
|
||||
const codepointCount: c_int = if (fontChars) |fontCharsSure| @intCast(fontCharsSure.len) else 0;
|
||||
return cdef.LoadFontFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileDataFinal)), @as(c_int, @intCast(fileDataLen)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), codepointCount);
|
||||
}
|
||||
|
||||
/// Load font data for further use
|
||||
|
@ -17,7 +17,7 @@ pub const RaylibError = error{
|
||||
LoadFontData,
|
||||
LoadCodepoints,
|
||||
LoadMaterials,
|
||||
LoadModelAnimations
|
||||
LoadModelAnimations,
|
||||
};
|
||||
|
||||
pub const Vector2 = extern struct {
|
||||
@ -1292,7 +1292,7 @@ pub const Font = extern struct {
|
||||
}
|
||||
|
||||
/// Load font from memory buffer, fileType refers to extension: i.e. '.ttf'
|
||||
pub fn fromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font {
|
||||
pub fn fromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: ?[]i32) Font {
|
||||
return rl.loadFontFromMemory(fileType, fileData, fontSize, fontChars);
|
||||
}
|
||||
|
||||
@ -2107,14 +2107,15 @@ pub fn loadFontEx(fileName: [*:0]const u8, fontSize: i32, fontChars: ?[]i32) Fon
|
||||
}
|
||||
|
||||
/// Load font from memory buffer, fileType refers to extension: i.e. '.ttf'
|
||||
pub fn loadFontFromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font {
|
||||
pub fn loadFontFromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: ?[]i32) Font {
|
||||
var fileDataFinal = @as([*c]const u8, 0);
|
||||
var fileDataLen: i32 = 0;
|
||||
if (fileData) |fileDataSure| {
|
||||
fileDataFinal = @as([*c]const u8, @ptrCast(fileDataSure));
|
||||
fileDataLen = @as(i32, @intCast(fileDataSure.len));
|
||||
}
|
||||
return cdef.LoadFontFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileDataFinal)), @as(c_int, @intCast(fileDataLen)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len)));
|
||||
const codepointCount: c_int = if (fontChars) |fontCharsSure| @intCast(fontCharsSure.len) else 0;
|
||||
return cdef.LoadFontFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileDataFinal)), @as(c_int, @intCast(fileDataLen)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), codepointCount);
|
||||
}
|
||||
|
||||
/// Load font data for further use
|
||||
|
Loading…
x
Reference in New Issue
Block a user