Make codepoints in loadFontData optional (#263)

This commit is contained in:
Nikolas 2025-08-03 13:56:43 +02:00
parent 22bb251252
commit 3eee232f10
No known key found for this signature in database
GPG Key ID: E95F679E3CDD9784
3 changed files with 26 additions and 8 deletions

View File

@ -2192,14 +2192,23 @@ pub fn loadFontFromImage(image: Image, key: Color, firstChar: i32) RaylibError!F
}
/// Load font data for further use
pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: FontType) RaylibError![]GlyphInfo {
pub fn loadFontData(fileData: []const u8, fontSize: i32, codePoints: ?[]i32, ty: FontType) RaylibError![]GlyphInfo {
var res: []GlyphInfo = undefined;
const ptr = cdef.LoadFontData(@as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len)), ty);
var codePointsFinal = @as([*c]i32, 0);
var codePointsLen: i32 = 0;
if (codePoints) |codePointsSure| {
codePointsFinal = @as([*c]i32, @ptrCast(codePointsSure));
codePointsLen = @as(i32, @intCast(codePointsSure.len));
} else {
codePointsLen = 95;
}
const ptr = cdef.LoadFontData(@as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as(c_int, fontSize), codePointsFinal, @as(c_int, @intCast(codePointsLen)), ty);
if (ptr == 0) return RaylibError.LoadFontData;
res.ptr = @as([*]GlyphInfo, @ptrCast(ptr));
res.len = @as(usize, @intCast(fontChars.len));
res.len = @as(usize, @intCast(codePointsLen));
return res;
}

View File

@ -2192,14 +2192,23 @@ pub fn loadFontFromImage(image: Image, key: Color, firstChar: i32) RaylibError!F
}
/// Load font data for further use
pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: FontType) RaylibError![]GlyphInfo {
pub fn loadFontData(fileData: []const u8, fontSize: i32, codePoints: ?[]i32, ty: FontType) RaylibError![]GlyphInfo {
var res: []GlyphInfo = undefined;
const ptr = cdef.LoadFontData(@as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len)), ty);
var codePointsFinal = @as([*c]i32, 0);
var codePointsLen: i32 = 0;
if (codePoints) |codePointsSure| {
codePointsFinal = @as([*c]i32, @ptrCast(codePointsSure));
codePointsLen = @as(i32, @intCast(codePointsSure.len));
} else {
codePointsLen = 95;
}
const ptr = cdef.LoadFontData(@as([*c]const u8, @ptrCast(fileData)), @as(c_int, @intCast(fileData.len)), @as(c_int, fontSize), codePointsFinal, @as(c_int, @intCast(codePointsLen)), ty);
if (ptr == 0) return RaylibError.LoadFontData;
res.ptr = @as([*]GlyphInfo, @ptrCast(ptr));
res.len = @as(usize, @intCast(fontChars.len));
res.len = @as(usize, @intCast(codePointsLen));
return res;
}

View File

@ -192,8 +192,8 @@ pub const rl_default_batch_drawcalls = @as(i32, 256);
pub const rl_default_batch_max_texture_units = @as(i32, 4);
pub const rl_max_matrix_stack_size = @as(i32, 32);
pub const rl_max_shader_locations = @as(i32, 32);
pub const rl_cull_distance_near = @as(f64, 0.01);
pub const rl_cull_distance_far = @as(f64, 1000.0);
pub const rl_cull_distance_near = @as(f64, 0.05);
pub const rl_cull_distance_far = @as(f64, 4000.0);
pub const rl_texture_wrap_s = @as(i32, 0x2802);
pub const rl_texture_wrap_t = @as(i32, 0x2803);
pub const rl_texture_mag_filter = @as(i32, 0x2800);