diff --git a/src/client/font.zig b/src/client/font.zig index aa208af..75ce75b 100644 --- a/src/client/font.zig +++ b/src/client/font.zig @@ -95,8 +95,8 @@ pub const Font = struct { try rects.append(allocator, .{ .id = @intCast(index),//@intCast(face.glyph().glyphIndex()), - .w = @intCast(bmp.width()), - .h = @intCast(bmp.rows()), + .w = @max(1, @as(c_int, @intCast(bmp.width()))), + .h = @max(1, @as(c_int, @intCast(bmp.rows()))), .x = 0, .y = 0, .was_packed = 0, @@ -111,7 +111,6 @@ pub const Font = struct { try face.loadGlyph(index, .{ .render = true }); const bmp = face.glyph().bitmap(); - const buf = bmp.buffer() orelse continue; const pitch: usize = @intCast(bmp.pitch()); const w: usize = @intCast(bmp.width()); @@ -120,13 +119,15 @@ pub const Font = struct { const dst_x: usize = @intCast(rect.x); const dst_y: usize = @intCast(rect.y); - for (0..h) |y| { - const src = buf[y * pitch .. y * pitch + w]; + if (bmp.buffer()) |buf| { + for (0..h) |y| { + const src = buf[y * pitch .. y * pitch + w]; - const dst_index = (dst_y + y) * ATLAS_SIZE + dst_x; - const dst = _atlas[dst_index .. dst_index + w]; + const dst_index = (dst_y + y) * ATLAS_SIZE + dst_x; + const dst = _atlas[dst_index .. dst_index + w]; - @memcpy(dst, src); + @memcpy(dst, src); + } } // std.log.info("{}", .{bmp.width()}); @@ -374,7 +375,8 @@ pub const Font = struct { // rl.gl.rlTexCoord2f(st1.x, st1.y); rl.gl.rlVertex2f(p1.x, p1.y); // rl.gl.rlTexCoord2f(st1.x, st0.y); rl.gl.rlVertex2f(p1.x, p0.y); } else { - std.log.warn("kb_text_shape found the glyph, but we didn't load it from the font.", .{}); + std.log.warn("kb_text_shape found the glyph, but we didn't load it from the font. index {}", .{RunGlyph.Id}); + std.log.warn("advance_x {}", .{advance_x}); x_offset += dpi_advance_x; y_offset += dpi_advance_y; continue;