mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-05 06:21:26 +12:00
Get the font directory from Windows (#13825)
This commit is contained in:
parent
db7f84f9f8
commit
b0de5970ce
7 changed files with 37 additions and 31 deletions
|
@ -299,8 +299,7 @@ namespace gl
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create font file
|
// Create font file
|
||||||
std::vector<u8> glyph_data;
|
const std::vector<u8> glyph_data = font->get_glyph_data();
|
||||||
font->get_glyph_data(glyph_data);
|
|
||||||
|
|
||||||
auto tex = std::make_unique<gl::texture>(GL_TEXTURE_2D_ARRAY, font_size.width, font_size.height, font_size.depth, 1, GL_R8);
|
auto tex = std::make_unique<gl::texture>(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, {});
|
tex->copy_from(glyph_data.data(), gl::texture::format::r, gl::texture::type::ubyte, {});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "overlay_controls.h"
|
#include "overlay_controls.h"
|
||||||
|
#include "Emu/System.h"
|
||||||
#include "Emu/vfs_config.h"
|
#include "Emu/vfs_config.h"
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
@ -107,19 +108,8 @@ namespace rsx
|
||||||
glyph_load_setup result;
|
glyph_load_setup result;
|
||||||
result.font_names.push_back(font_name);
|
result.font_names.push_back(font_name);
|
||||||
|
|
||||||
#ifdef _WIN32
|
const std::vector<std::string> font_dirs = Emu.GetCallbacks().get_font_dirs();
|
||||||
result.lookup_font_dirs.emplace_back("C:/Windows/Fonts/");
|
result.lookup_font_dirs.insert(result.lookup_font_dirs.end(), font_dirs.begin(), font_dirs.end());
|
||||||
#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
|
|
||||||
// Search dev_flash for the font too
|
// 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/");
|
||||||
result.lookup_font_dirs.push_back(g_cfg_vfs.get_dev_flash() + "data/font/SONY-CC/");
|
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<vertex>& result, f32& x_advance, f32& y_advance, const char32_t* text, usz char_limit, u16 max_width, bool wrap)
|
std::vector<vertex> 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;
|
x_advance = 0.f;
|
||||||
y_advance = 0.f;
|
y_advance = 0.f;
|
||||||
result.clear();
|
std::vector<vertex> result;
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
return;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render as many characters as possible as glyphs.
|
// Render as many characters as possible as glyphs.
|
||||||
|
@ -302,7 +292,7 @@ namespace rsx
|
||||||
case '\0':
|
case '\0':
|
||||||
{
|
{
|
||||||
// We're done.
|
// We're done.
|
||||||
return;
|
return result;
|
||||||
}
|
}
|
||||||
case '\n':
|
case '\n':
|
||||||
{
|
{
|
||||||
|
@ -409,28 +399,27 @@ namespace rsx
|
||||||
}
|
}
|
||||||
} // switch
|
} // switch
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<vertex> font::render_text(const char32_t* text, u16 max_width, bool wrap)
|
std::vector<vertex> font::render_text(const char32_t* text, u16 max_width, bool wrap)
|
||||||
{
|
{
|
||||||
std::vector<vertex> result;
|
|
||||||
f32 unused_x, unused_y;
|
f32 unused_x, unused_y;
|
||||||
|
|
||||||
render_text_ex(result, unused_x, unused_y, text, -1, max_width, wrap);
|
return render_text_ex(unused_x, unused_y, text, -1, max_width, wrap);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<f32, f32> font::get_char_offset(const char32_t* text, usz max_length, u16 max_width, bool wrap)
|
std::pair<f32, f32> font::get_char_offset(const char32_t* text, usz max_length, u16 max_width, bool wrap)
|
||||||
{
|
{
|
||||||
std::vector<vertex> unused;
|
|
||||||
f32 loc_x, loc_y;
|
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};
|
return {loc_x, loc_y};
|
||||||
}
|
}
|
||||||
|
|
||||||
void font::get_glyph_data(std::vector<u8>& bytes) const
|
std::vector<u8> font::get_glyph_data() const
|
||||||
{
|
{
|
||||||
|
std::vector<u8> bytes;
|
||||||
const u32 page_size = codepage::bitmap_width * codepage::bitmap_height;
|
const u32 page_size = codepage::bitmap_width * codepage::bitmap_height;
|
||||||
const auto size = page_size * m_glyph_map.size();
|
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);
|
std::memcpy(data, e.second->glyph_data.data(), page_size);
|
||||||
data += page_size;
|
data += page_size;
|
||||||
}
|
}
|
||||||
|
return bytes;
|
||||||
}
|
}
|
||||||
} // namespace overlays
|
} // namespace overlays
|
||||||
} // namespace rsx
|
} // namespace rsx
|
||||||
|
|
|
@ -73,7 +73,7 @@ namespace rsx
|
||||||
|
|
||||||
stbtt_aligned_quad get_char(char32_t c, f32& x_advance, f32& y_advance);
|
stbtt_aligned_quad get_char(char32_t c, f32& x_advance, f32& y_advance);
|
||||||
|
|
||||||
void render_text_ex(std::vector<vertex>& result, f32& x_advance, f32& y_advance, const char32_t* text, usz char_limit, u16 max_width, bool wrap);
|
std::vector<vertex> render_text_ex(f32& x_advance, f32& y_advance, const char32_t* text, usz char_limit, u16 max_width, bool wrap);
|
||||||
|
|
||||||
std::vector<vertex> render_text(const char32_t* text, u16 max_width = -1, bool wrap = false);
|
std::vector<vertex> render_text(const char32_t* text, u16 max_width = -1, bool wrap = false);
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ namespace rsx
|
||||||
|
|
||||||
// Renderer info
|
// Renderer info
|
||||||
size3u get_glyph_data_dimensions() const { return { codepage::bitmap_width, codepage::bitmap_height, ::size32(m_glyph_map) }; }
|
size3u get_glyph_data_dimensions() const { return { codepage::bitmap_width, codepage::bitmap_height, ::size32(m_glyph_map) }; }
|
||||||
void get_glyph_data(std::vector<u8>& bytes) const;
|
std::vector<u8> get_glyph_data() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Singletons are cancer
|
// TODO: Singletons are cancer
|
||||||
|
|
|
@ -387,7 +387,7 @@ namespace vk
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::image_view* ui_overlay_renderer::upload_simple_texture(vk::render_device& dev, vk::command_buffer& cmd,
|
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 VkFormat format = (font) ? VK_FORMAT_R8_UNORM : VK_FORMAT_B8G8R8A8_UNORM;
|
||||||
const u32 pitch = (font) ? w : w * 4;
|
const u32 pitch = (font) ? w : w * 4;
|
||||||
|
@ -517,8 +517,7 @@ namespace vk
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create font resource
|
// Create font resource
|
||||||
std::vector<u8> bytes;
|
const std::vector<u8> bytes = font->get_glyph_data();
|
||||||
font->get_glyph_data(bytes);
|
|
||||||
|
|
||||||
return upload_simple_texture(cmd.get_command_pool().get_owner(), cmd, upload_heap, key, image_size.width, image_size.height, image_size.depth,
|
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);
|
true, false, bytes.data(), -1);
|
||||||
|
|
|
@ -152,7 +152,7 @@ namespace vk
|
||||||
ui_overlay_renderer();
|
ui_overlay_renderer();
|
||||||
|
|
||||||
vk::image_view* upload_simple_texture(vk::render_device& dev, vk::command_buffer& cmd,
|
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);
|
void init(vk::command_buffer& cmd, vk::data_heap& upload_heap);
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@ struct EmuCallbacks
|
||||||
std::function<bool(const std::string&, std::string&, s32&, s32&, s32&)> get_image_info; // (filename, sub_type, width, height, CellSearchOrientation)
|
std::function<bool(const std::string&, std::string&, s32&, s32&, s32&)> get_image_info; // (filename, sub_type, width, height, CellSearchOrientation)
|
||||||
std::function<bool(const std::string&, s32, s32, s32&, s32&, u8*, bool)> get_scaled_image; // (filename, target_width, target_height, width, height, dst, force_fit)
|
std::function<bool(const std::string&, s32, s32, s32&, s32&, u8*, bool)> 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::string(*resolve_path)(std::string_view) = [](std::string_view arg){ return std::string{arg}; }; // Resolve path using Qt
|
||||||
|
std::function<std::vector<std::string>()> get_font_dirs;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace utils
|
namespace utils
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include <QFileInfo> // This shouldn't be outside rpcs3qt...
|
#include <QFileInfo> // This shouldn't be outside rpcs3qt...
|
||||||
#include <QImageReader> // This shouldn't be outside rpcs3qt...
|
#include <QImageReader> // This shouldn't be outside rpcs3qt...
|
||||||
|
#include <QStandardPaths> // This shouldn't be outside rpcs3qt...
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
LOG_CHANNEL(sys_log, "SYS");
|
LOG_CHANNEL(sys_log, "SYS");
|
||||||
|
@ -331,5 +332,21 @@ EmuCallbacks main_application::CreateCallbacks()
|
||||||
return QFileInfo(QString::fromUtf8(sv.data(), static_cast<int>(sv.size()))).canonicalFilePath().toStdString();
|
return QFileInfo(QString::fromUtf8(sv.data(), static_cast<int>(sv.size()))).canonicalFilePath().toStdString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
callbacks.get_font_dirs = []()
|
||||||
|
{
|
||||||
|
const QStringList locations = QStandardPaths::standardLocations(QStandardPaths::FontsLocation);
|
||||||
|
std::vector<std::string> 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;
|
return callbacks;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue