Use FT_New_Memory_Face for freetype fonts to fix loading non-ascii paths on Windows

This commit is contained in:
Nikita Lisitsa 2025-03-04 19:59:38 +03:00
parent d41c53193d
commit 2e28b3ffc6

View file

@ -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<font_builder> 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<freetype_font_builder>(std::make_shared<face_shared>(device, face));
FT_Face face;
ft_check_result(FT_New_Memory_Face(ft_library(), reinterpret_cast<FT_Byte const *>(font_data.data()), font_data.size(), 0, &face), util::to_string("Failed to load font ", path, ": "));
auto result = std::make_unique<freetype_font_builder>(std::make_shared<face_shared>(std::move(font_data), device, face));
log::debug() << "Loaded font " << result->name() << " (" << path << ")";