From 2e28b3ffc6f4e98cb7a5d73d15414dcc7a8c4d0a Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 4 Mar 2025 19:59:38 +0300 Subject: [PATCH] Use FT_New_Memory_Face for freetype fonts to fix loading non-ascii paths on Windows --- libs/fonts/source/freetype.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/fonts/source/freetype.cpp b/libs/fonts/source/freetype.cpp index 615c3cde..f27dead1 100644 --- a/libs/fonts/source/freetype.cpp +++ b/libs/fonts/source/freetype.cpp @@ -71,6 +71,7 @@ namespace psemek::fonts struct face_shared { + util::blob data; wgpu::device device; FT_Face face; @@ -333,11 +334,12 @@ namespace psemek::fonts std::unique_ptr load_freetype_font(wgpu::device device, std::filesystem::path const & path) { - FT_Face face; - auto path_str = path.string(); - ft_check_result(FT_New_Face(ft_library(), path_str.data(), 0, &face), "Failed to load font " + path_str + ": "); + auto font_data = io::read_full(io::file_istream{path}); - auto result = std::make_unique(std::make_shared(device, face)); + FT_Face face; + ft_check_result(FT_New_Memory_Face(ft_library(), reinterpret_cast(font_data.data()), font_data.size(), 0, &face), util::to_string("Failed to load font ", path, ": ")); + + auto result = std::make_unique(std::make_shared(std::move(font_data), device, face)); log::debug() << "Loaded font " << result->name() << " (" << path << ")";