From f93e9eedb3830d4c5aa89903504aa8abe2b72c27 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 20 Aug 2022 10:50:37 -0700 Subject: [PATCH] font: move codepoint into a public API --- src/font/FallbackSet.zig | 3 ++- src/font/Family.zig | 12 +----------- src/font/main.zig | 13 +++++++++++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/font/FallbackSet.zig b/src/font/FallbackSet.zig index 57faf1fee..416f8fef5 100644 --- a/src/font/FallbackSet.zig +++ b/src/font/FallbackSet.zig @@ -12,6 +12,7 @@ const Atlas = @import("../Atlas.zig"); const Family = @import("main.zig").Family; const Glyph = @import("main.zig").Glyph; const Style = @import("main.zig").Style; +const codepoint = @import("main.zig").codepoint; const ftok = ftc.FT_Err_Ok; const log = std.log.scoped(.font_fallback); @@ -54,7 +55,7 @@ pub fn getOrAddGlyph( assert(self.families.items.len > 0); // We need a UTF32 codepoint - const utf32 = Family.codepoint(v); + const utf32 = codepoint(v); // If we have this already, load it directly const glyphKey: GlyphKey = .{ .style = style, .codepoint = utf32 }; diff --git a/src/font/Family.zig b/src/font/Family.zig index d1b00d223..f6c068078 100644 --- a/src/font/Family.zig +++ b/src/font/Family.zig @@ -11,6 +11,7 @@ const Face = @import("main.zig").Face; const Glyph = @import("main.zig").Glyph; const Style = @import("main.zig").Style; const testFont = @import("test.zig").fontRegular; +const codepoint = @import("main.zig").codepoint; 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; } -/// 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 { const testing = std.testing; const alloc = testing.allocator; diff --git a/src/font/main.zig b/src/font/main.zig index cfcd24f07..d7919da28 100644 --- a/src/font/main.zig +++ b/src/font/main.zig @@ -1,3 +1,5 @@ +const std = @import("std"); + pub const Face = @import("Face.zig"); pub const Family = @import("Family.zig"); pub const Glyph = @import("Glyph.zig"); @@ -15,6 +17,17 @@ pub const Style = enum { 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 { _ = Face; _ = Family;