Make fontChars optional in loadFontFromMemory (#153)

Fixed loadFontFromMemory and Font.fromMemory not allowing null for fontChars
This commit is contained in:
johan0A 2024-09-28 14:54:02 +02:00 committed by GitHub
parent d7d9e41863
commit 87e18ab398
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View File

@ -17,7 +17,7 @@ pub const RaylibError = error{
LoadFontData, LoadFontData,
LoadCodepoints, LoadCodepoints,
LoadMaterials, LoadMaterials,
LoadModelAnimations LoadModelAnimations,
}; };
pub const Vector2 = extern struct { 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' /// 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); 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' /// 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 fileDataFinal = @as([*c]const u8, 0);
var fileDataLen: i32 = 0; var fileDataLen: i32 = 0;
if (fileData) |fileDataSure| { if (fileData) |fileDataSure| {
fileDataFinal = @as([*c]const u8, @ptrCast(fileDataSure)); fileDataFinal = @as([*c]const u8, @ptrCast(fileDataSure));
fileDataLen = @as(i32, @intCast(fileDataSure.len)); 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 /// Load font data for further use

View File

@ -17,7 +17,7 @@ pub const RaylibError = error{
LoadFontData, LoadFontData,
LoadCodepoints, LoadCodepoints,
LoadMaterials, LoadMaterials,
LoadModelAnimations LoadModelAnimations,
}; };
pub const Vector2 = extern struct { 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' /// 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); 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' /// 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 fileDataFinal = @as([*c]const u8, 0);
var fileDataLen: i32 = 0; var fileDataLen: i32 = 0;
if (fileData) |fileDataSure| { if (fileData) |fileDataSure| {
fileDataFinal = @as([*c]const u8, @ptrCast(fileDataSure)); fileDataFinal = @as([*c]const u8, @ptrCast(fileDataSure));
fileDataLen = @as(i32, @intCast(fileDataSure.len)); 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 /// Load font data for further use