From 33660b3ef78eb4783e9da4bca9bce5cb855ae2a8 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Thu, 17 Apr 2025 21:40:35 +0200 Subject: [PATCH] Add support for SFML utf8 strings --- include/frontend.hpp | 3 ++- source/TextRectangle.cpp | 10 +++++++--- source/WindowScreen.cpp | 7 ++++++- source/frontend.cpp | 6 +++--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/frontend.hpp b/include/frontend.hpp index 7a073a3..ced955b 100755 --- a/include/frontend.hpp +++ b/include/frontend.hpp @@ -321,7 +321,8 @@ private: int get_fullscreen_offset_y(int top_width, int top_height, int bot_width, int bot_height, int separator_contribute); void resize_window_and_out_rects(bool do_work = true); void create_window(bool re_prepare_size, bool reset_text = true); - std::string title_factory(); + std::string _title_factory(); + sf::String title_factory(); void update_view_size(); void open(); void update_screen_settings(); diff --git a/source/TextRectangle.cpp b/source/TextRectangle.cpp index 25ea136..0634970 100755 --- a/source/TextRectangle.cpp +++ b/source/TextRectangle.cpp @@ -153,9 +153,13 @@ void TextRectangle::reset_data(TextData &data) { data.pos_y = 0; } +static sf::String convert_to_utf8(const std::string &str) { + return sf::String::fromUtf8(str.begin(), str.end()); +} + void TextRectangle::setTextWithLineWrapping(int x_limit) { if(x_limit == 0) { - this->actual_text.setString(this->loaded_data.printed_text); + this->actual_text.setString(convert_to_utf8(this->loaded_data.printed_text)); return; } bool is_done = false; @@ -173,7 +177,7 @@ void TextRectangle::setTextWithLineWrapping(int x_limit) { } for(size_t i = pos; i < space_pos; i++) curr_text += this->loaded_data.printed_text[i]; - this->actual_text.setString(curr_text); + this->actual_text.setString(convert_to_utf8(curr_text)); sf::FloatRect globalBounds = this->actual_text.getGlobalBounds(); int bounds_width = (int)(globalBounds.size.x + (globalBounds.position.x * 2)); if(line_started && (bounds_width > x_limit)) { @@ -185,7 +189,7 @@ void TextRectangle::setTextWithLineWrapping(int x_limit) { line_started = true; new_text = curr_text; } - this->actual_text.setString(new_text); + this->actual_text.setString(convert_to_utf8(new_text)); } void TextRectangle::setRealSize(int width, int height, bool check_previous) { diff --git a/source/WindowScreen.cpp b/source/WindowScreen.cpp index aaf42f4..fa7af02 100755 --- a/source/WindowScreen.cpp +++ b/source/WindowScreen.cpp @@ -481,13 +481,18 @@ void WindowScreen::window_factory(bool is_main_thread) { this->update_connection(); } -std::string WindowScreen::title_factory() { +std::string WindowScreen::_title_factory() { std::string title = this->win_title; if(this->capture_status->connected) title += " - " + get_name_of_device(this->capture_status); return title; } +sf::String WindowScreen::title_factory() { + std::string title = this->_title_factory(); + return sf::String::fromUtf8(title.begin(), title.end()); +} + // These values may be undefined under Windows... #ifndef GL_BGR #define GL_BGR 0x80e0 diff --git a/source/frontend.cpp b/source/frontend.cpp index 1c6a3cf..a47adfa 100755 --- a/source/frontend.cpp +++ b/source/frontend.cpp @@ -109,7 +109,7 @@ const CropData scaled_ds_pokemon_crop = { .bot_x = 0, .bot_y = 0, .allowed_joint = true, .allowed_top = true, .allowed_bottom = false, .allowed_3ds = true, .allowed_ds = false, .is_game_specific = true, -.name = "Scaled Pokemon DS"}; +.name = "Scaled Pokémon DS"}; const CropData scaled_ds_pmd_brt_crop = { .top_width = TOP_SCALED_DS_WIDTH_3DS, .top_height = HEIGHT_3DS, @@ -127,7 +127,7 @@ const CropData native_ds_pokemon_crop = { .bot_x = (BOT_WIDTH_3DS - WIDTH_DS) / 2, .bot_y = HEIGHT_3DS - HEIGHT_DS, .allowed_joint = true, .allowed_top = true, .allowed_bottom = true, .allowed_3ds = true, .allowed_ds = false, .is_game_specific = true, -.name = "Native Pokemon DS"}; +.name = "Native Pokémon DS"}; const CropData native_ds_pmd_brt_crop = { .top_width = WIDTH_DS, .top_height = HEIGHT_DS, @@ -190,7 +190,7 @@ const CropData ds_pokemon_crop = { .bot_x = 0, .bot_y = 0, .allowed_joint = true, .allowed_top = true, .allowed_bottom = true, .allowed_3ds = false, .allowed_ds = true, .is_game_specific = true, -.name = "Pokemon DS"}; +.name = "Pokémon DS"}; const CropData ds_pmd_brt_crop = { .top_width = WIDTH_DS, .top_height = HEIGHT_DS,