VortexCoyote / leraine-studio

A cross-platform portable open-source VSRG chart editor written in C++ with SFML.
Mozilla Public License 2.0
13 stars 6 forks source link

Unicode support #44

Open VortexCoyote opened 3 years ago

VortexCoyote commented 3 years ago

Loading files with unicode currently crashes the editor. Investigate how we can support this format

JaanJah commented 3 years ago

I looked into this and found out that we probably have to load in another font and add a japanese/other glyph ranges to support more unicode characters.

Ref: https://github.com/ocornut/imgui/blob/master/docs/FONTS.md#font-loading-instructions

UnnamedOrange commented 3 years ago

It seems that the imgui open file dialog uses UTF-8 as its coding, though the type std::string or const char* is used. However, in Windows const char* means ANSI, which is not the same as UTF-8. An experiment is shown below. Change:

https://github.com/VortexCoyote/leraine-studio/blob/a362ac483036bb2305ab88e06a8ea03e3dd5d109/source/modules/chart-parser-module.cpp#L99

To:

    std::ifstream chartFile{std::filesystem::path(reinterpret_cast<const char8_t*>(InPath.c_str()))}; // Regard InPath as UTF-8.

(To support char8_t, use C++20.) This makes the constructor of ifstream work, while the former one will throw a "File not found!".

Note that there are more codes to be modified.

UnnamedOrange commented 3 years ago

Sample of InPath:

C:\Users\username\Desktop\测试\516517 DJ Sharpnel - Over the Fullereneshift

测试 in the path corrupts the routine, while a path in pure English will not.