From 83e56612092217721bb5920de0f5be14481e2343 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Mon, 18 Aug 2025 11:45:12 -0500 Subject: [PATCH] Fix rendering UTF-8 text --- src/game/boe.text.cpp | 2 +- src/gfx/render_text.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/game/boe.text.cpp b/src/game/boe.text.cpp index 36269c3d..a1ea6e26 100644 --- a/src/game/boe.text.cpp +++ b/src/game/boe.text.cpp @@ -1130,7 +1130,7 @@ void print_buf () { line_style.applyTo(text, get_ui_scale()); // A spacing factor of 1.0 within multiline messages doesn't actually line up with other single buffer lines text.setLineSpacing(0.85); - text.setString(message); + text.setString(sf::String::fromUtf8(message.begin(), message.end())); text.setPosition(moveTo); draw_scale_aware_text(text_area_gworld(), text); } diff --git a/src/gfx/render_text.cpp b/src/gfx/render_text.cpp index 611325b3..a86861c6 100644 --- a/src/gfx/render_text.cpp +++ b/src/gfx/render_text.cpp @@ -125,7 +125,7 @@ break_info_t calculate_line_wrapping(rectangle dest_rect, std::string str, TextS short str_len = str.length(); unsigned short last_line_break = 0,last_word_break = 0; - str_to_draw.setString(str); + str_to_draw.setString(sf::String::fromUtf8(str.begin(), str.end())); // Even if the text is only one line, break_info is required for calculating word boundaries. // So we can't skip the rest of this. @@ -263,7 +263,7 @@ static void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,st for(auto it : substitutions){ boost::replace_all(str, it.first, it.second); } - str_to_draw.setString(str); + str_to_draw.setString(sf::String::fromUtf8(str.begin(), str.end())); short total_width = str_to_draw.getLocalBounds().width; options.style.applyTo(str_to_draw, get_ui_scale()); @@ -337,7 +337,7 @@ static void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,st } for(auto& snippet : options.snippets) { - str_to_draw.setString(snippet.text); + str_to_draw.setString(sf::String::fromUtf8(snippet.text.begin(), snippet.text.end())); str_to_draw.setPosition(snippet.at); if(snippet.hilited) { rectangle bounds = str_to_draw.getGlobalBounds(); @@ -409,7 +409,7 @@ size_t string_length(std::string str, const TextStyle& style, short* height){ sf::Text text; style.applyTo(text); - text.setString(str); + text.setString(sf::String::fromUtf8(str.begin(), str.end())); total_width = text.getLocalBounds().width; if(strings_to_cache.count(str)){ location measurement;