diff --git a/README.md b/README.md index 629580c1..e9c50090 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ correct place to search. For example, if you installed Boost via Homebrew, you m add something like the following to the Project Build Settings, under Linking->Other Linking Flags: - -lboost_filesystem -lboost_system -L/usr/local/Cellar/boost/1.57.0/lib + -lboost_filesystem -lboost_system -lboost_locale -L/usr/local/Cellar/boost/1.57.0/lib Again with Homebrew, you may also need to add the following to Apple LLVM Custom Compiler Flags -> Other C++ Flags: diff --git a/SConstruct b/SConstruct index ed27f391..4a2fcc12 100644 --- a/SConstruct +++ b/SConstruct @@ -397,6 +397,7 @@ if not env.GetOption('clean'): check_header('boost/spirit/include/classic.hpp', 'Boost.Spirit.Classic') check_lib('boost_system', 'Boost.System', suffixes, boost_versions) check_lib('boost_filesystem', 'Boost.Filesystem', suffixes, boost_versions) + check_lib('boost_locale', 'Boost.Locale', suffixes, boost_versions) sfml_suffixes = ['-d'] check_lib('sfml-system', 'SFML-system', sfml_suffixes) check_lib('sfml-window', 'SFML-window', sfml_suffixes) diff --git a/proj/vs2013/vcpkg.json b/proj/vs2013/vcpkg.json index 7dc72c2e..1b2b04d0 100644 --- a/proj/vs2013/vcpkg.json +++ b/proj/vs2013/vcpkg.json @@ -14,6 +14,7 @@ "boost-chrono", "boost-math", "boost-spirit", - "boost-process" + "boost-process", + "boost-locale" ] } \ No newline at end of file diff --git a/proj/vs2017/vcpkg.json b/proj/vs2017/vcpkg.json index 7dc72c2e..1b2b04d0 100644 --- a/proj/vs2017/vcpkg.json +++ b/proj/vs2017/vcpkg.json @@ -14,6 +14,7 @@ "boost-chrono", "boost-math", "boost-spirit", - "boost-process" + "boost-process", + "boost-locale" ] } \ No newline at end of file diff --git a/src/fileio/fileio_scen.cpp b/src/fileio/fileio_scen.cpp index 6edb5e9b..704d98e9 100644 --- a/src/fileio/fileio_scen.cpp +++ b/src/fileio/fileio_scen.cpp @@ -9,10 +9,13 @@ #include "fileio.hpp" #include +#include #include #include #include #include +#include "tools/replay.hpp" +#include "dialogxml/dialogs/strchoice.hpp" #include "dialogxml/dialogs/strdlog.hpp" @@ -303,26 +306,83 @@ bool load_scenario_v1(fs::path file_to_load, cScenario& scenario, eLoadScenario scenario.special_items.resize(50); scenario.journal_strs.resize(50); scenario.spec_strs.resize(100); + + static std::vector encodings_to_try = {"Latin1", "Windows-1252", "MacRoman"}; + fs::path meta = file_to_load.parent_path() / "meta.xml"; + using namespace ticpp; + ticpp::Document meta_doc; + if(!fs::exists(meta)){ + ticpp::Element root_element("meta"); + meta_doc.InsertEndChild(root_element); + }else{ + meta_doc.LoadFile(meta.string()); + } + + auto info = info_from_action(*meta_doc.FirstChildElement()); + for(short i = 0; i < 270; i++) { len = (long) (temp_scenario.scen_str_len[i]); fread(temp_str, len, 1, file_id); temp_str[len] = 0; - if(i == 0) scenario.scen_name = temp_str; + + std::string decoded; + std::vector options; + if(info.find("encoding") != info.end()){ + std::string encoding = info["encoding"]; + decoded = boost::locale::conv::to_utf(temp_str, encoding); + }else{ + bool different = false; + for(std::string encoding : encodings_to_try){ + std::string enc = boost::locale::conv::to_utf(temp_str, encoding); + if(!options.empty() && enc != options.back()) different = true; + options.push_back(enc); + } + if(different){ + LOG_VALUE(file_to_load); + for(std::string enc : options){ + LOG_VALUE(enc); + } + int which = -1; + // Comment this out if you're not messing with the metadata: + // which = cStringChoice(options, "Which is best?").show(-1); + if(which != -1){ + info["encoding"] = encodings_to_try[which]; + decoded = options[which]; + } + else{ + decoded = options[0]; // temp! + } + }else{ + decoded = options.back(); + } + } + + if(i == 0) scenario.scen_name = decoded; else if(i == 1 || i == 2) - scenario.teaser_text[i-1] = temp_str; + scenario.teaser_text[i-1] = decoded; else if(i == 3) - scenario.contact_info[1] = temp_str; + scenario.contact_info[1] = decoded; else if(i >= 4 && i < 10) - scenario.intro_strs[i-4] = temp_str; + scenario.intro_strs[i-4] = decoded; else if(i >= 10 && i < 60) - scenario.journal_strs[i-10] = temp_str; + scenario.journal_strs[i-10] = decoded; else if(i >= 60 && i < 160) { - if(i % 2 == 0) scenario.special_items[(i-60)/2].name = temp_str; - else scenario.special_items[(i-60)/2].descr = temp_str; + if(i % 2 == 0) scenario.special_items[(i-60)/2].name = decoded; + else scenario.special_items[(i-60)/2].descr = decoded; } else if(i >= 260) continue; // These were never ever used, for some reason. - else scenario.spec_strs[i-160] = temp_str; + else scenario.spec_strs[i-160] = decoded; } - + Element new_root("meta"); + ticpp::Document new_doc; + for(auto& p : info){ + Element next_child(p.first); + Text child_text(p.second); + next_child.InsertEndChild(child_text); + new_root.InsertEndChild(next_child); + } + new_doc.InsertEndChild(new_root); + new_doc.SaveFile(meta.string()); + fclose(file_id); scenario.scen_file = file_to_load; diff --git a/src/gfx/render_text.cpp b/src/gfx/render_text.cpp index a528945f..a2445a0b 100644 --- a/src/gfx/render_text.cpp +++ b/src/gfx/render_text.cpp @@ -109,7 +109,11 @@ static void push_snippets(size_t start, size_t end, text_params_t& options, size } std::map substitutions = { - {"–", "--"} + {"–", "--"}, + {"´", "'"}, + {"©", "(C)"}, + {"…", "..."}, + {"™", "TM"} }; break_info_t calculate_line_wrapping(rectangle dest_rect, std::string str, TextStyle style) {