mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
font: move codepoint into a public API
This commit is contained in:
@ -12,6 +12,7 @@ const Atlas = @import("../Atlas.zig");
|
|||||||
const Family = @import("main.zig").Family;
|
const Family = @import("main.zig").Family;
|
||||||
const Glyph = @import("main.zig").Glyph;
|
const Glyph = @import("main.zig").Glyph;
|
||||||
const Style = @import("main.zig").Style;
|
const Style = @import("main.zig").Style;
|
||||||
|
const codepoint = @import("main.zig").codepoint;
|
||||||
|
|
||||||
const ftok = ftc.FT_Err_Ok;
|
const ftok = ftc.FT_Err_Ok;
|
||||||
const log = std.log.scoped(.font_fallback);
|
const log = std.log.scoped(.font_fallback);
|
||||||
@ -54,7 +55,7 @@ pub fn getOrAddGlyph(
|
|||||||
assert(self.families.items.len > 0);
|
assert(self.families.items.len > 0);
|
||||||
|
|
||||||
// We need a UTF32 codepoint
|
// We need a UTF32 codepoint
|
||||||
const utf32 = Family.codepoint(v);
|
const utf32 = codepoint(v);
|
||||||
|
|
||||||
// If we have this already, load it directly
|
// If we have this already, load it directly
|
||||||
const glyphKey: GlyphKey = .{ .style = style, .codepoint = utf32 };
|
const glyphKey: GlyphKey = .{ .style = style, .codepoint = utf32 };
|
||||||
|
@ -11,6 +11,7 @@ const Face = @import("main.zig").Face;
|
|||||||
const Glyph = @import("main.zig").Glyph;
|
const Glyph = @import("main.zig").Glyph;
|
||||||
const Style = @import("main.zig").Style;
|
const Style = @import("main.zig").Style;
|
||||||
const testFont = @import("test.zig").fontRegular;
|
const testFont = @import("test.zig").fontRegular;
|
||||||
|
const codepoint = @import("main.zig").codepoint;
|
||||||
|
|
||||||
const log = std.log.scoped(.font_family);
|
const log = std.log.scoped(.font_family);
|
||||||
|
|
||||||
@ -141,17 +142,6 @@ pub fn addGlyph(self: *Family, alloc: Allocator, v: anytype, style: Style) !*Gly
|
|||||||
return gop.value_ptr;
|
return gop.value_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the UTF-32 codepoint for the given value.
|
|
||||||
pub fn codepoint(v: anytype) u32 {
|
|
||||||
// We need a UTF32 codepoint for freetype
|
|
||||||
return switch (@TypeOf(v)) {
|
|
||||||
u32 => v,
|
|
||||||
comptime_int, u8 => @intCast(u32, v),
|
|
||||||
[]const u8 => @intCast(u32, try std.unicode.utfDecode(v)),
|
|
||||||
else => @compileError("invalid codepoint type"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
test {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
pub const Face = @import("Face.zig");
|
pub const Face = @import("Face.zig");
|
||||||
pub const Family = @import("Family.zig");
|
pub const Family = @import("Family.zig");
|
||||||
pub const Glyph = @import("Glyph.zig");
|
pub const Glyph = @import("Glyph.zig");
|
||||||
@ -15,6 +17,17 @@ pub const Style = enum {
|
|||||||
bold_italic,
|
bold_italic,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Returns the UTF-32 codepoint for the given value.
|
||||||
|
pub fn codepoint(v: anytype) u32 {
|
||||||
|
// We need a UTF32 codepoint for freetype
|
||||||
|
return switch (@TypeOf(v)) {
|
||||||
|
u32 => v,
|
||||||
|
comptime_int, u8 => @intCast(u32, v),
|
||||||
|
[]const u8 => @intCast(u32, try std.unicode.utfDecode(v)),
|
||||||
|
else => @compileError("invalid codepoint type"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
_ = Face;
|
_ = Face;
|
||||||
_ = Family;
|
_ = Family;
|
||||||
|
Reference in New Issue
Block a user