From b0de5970ce804767da476256efa7f534f0908e1d Mon Sep 17 00:00:00 2001 From: oltolm Date: Sat, 13 May 2023 20:58:59 +0200 Subject: [PATCH] Get the font directory from Windows (#13825) --- rpcs3/Emu/RSX/GL/GLOverlays.cpp | 3 +- rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp | 36 +++++++++--------------- rpcs3/Emu/RSX/Overlays/overlay_fonts.h | 4 +-- rpcs3/Emu/RSX/VK/VKOverlays.cpp | 5 ++-- rpcs3/Emu/RSX/VK/VKOverlays.h | 2 +- rpcs3/Emu/System.h | 1 + rpcs3/main_application.cpp | 17 +++++++++++ 7 files changed, 37 insertions(+), 31 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLOverlays.cpp b/rpcs3/Emu/RSX/GL/GLOverlays.cpp index f6be7a1589..e52843aa2b 100644 --- a/rpcs3/Emu/RSX/GL/GLOverlays.cpp +++ b/rpcs3/Emu/RSX/GL/GLOverlays.cpp @@ -299,8 +299,7 @@ namespace gl } // Create font file - std::vector glyph_data; - font->get_glyph_data(glyph_data); + const std::vector glyph_data = font->get_glyph_data(); auto tex = std::make_unique(GL_TEXTURE_2D_ARRAY, font_size.width, font_size.height, font_size.depth, 1, GL_R8); tex->copy_from(glyph_data.data(), gl::texture::format::r, gl::texture::type::ubyte, {}); diff --git a/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp b/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp index 80151fcc6e..6de7440e5e 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_fonts.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include "overlay_controls.h" +#include "Emu/System.h" #include "Emu/vfs_config.h" #ifndef _WIN32 @@ -107,19 +108,8 @@ namespace rsx glyph_load_setup result; result.font_names.push_back(font_name); -#ifdef _WIN32 - result.lookup_font_dirs.emplace_back("C:/Windows/Fonts/"); -#else - char* home = getenv("HOME"); - if (home == nullptr) - home = getpwuid(getuid())->pw_dir; - - result.lookup_font_dirs.emplace_back(home); - if (home[result.lookup_font_dirs[0].length() - 1] == '/') - result.lookup_font_dirs[0] += ".fonts/"; - else - result.lookup_font_dirs[0] += "/.fonts/"; -#endif + const std::vector font_dirs = Emu.GetCallbacks().get_font_dirs(); + result.lookup_font_dirs.insert(result.lookup_font_dirs.end(), font_dirs.begin(), font_dirs.end()); // Search dev_flash for the font too result.lookup_font_dirs.push_back(g_cfg_vfs.get_dev_flash() + "data/font/"); result.lookup_font_dirs.push_back(g_cfg_vfs.get_dev_flash() + "data/font/SONY-CC/"); @@ -283,15 +273,15 @@ namespace rsx } } - void font::render_text_ex(std::vector& result, f32& x_advance, f32& y_advance, const char32_t* text, usz char_limit, u16 max_width, bool wrap) + std::vector font::render_text_ex(f32& x_advance, f32& y_advance, const char32_t* text, usz char_limit, u16 max_width, bool wrap) { x_advance = 0.f; y_advance = 0.f; - result.clear(); + std::vector result; if (!initialized) { - return; + return result; } // Render as many characters as possible as glyphs. @@ -302,7 +292,7 @@ namespace rsx case '\0': { // We're done. - return; + return result; } case '\n': { @@ -409,28 +399,27 @@ namespace rsx } } // switch } + return result; } std::vector font::render_text(const char32_t* text, u16 max_width, bool wrap) { - std::vector result; f32 unused_x, unused_y; - render_text_ex(result, unused_x, unused_y, text, -1, max_width, wrap); - return result; + return render_text_ex(unused_x, unused_y, text, -1, max_width, wrap); } std::pair font::get_char_offset(const char32_t* text, usz max_length, u16 max_width, bool wrap) { - std::vector unused; f32 loc_x, loc_y; - render_text_ex(unused, loc_x, loc_y, text, max_length, max_width, wrap); + render_text_ex(loc_x, loc_y, text, max_length, max_width, wrap); return {loc_x, loc_y}; } - void font::get_glyph_data(std::vector& bytes) const + std::vector font::get_glyph_data() const { + std::vector bytes; const u32 page_size = codepage::bitmap_width * codepage::bitmap_height; const auto size = page_size * m_glyph_map.size(); @@ -442,6 +431,7 @@ namespace rsx std::memcpy(data, e.second->glyph_data.data(), page_size); data += page_size; } + return bytes; } } // namespace overlays } // namespace rsx diff --git a/rpcs3/Emu/RSX/Overlays/overlay_fonts.h b/rpcs3/Emu/RSX/Overlays/overlay_fonts.h index ce5d8eb58e..857c6e3cdd 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_fonts.h +++ b/rpcs3/Emu/RSX/Overlays/overlay_fonts.h @@ -73,7 +73,7 @@ namespace rsx stbtt_aligned_quad get_char(char32_t c, f32& x_advance, f32& y_advance); - void render_text_ex(std::vector& result, f32& x_advance, f32& y_advance, const char32_t* text, usz char_limit, u16 max_width, bool wrap); + std::vector render_text_ex(f32& x_advance, f32& y_advance, const char32_t* text, usz char_limit, u16 max_width, bool wrap); std::vector render_text(const char32_t* text, u16 max_width = -1, bool wrap = false); @@ -87,7 +87,7 @@ namespace rsx // Renderer info size3u get_glyph_data_dimensions() const { return { codepage::bitmap_width, codepage::bitmap_height, ::size32(m_glyph_map) }; } - void get_glyph_data(std::vector& bytes) const; + std::vector get_glyph_data() const; }; // TODO: Singletons are cancer diff --git a/rpcs3/Emu/RSX/VK/VKOverlays.cpp b/rpcs3/Emu/RSX/VK/VKOverlays.cpp index b3b378cc00..638b2138df 100644 --- a/rpcs3/Emu/RSX/VK/VKOverlays.cpp +++ b/rpcs3/Emu/RSX/VK/VKOverlays.cpp @@ -387,7 +387,7 @@ namespace vk } vk::image_view* ui_overlay_renderer::upload_simple_texture(vk::render_device& dev, vk::command_buffer& cmd, - vk::data_heap& upload_heap, u64 key, u32 w, u32 h, u32 layers, bool font, bool temp, void* pixel_src, u32 owner_uid) + vk::data_heap& upload_heap, u64 key, u32 w, u32 h, u32 layers, bool font, bool temp, const void* pixel_src, u32 owner_uid) { const VkFormat format = (font) ? VK_FORMAT_R8_UNORM : VK_FORMAT_B8G8R8A8_UNORM; const u32 pitch = (font) ? w : w * 4; @@ -517,8 +517,7 @@ namespace vk } // Create font resource - std::vector bytes; - font->get_glyph_data(bytes); + const std::vector bytes = font->get_glyph_data(); return upload_simple_texture(cmd.get_command_pool().get_owner(), cmd, upload_heap, key, image_size.width, image_size.height, image_size.depth, true, false, bytes.data(), -1); diff --git a/rpcs3/Emu/RSX/VK/VKOverlays.h b/rpcs3/Emu/RSX/VK/VKOverlays.h index 28fc31a556..31eaebb84d 100644 --- a/rpcs3/Emu/RSX/VK/VKOverlays.h +++ b/rpcs3/Emu/RSX/VK/VKOverlays.h @@ -152,7 +152,7 @@ namespace vk ui_overlay_renderer(); vk::image_view* upload_simple_texture(vk::render_device& dev, vk::command_buffer& cmd, - vk::data_heap& upload_heap, u64 key, u32 w, u32 h, u32 layers, bool font, bool temp, void* pixel_src, u32 owner_uid); + vk::data_heap& upload_heap, u64 key, u32 w, u32 h, u32 layers, bool font, bool temp, const void* pixel_src, u32 owner_uid); void init(vk::command_buffer& cmd, vk::data_heap& upload_heap); diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 73584c55d7..6636ba65fc 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -94,6 +94,7 @@ struct EmuCallbacks std::function get_image_info; // (filename, sub_type, width, height, CellSearchOrientation) std::function get_scaled_image; // (filename, target_width, target_height, width, height, dst, force_fit) std::string(*resolve_path)(std::string_view) = [](std::string_view arg){ return std::string{arg}; }; // Resolve path using Qt + std::function()> get_font_dirs; }; namespace utils diff --git a/rpcs3/main_application.cpp b/rpcs3/main_application.cpp index 5f0af7fe2a..42c8667312 100644 --- a/rpcs3/main_application.cpp +++ b/rpcs3/main_application.cpp @@ -36,6 +36,7 @@ #include // This shouldn't be outside rpcs3qt... #include // This shouldn't be outside rpcs3qt... +#include // This shouldn't be outside rpcs3qt... #include LOG_CHANNEL(sys_log, "SYS"); @@ -331,5 +332,21 @@ EmuCallbacks main_application::CreateCallbacks() return QFileInfo(QString::fromUtf8(sv.data(), static_cast(sv.size()))).canonicalFilePath().toStdString(); }; + callbacks.get_font_dirs = []() + { + const QStringList locations = QStandardPaths::standardLocations(QStandardPaths::FontsLocation); + std::vector font_dirs; + for (const QString& location : locations) + { + std::string font_dir = location.toStdString(); + if (!font_dir.ends_with('/')) + { + font_dir += '/'; + } + font_dirs.push_back(font_dir); + } + return font_dirs; + }; + return callbacks; }