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", .{
|
const ztracy = b.dependency("ztracy", .{
|
||||||
.enable_ztracy = true,
|
.enable_ztracy = false,
|
||||||
.enable_fibers = false,
|
.enable_fibers = false,
|
||||||
.on_demand = false,
|
.on_demand = false,
|
||||||
});
|
});
|
||||||
client.root_module.addImport("ztracy", ztracy.module("root"));
|
client.root_module.addImport("ztracy", ztracy.module("root"));
|
||||||
client.linkLibrary(ztracy.artifact("tracy"));
|
client.linkLibrary(ztracy.artifact("tracy"));
|
||||||
|
|
||||||
const freetype_module = b.addModule("mach-freetype", .{
|
const mach_freetype = b.dependency("mach_freetype", .{
|
||||||
.root_source_file = b.path("vendor/mach-freetype/src/freetype.zig"),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (b.lazyDependency("freetype", .{
|
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.use_system_zlib = false,
|
});
|
||||||
.enable_brotli = false,
|
client.root_module.addImport("mach-freetype", mach_freetype.module("mach-freetype"));
|
||||||
})) |dep| {
|
client.root_module.addImport("mach-harfbuzz", mach_freetype.module("mach-harfbuzz"));
|
||||||
// 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.addCSourceFile(.{ .file = b.path("vendor/kb_text_shape/kb_text_shape.h"), .language = .c, .flags = &.{"-DKB_TEXT_SHAPE_IMPLEMENTATION"} });
|
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(.{
|
const kb_text_shape = b.addTranslateC(.{
|
||||||
|
|||||||
@ -52,14 +52,14 @@
|
|||||||
.url = "https://github.com/theseyan/bufzilla/archive/refs/tags/v0.3.2.tar.gz",
|
.url = "https://github.com/theseyan/bufzilla/archive/refs/tags/v0.3.2.tar.gz",
|
||||||
.hash = "bufzilla-0.3.0-gU6dXi67AQAg3WIFrNQ0iafrvexj3iBwVcczrVzrN3Ir",
|
.hash = "bufzilla-0.3.0-gU6dXi67AQAg3WIFrNQ0iafrvexj3iBwVcczrVzrN3Ir",
|
||||||
},
|
},
|
||||||
.freetype = .{
|
|
||||||
.url = "git+https://github.com/hexops/freetype#972cd37bccecae2cc9f54cf0b562263a13209d02",
|
|
||||||
.hash = "freetype-0.0.0-AAAAAA5JcwBMujojfNLEq5g_WijZtU56mRLYx8bjjiMU",
|
|
||||||
},
|
|
||||||
.ztracy = .{
|
.ztracy = .{
|
||||||
.url = "git+https://github.com/zig-gamedev/ztracy#d95d2a193b9f97944a17026c9a42b5d0f9a88c94",
|
.url = "git+https://github.com/zig-gamedev/ztracy#d95d2a193b9f97944a17026c9a42b5d0f9a88c94",
|
||||||
.hash = "ztracy-0.14.0-dev-zHJSqzUHGQAmhJybhlwtl1QKevUBw4M5YKZqPfWx2y99",
|
.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 = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const rl = @import("raylib");
|
const rl = @import("raylib");
|
||||||
const kb = @import("kb");
|
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 rp = @import("stb_rect_pack");
|
||||||
const ztracy = @import("ztracy");
|
const ztracy = @import("ztracy");
|
||||||
|
|
||||||
@ -37,16 +38,22 @@ const Glyph = struct {
|
|||||||
pub const Font = struct {
|
pub const Font = struct {
|
||||||
face : ft.Face,
|
face : ft.Face,
|
||||||
glyphs : std.AutoHashMap(u32, Glyph),
|
glyphs : std.AutoHashMap(u32, Glyph),
|
||||||
kb : kb.kbts_font,
|
kbts_font : kb.kbts_font,
|
||||||
// texture : c.Texture2D,
|
// texture : c.Texture2D,
|
||||||
texture : rl.Texture2D,
|
texture : rl.Texture2D,
|
||||||
file_data : []u8,
|
kb_file_data : []u8,
|
||||||
|
|
||||||
pub fn init(filename : []const u8, size : i32, allocator: std.mem.Allocator) !Font {
|
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);
|
const kb_file_data = try allocator.dupe(u8, file_data);
|
||||||
errdefer allocator.free(file_data);
|
errdefer allocator.free(kb_file_data);
|
||||||
|
|
||||||
var face = try ft_lib.createFaceMemory(file_data, 0);
|
var face = try ft_lib.createFaceMemory(file_data, 0);
|
||||||
var glyphs = std.AutoHashMap(u32, Glyph).init(allocator);
|
var glyphs = std.AutoHashMap(u32, Glyph).init(allocator);
|
||||||
@ -161,18 +168,21 @@ pub const Font = struct {
|
|||||||
|
|
||||||
const texture = try rl.loadTextureFromImage(atlas);
|
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.", .{});
|
std.log.info("[Error] [kb_text_shape] Failed to load the font.", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hb_blob = hb.Blob.initFromFile(filename);
|
||||||
|
_ = hb_blob;
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.face = face,
|
.face = face,
|
||||||
.glyphs = glyphs,
|
.glyphs = glyphs,
|
||||||
.kb = _kb,
|
.kbts_font = kbts_font,
|
||||||
.texture = texture,
|
.texture = texture,
|
||||||
.file_data = file_data,
|
.kb_file_data = kb_file_data,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +191,7 @@ pub const Font = struct {
|
|||||||
self.face.deinit();
|
self.face.deinit();
|
||||||
kb.kbts_FreeFont(&self.kb);
|
kb.kbts_FreeFont(&self.kb);
|
||||||
self.texture.unload();
|
self.texture.unload();
|
||||||
allocator.free(self.file_data);
|
allocator.free(self.kb_file_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_text(
|
pub fn render_text(
|
||||||
@ -226,6 +236,7 @@ pub const Font = struct {
|
|||||||
render_pos.y += dpi_font_ascent;
|
render_pos.y += dpi_font_ascent;
|
||||||
|
|
||||||
const Context = kb.kbts_CreateShapeContext(null, null);
|
const Context = kb.kbts_CreateShapeContext(null, null);
|
||||||
|
defer kb.kbts_DestroyShapeContext(Context);
|
||||||
const kb_font = kb.kbts_ShapePushFont(Context, &self.kb);
|
const kb_font = kb.kbts_ShapePushFont(Context, &self.kb);
|
||||||
if (kb_font == null) {
|
if (kb_font == null) {
|
||||||
std.log.info("Could not open font!", .{});
|
std.log.info("Could not open font!", .{});
|
||||||
|
|||||||
@ -3,7 +3,7 @@ const zm = @import("zmath");
|
|||||||
const znet = @import("znet");
|
const znet = @import("znet");
|
||||||
const rl = @import("raylib");
|
const rl = @import("raylib");
|
||||||
const bufzilla = @import("bufzilla");
|
const bufzilla = @import("bufzilla");
|
||||||
const ft = @import("freetype");
|
const ft = @import("mach-freetype");
|
||||||
const ztracy = @import("ztracy");
|
const ztracy = @import("ztracy");
|
||||||
|
|
||||||
const shared = @import("shared");
|
const shared = @import("shared");
|
||||||
@ -237,15 +237,15 @@ pub fn main() !void {
|
|||||||
|
|
||||||
// const lorem = @embedFile("embeds/lorem.txt");
|
// const lorem = @embedFile("embeds/lorem.txt");
|
||||||
|
|
||||||
// vollkorn[0].render_text(
|
vollkorn[0].render_text(
|
||||||
// lorem,
|
"The night is long and cold outside.",
|
||||||
// rl.Vector2{ .x = 0, .y = 0 },
|
rl.Vector2{ .x = 0, .y = 0 },
|
||||||
// true,
|
true,
|
||||||
// .white,
|
.white,
|
||||||
// .blank,
|
.blank,
|
||||||
// false,
|
false,
|
||||||
// true
|
true
|
||||||
// );
|
);
|
||||||
|
|
||||||
arabic[0].render_text(
|
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