overlays: use std::string_view for font functions

This commit is contained in:
Megamouse 2025-11-16 11:51:02 +01:00
parent 9b1d39c14e
commit 2d3e6c6d02
2 changed files with 6 additions and 6 deletions

View file

@ -52,13 +52,13 @@ namespace rsx
return quad; return quad;
} }
font::font(const char* ttf_name, f32 size) font::font(std::string_view ttf_name, f32 size)
{ {
// Convert pt to px // Convert pt to px
size_px = ceilf(size * 96.f / 72.f); size_px = ceilf(size * 96.f / 72.f);
size_pt = size; size_pt = size;
font_name = ttf_name; font_name = std::string(ttf_name);
initialized = true; initialized = true;
} }

View file

@ -69,7 +69,7 @@ namespace rsx
codepage* initialize_codepage(char32_t codepage_id); codepage* initialize_codepage(char32_t codepage_id);
public: public:
font(const char* ttf_name, f32 size); font(std::string_view ttf_name, f32 size);
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);
@ -79,7 +79,7 @@ namespace rsx
std::pair<f32, f32> get_char_offset(const char32_t* text, usz max_length, u16 max_width = -1, bool wrap = false); std::pair<f32, f32> get_char_offset(const char32_t* text, usz max_length, u16 max_width = -1, bool wrap = false);
bool matches(const char* name, int size) const { return static_cast<int>(size_pt) == size && font_name == name; } bool matches(std::string_view name, int size) const { return static_cast<int>(size_pt) == size && font_name == name; }
std::string_view get_name() const { return font_name; } std::string_view get_name() const { return font_name; }
f32 get_size_pt() const { return size_pt; } f32 get_size_pt() const { return size_pt; }
f32 get_size_px() const { return size_px; } f32 get_size_px() const { return size_px; }
@ -97,7 +97,7 @@ namespace rsx
std::vector<std::unique_ptr<font>> fonts; std::vector<std::unique_ptr<font>> fonts;
static fontmgr* m_instance; static fontmgr* m_instance;
font* find(const char* name, int size) font* find(std::string_view name, int size)
{ {
for (const auto& f : fonts) for (const auto& f : fonts)
{ {
@ -121,7 +121,7 @@ namespace rsx
} }
} }
static font* get(const char* name, int size) static font* get(std::string_view name, int size)
{ {
if (m_instance == nullptr) if (m_instance == nullptr)
m_instance = new fontmgr; m_instance = new fontmgr;