Merge pull request #64 from seppelin/devel

add default fontChars support
This commit is contained in:
Nikolas 2024-01-17 20:52:58 +01:00 committed by GitHub
commit 54c298fe24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -542,7 +542,7 @@ pub const Font = extern struct {
return rl.loadFontFromImage(image, key, firstChar); return rl.loadFontFromImage(image, key, firstChar);
} }
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);
} }
@ -1281,14 +1281,20 @@ pub fn loadImagePalette(image: Image, maxPaletteSize: i32) []Color {
return res; return res;
} }
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: [*c]const u8 = 0;
var fileDataLen: i32 = 0; var fileDataLen: c_int = undefined;
if (fileData) |fileDataSure| { if (fileData) |fileDataSure| {
fileDataFinal = @as([*c]const u8, @ptrCast(fileDataSure)); fileDataFinal = @ptrCast(fileDataSure);
fileDataLen = @as(i32, @intCast(fileDataSure.len)); fileDataLen = @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))); var fontCharsFinal: [*c]c_int = 0;
var fontCharsLen: c_int = undefined;
if (fontChars) |fontCharsSure| {
fontCharsFinal = @ptrCast(fontCharsSure);
fontCharsLen = @intCast(fontCharsSure.len);
}
return cdef.LoadFontFromMemory(@ptrCast(fileType), fileDataFinal, fileDataLen, fontSize, fontCharsFinal, fontCharsLen);
} }
pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: i32) []GlyphInfo { pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: i32) []GlyphInfo {