harfbuzz
This commit is contained in:
parent
5af49cfdbd
commit
12199ac7b6
21
build.zig
21
build.zig
@ -82,30 +82,19 @@ pub fn build(b: *std.Build) void {
|
||||
});
|
||||
|
||||
const ztracy = b.dependency("ztracy", .{
|
||||
.enable_ztracy = true,
|
||||
.enable_ztracy = false,
|
||||
.enable_fibers = false,
|
||||
.on_demand = false,
|
||||
});
|
||||
client.root_module.addImport("ztracy", ztracy.module("root"));
|
||||
client.linkLibrary(ztracy.artifact("tracy"));
|
||||
|
||||
const freetype_module = b.addModule("mach-freetype", .{
|
||||
.root_source_file = b.path("vendor/mach-freetype/src/freetype.zig"),
|
||||
});
|
||||
|
||||
if (b.lazyDependency("freetype", .{
|
||||
const mach_freetype = b.dependency("mach_freetype", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.use_system_zlib = false,
|
||||
.enable_brotli = false,
|
||||
})) |dep| {
|
||||
// freetype_tests.root_module.linkLibrary(dep.artifact("freetype"));
|
||||
freetype_module.linkLibrary(dep.artifact("freetype"));
|
||||
// harfbuzz_module.linkLibrary(dep.artifact("freetype"));
|
||||
// harfbuzz_tests.root_module.linkLibrary(dep.artifact("freetype"));
|
||||
}
|
||||
|
||||
client.root_module.addImport("freetype", freetype_module);
|
||||
});
|
||||
client.root_module.addImport("mach-freetype", mach_freetype.module("mach-freetype"));
|
||||
client.root_module.addImport("mach-harfbuzz", mach_freetype.module("mach-harfbuzz"));
|
||||
|
||||
client.root_module.addCSourceFile(.{ .file = b.path("vendor/kb_text_shape/kb_text_shape.h"), .language = .c, .flags = &.{"-DKB_TEXT_SHAPE_IMPLEMENTATION"} });
|
||||
const kb_text_shape = b.addTranslateC(.{
|
||||
|
||||
@ -52,14 +52,14 @@
|
||||
.url = "https://github.com/theseyan/bufzilla/archive/refs/tags/v0.3.2.tar.gz",
|
||||
.hash = "bufzilla-0.3.0-gU6dXi67AQAg3WIFrNQ0iafrvexj3iBwVcczrVzrN3Ir",
|
||||
},
|
||||
.freetype = .{
|
||||
.url = "git+https://github.com/hexops/freetype#972cd37bccecae2cc9f54cf0b562263a13209d02",
|
||||
.hash = "freetype-0.0.0-AAAAAA5JcwBMujojfNLEq5g_WijZtU56mRLYx8bjjiMU",
|
||||
},
|
||||
.ztracy = .{
|
||||
.url = "git+https://github.com/zig-gamedev/ztracy#d95d2a193b9f97944a17026c9a42b5d0f9a88c94",
|
||||
.hash = "ztracy-0.14.0-dev-zHJSqzUHGQAmhJybhlwtl1QKevUBw4M5YKZqPfWx2y99",
|
||||
},
|
||||
.mach_freetype = .{
|
||||
.url = "git+https://github.com/hexops/mach-freetype#44f481e3435592810a7c55fc2f37e470dcba2a9c",
|
||||
.hash = "mach_freetype-0.0.0-AAAAAG4nCAANuVIO0Lmyh-H-eN2d60k-xlxIW_Xv90jq",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
"build.zig",
|
||||
|
||||
@ -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!", .{});
|
||||
|
||||
@ -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(
|
||||
"الليل طويل وبارد في الخارج",
|
||||
|
||||
1293
vendor/mach-freetype/src/harfbuzz.zig
vendored
Normal file
1293
vendor/mach-freetype/src/harfbuzz.zig
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user