Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the font directory from Windows #13825

Merged
merged 4 commits into from May 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions rpcs3/Emu/RSX/GL/GLOverlays.cpp
Expand Up @@ -299,8 +299,7 @@ namespace gl
}

// Create font file
std::vector<u8> glyph_data;
font->get_glyph_data(glyph_data);
std::vector<u8> glyph_data = font->get_glyph_data();
oltolm marked this conversation as resolved.
Show resolved Hide resolved

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, {});
Expand Down
36 changes: 13 additions & 23 deletions 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
Expand Down Expand Up @@ -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
auto font_dirs = Emu.GetCallbacks().get_font_dirs();
oltolm marked this conversation as resolved.
Show resolved Hide resolved
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/");
Expand Down Expand Up @@ -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;
y_advance = 0.f;
result.clear();
std::vector<vertex> result;

if (!initialized)
{
return;
return result;
}

// Render as many characters as possible as glyphs.
Expand All @@ -302,7 +292,7 @@ namespace rsx
case '\0':
{
// We're done.
return;
return result;
}
case '\n':
{
Expand Down Expand Up @@ -409,28 +399,27 @@ namespace rsx
}
} // switch
}
return result;
}

std::vector<vertex> font::render_text(const char32_t* text, u16 max_width, bool wrap)
{
std::vector<vertex> 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<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;

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<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 auto size = page_size * m_glyph_map.size();

Expand All @@ -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
4 changes: 2 additions & 2 deletions rpcs3/Emu/RSX/Overlays/overlay_fonts.h
Expand Up @@ -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<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);

Expand All @@ -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<u8>& bytes) const;
std::vector<u8> get_glyph_data() const;
};

// TODO: Singletons are cancer
Expand Down
3 changes: 1 addition & 2 deletions rpcs3/Emu/RSX/VK/VKOverlays.cpp
Expand Up @@ -517,8 +517,7 @@ namespace vk
}

// Create font resource
std::vector<u8> bytes;
font->get_glyph_data(bytes);
std::vector<u8> bytes = font->get_glyph_data();
oltolm marked this conversation as resolved.
Show resolved Hide resolved

return upload_simple_texture(cmd.get_command_pool().get_owner(), cmd, upload_heap, key, image_size.width, image_size.height, image_size.depth,
oltolm marked this conversation as resolved.
Show resolved Hide resolved
true, false, bytes.data(), -1);
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/System.h
Expand Up @@ -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&, 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::function<std::vector<std::string>()> get_font_dirs;
};

namespace utils
Expand Down
17 changes: 17 additions & 0 deletions rpcs3/main_application.cpp
Expand Up @@ -36,6 +36,7 @@

#include <QFileInfo> // This shouldn't be outside rpcs3qt...
#include <QImageReader> // This shouldn't be outside rpcs3qt...
#include <QStandardPaths> // This shouldn't be outside rpcs3qt...
#include <thread>

LOG_CHANNEL(sys_log, "SYS");
Expand Down Expand Up @@ -331,5 +332,21 @@ EmuCallbacks main_application::CreateCallbacks()
return QFileInfo(QString::fromUtf8(sv.data(), static_cast<int>(sv.size()))).canonicalFilePath().toStdString();
};

callbacks.get_font_dirs = []()
{
auto locations = QStandardPaths::standardLocations(QStandardPaths::FontsLocation);
oltolm marked this conversation as resolved.
Show resolved Hide resolved
std::vector<std::string> font_dirs;
for (const auto& location : locations)
oltolm marked this conversation as resolved.
Show resolved Hide resolved
{
auto font_dir = location.toStdString();
oltolm marked this conversation as resolved.
Show resolved Hide resolved
if (!font_dir.ends_with('/'))
{
font_dir += '/';
}
font_dirs.push_back(font_dir);
}
return font_dirs;
};

return callbacks;
}