harfbuzz
This commit is contained in:
1 parent
5af49cfdbd
commit
12199ac7b6
5 files changed
+1333
-40
No files matched your search
+21
-10
@@ -1,7 +1,8 @@
|
||||
const std = @import("std");
|
||||
const rl = @import("raylib");
|
||||
const kb = @import("kb");
|
||||
const ft = @import("freetype");
|
||||
const ft = @import("mach-freetype");
|
||||
const hb = @import("mach-harfbuzz");
|
||||
const rp = @import("stb_rect_pack");
|
||||
const ztracy = @import("ztracy");
|
||||
|
||||
@@ -37,16 +38,22 @@ const Glyph = struct {
|
||||
pub const Font = struct {
|
||||
face : ft.Face,
|
||||
glyphs : std.AutoHashMap(u32, Glyph),
|
||||
kb : kb.kbts_font,
|
||||
kbts_font : kb.kbts_font,
|
||||
// texture : c.Texture2D,
|
||||
texture : rl.Texture2D,
|
||||
file_data : []u8,
|
||||
kb_file_data : []u8,
|
||||
|
||||
pub fn init(filename : []const u8, size : i32, allocator: std.mem.Allocator) !Font {
|
||||
|
||||
const file_data = try std.fs.cwd().readFileAlloc(
|
||||
allocator,
|
||||
filename,
|
||||
10 * 1024 * 1024
|
||||
);
|
||||
defer allocator.free(file_data);
|
||||
|
||||
const file_data = try std.fs.cwd().readFileAlloc(allocator, filename, 10 * 1024 * 1024);
|
||||
errdefer allocator.free(file_data);
|
||||
const kb_file_data = try allocator.dupe(u8, file_data);
|
||||
errdefer allocator.free(kb_file_data);
|
||||
|
||||
var face = try ft_lib.createFaceMemory(file_data, 0);
|
||||
var glyphs = std.AutoHashMap(u32, Glyph).init(allocator);
|
||||
@@ -161,18 +168,21 @@ pub const Font = struct {
|
||||
|
||||
const texture = try rl.loadTextureFromImage(atlas);
|
||||
|
||||
var _kb = kb.kbts_FontFromMemory(file_data.ptr, @intCast(file_data.len), 0, null, null);
|
||||
var kbts_font = kb.kbts_FontFromMemory(kb_file_data.ptr, @intCast(kb_file_data.len), 0, null, null);
|
||||
|
||||
if (kb.kbts_FontIsValid(&_kb) == 0) {
|
||||
if (kb.kbts_FontIsValid(&kbts_font) == 0) {
|
||||
std.log.info("[Error] [kb_text_shape] Failed to load the font.", .{});
|
||||
}
|
||||
|
||||
const hb_blob = hb.Blob.initFromFile(filename);
|
||||
_ = hb_blob;
|
||||
|
||||
return .{
|
||||
.face = face,
|
||||
.glyphs = glyphs,
|
||||
.kb = _kb,
|
||||
.kbts_font = kbts_font,
|
||||
.texture = texture,
|
||||
.file_data = file_data,
|
||||
.kb_file_data = kb_file_data,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -181,7 +191,7 @@ pub const Font = struct {
|
||||
self.face.deinit();
|
||||
kb.kbts_FreeFont(&self.kb);
|
||||
self.texture.unload();
|
||||
allocator.free(self.file_data);
|
||||
allocator.free(self.kb_file_data);
|
||||
}
|
||||
|
||||
pub fn render_text(
|
||||
@@ -226,6 +236,7 @@ pub const Font = struct {
|
||||
render_pos.y += dpi_font_ascent;
|
||||
|
||||
const Context = kb.kbts_CreateShapeContext(null, null);
|
||||
defer kb.kbts_DestroyShapeContext(Context);
|
||||
const kb_font = kb.kbts_ShapePushFont(Context, &self.kb);
|
||||
if (kb_font == null) {
|
||||
std.log.info("Could not open font!", .{});
|
||||
|
||||
+10
-10
@@ -3,7 +3,7 @@ const zm = @import("zmath");
|
||||
const znet = @import("znet");
|
||||
const rl = @import("raylib");
|
||||
const bufzilla = @import("bufzilla");
|
||||
const ft = @import("freetype");
|
||||
const ft = @import("mach-freetype");
|
||||
const ztracy = @import("ztracy");
|
||||
|
||||
const shared = @import("shared");
|
||||
@@ -237,15 +237,15 @@ pub fn main() !void {
|
||||
|
||||
// const lorem = @embedFile("embeds/lorem.txt");
|
||||
|
||||
// vollkorn[0].render_text(
|
||||
// lorem,
|
||||
// rl.Vector2{ .x = 0, .y = 0 },
|
||||
// true,
|
||||
// .white,
|
||||
// .blank,
|
||||
// false,
|
||||
// true
|
||||
// );
|
||||
vollkorn[0].render_text(
|
||||
"The night is long and cold outside.",
|
||||
rl.Vector2{ .x = 0, .y = 0 },
|
||||
true,
|
||||
.white,
|
||||
.blank,
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
arabic[0].render_text(
|
||||
"الليل طويل وبارد في الخارج",
|
||||
|
||||
Reference in new issue
Block a user