Try explicitely converting to and from utf8

This commit is contained in:
Stepland 2022-12-27 18:30:38 +01:00
parent 05581c9b80
commit cc1aab77d5
5 changed files with 35 additions and 5 deletions

View File

@ -1,4 +1,5 @@
#include "file_dialogs.hpp" #include "file_dialogs.hpp"
#include "utf8_strings.hpp"
#include <cstring> #include <cstring>
@ -30,8 +31,8 @@ namespace feis {
if (utf8_path == nullptr) { if (utf8_path == nullptr) {
return {}; return {};
} else { } else {
const auto u8string_path = std::u8string{utf8_path, utf8_path+std::strlen(utf8_path)}; const std::string utf8_string{utf8_path, utf8_path+std::strlen(utf8_path)};
return std::filesystem::path{u8string_path}; return to_path(utf8_string);
} }
} }
} }

View File

@ -27,6 +27,7 @@
#include "sound_effect.hpp" #include "sound_effect.hpp"
#include "src/custom_sfml_audio/synced_sound_streams.hpp" #include "src/custom_sfml_audio/synced_sound_streams.hpp"
#include "widgets/blank_screen.hpp" #include "widgets/blank_screen.hpp"
#include "utf8_strings.hpp"
int main() { int main() {
// TODO : Make the playfield not appear when there's no chart selected // 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)) { if (not std::filesystem::exists(font_path)) {
tinyfd_messageBox( tinyfd_messageBox(
"Error", "Error",
("Could not open "+font_path.string()).c_str(), ("Could not open "+to_utf8_encoded_string(font_path)).c_str(),
"ok", "ok",
"error", "error",
1 1
@ -63,8 +64,9 @@ int main() {
ImGuiIO& IO = ImGui::GetIO(); ImGuiIO& IO = ImGui::GetIO();
IO.Fonts->Clear(); IO.Fonts->Clear();
IO.Fonts->AddFontFromFileTTF( IO.Fonts->AddFontFromFileTTF(
(assets_folder / "fonts" / "NotoSans-Medium.ttf").c_str(), to_utf8_encoded_string(assets_folder / "fonts" / "NotoSans-Medium.ttf").c_str(),
16.f); 16.f
);
ImGui::SFML::UpdateFontTexture(); ImGui::SFML::UpdateFontTexture();
IO.ConfigWindowsMoveFromTitleBarOnly = true; IO.ConfigWindowsMoveFromTitleBarOnly = true;

View File

@ -31,6 +31,7 @@ sources += files(
'sound_effect.cpp', 'sound_effect.cpp',
'special_numeric_types.cpp', 'special_numeric_types.cpp',
'toolbox.cpp', 'toolbox.cpp',
'utf8_strings.cpp',
) )
conf_data = configuration_data() conf_data = configuration_data()

19
src/utf8_strings.cpp Normal file
View File

@ -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)};
}

7
src/utf8_strings.hpp Normal file
View File

@ -0,0 +1,7 @@
#include <filesystem>
#include <string>
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);