From cc1aab77d5aca90fab5d82f46438d2512439daed Mon Sep 17 00:00:00 2001 From: Stepland <10530295-Buggyroom@users.noreply.gitlab.com> Date: Tue, 27 Dec 2022 18:30:38 +0100 Subject: [PATCH] Try explicitely converting to and from utf8 --- src/file_dialogs.cpp | 5 +++-- src/main.cpp | 8 +++++--- src/meson.build | 1 + src/utf8_strings.cpp | 19 +++++++++++++++++++ src/utf8_strings.hpp | 7 +++++++ 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 src/utf8_strings.cpp create mode 100644 src/utf8_strings.hpp diff --git a/src/file_dialogs.cpp b/src/file_dialogs.cpp index 5e9503b..539d9fc 100644 --- a/src/file_dialogs.cpp +++ b/src/file_dialogs.cpp @@ -1,4 +1,5 @@ #include "file_dialogs.hpp" +#include "utf8_strings.hpp" #include @@ -30,8 +31,8 @@ namespace feis { if (utf8_path == nullptr) { return {}; } else { - const auto u8string_path = std::u8string{utf8_path, utf8_path+std::strlen(utf8_path)}; - return std::filesystem::path{u8string_path}; + const std::string utf8_string{utf8_path, utf8_path+std::strlen(utf8_path)}; + return to_path(utf8_string); } } } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index c615962..73c2b91 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,7 @@ #include "sound_effect.hpp" #include "src/custom_sfml_audio/synced_sound_streams.hpp" #include "widgets/blank_screen.hpp" +#include "utf8_strings.hpp" int main() { // TODO : Make the playfield not appear when there's no chart selected @@ -53,7 +54,7 @@ int main() { if (not std::filesystem::exists(font_path)) { tinyfd_messageBox( "Error", - ("Could not open "+font_path.string()).c_str(), + ("Could not open "+to_utf8_encoded_string(font_path)).c_str(), "ok", "error", 1 @@ -63,8 +64,9 @@ int main() { ImGuiIO& IO = ImGui::GetIO(); IO.Fonts->Clear(); IO.Fonts->AddFontFromFileTTF( - (assets_folder / "fonts" / "NotoSans-Medium.ttf").c_str(), - 16.f); + to_utf8_encoded_string(assets_folder / "fonts" / "NotoSans-Medium.ttf").c_str(), + 16.f + ); ImGui::SFML::UpdateFontTexture(); IO.ConfigWindowsMoveFromTitleBarOnly = true; diff --git a/src/meson.build b/src/meson.build index ca8149d..a7be0f4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -31,6 +31,7 @@ sources += files( 'sound_effect.cpp', 'special_numeric_types.cpp', 'toolbox.cpp', + 'utf8_strings.cpp', ) conf_data = configuration_data() diff --git a/src/utf8_strings.cpp b/src/utf8_strings.cpp new file mode 100644 index 0000000..03416bc --- /dev/null +++ b/src/utf8_strings.cpp @@ -0,0 +1,19 @@ +#include "utf8_strings.hpp" + +std::string to_utf8_encoded_string(const std::u8string& u8s) { + std::string result{u8s.cbegin(), u8s.cend()}; + return result; +} + +std::string to_utf8_encoded_string(const std::filesystem::path& path) { + return to_utf8_encoded_string(path.u8string()); +} + +std::u8string to_u8string(const std::string& utf8s) { + std::u8string result{utf8s.cbegin(), utf8s.cend()}; + return result; +} + +std::filesystem::path to_path(const std::string& utf8s) { + return std::filesystem::path{to_u8string(utf8s)}; +} \ No newline at end of file diff --git a/src/utf8_strings.hpp b/src/utf8_strings.hpp new file mode 100644 index 0000000..00a18af --- /dev/null +++ b/src/utf8_strings.hpp @@ -0,0 +1,7 @@ +#include +#include + +std::string to_utf8_encoded_string(const std::u8string& u8s); +std::string to_utf8_encoded_string(const std::filesystem::path& path); +std::u8string to_u8string(const std::string& utf8s); +std::filesystem::path to_path(const std::string& utf8s); \ No newline at end of file