Add support for chinese & russian #72

This commit is contained in:
Grinch_ 2022-06-20 04:36:20 +06:00
parent 95ca4db0fd
commit ca325a4c2d
7 changed files with 32 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@ -78,7 +78,6 @@ void CheatMenu::ProcessPages()
ImGuiStyle &style = ImGui::GetStyle(); ImGuiStyle &style = ImGui::GetStyle();
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
ImGui::PushFont(FontMgr::Get("header"));
m_nMenuPage = Updater::IsUpdateAvailable() ? eMenuPages::UPDATE : m_nMenuPage; m_nMenuPage = Updater::IsUpdateAvailable() ? eMenuPages::UPDATE : m_nMenuPage;
// Check once if it's anniversary day // Check once if it's anniversary day
@ -166,7 +165,6 @@ void CheatMenu::ProcessPages()
ImGui::SameLine(); ImGui::SameLine();
} }
} }
ImGui::PopFont();
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::Dummy(ImVec2(0, 10)); ImGui::Dummy(ImVec2(0, 10));

View File

@ -139,9 +139,8 @@ void D3dHook::ProcessFrame(void* ptr)
ImGui_ImplWin32_EnableDpiAwareness(); ImGui_ImplWin32_EnableDpiAwareness();
// Loading fonts // Loading fonts
io.FontDefault = FontMgr::Load("text", 1.0f); io.FontDefault = FontMgr::Load("text", 1.1f);
FontMgr::Load("title", 2.0f); FontMgr::Load("title", 2.0f);
FontMgr::Load("header", 1.25f);
io.IniFilename = nullptr; io.IniFilename = nullptr;
io.LogFilename = nullptr; io.LogFilename = nullptr;

View File

@ -14,12 +14,37 @@ ImFont* FontMgr::Get(const char* fontName)
return nullptr; return nullptr;
} }
const ImWchar* FontMgr::GetGlyphRanges()
{
static const ImWchar ranges[] =
{
0x0020, 0x00FF, // Basic Latin + Latin Supplement
0x2000, 0x206F, // General Punctuation
// Chinease
0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana
0x31F0, 0x31FF, // Katakana Phonetic Extensions
0xFF00, 0xFFEF, // Half-width characters
0xFFFD, 0xFFFD, // Invalid
0x4e00, 0x9FAF, // CJK Ideograms
// Russian
0x0020, 0x00FF, // Basic Latin + Latin Supplement
0x0400, 0x052F, // Cyrillic + Cyrillic Supplement
0x2DE0, 0x2DFF, // Cyrillic Extended-A
0xA640, 0xA69F, // Cyrillic Extended-B
0x2212, 0x2212, // Minus Sign
0,
};
return &ranges[0];
}
ImFont* FontMgr::Load(const char* fontName, float fontMul) ImFont* FontMgr::Load(const char* fontName, float fontMul)
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
size_t fontSize = static_cast<int>(screen::GetScreenHeight() / 54.85f) * fontMul; size_t fontSize = static_cast<int>(screen::GetScreenHeight() / 54.85f) * fontMul;
std::string fullPath = std::format("{}{}.ttf", PLUGIN_PATH((char*)FILE_NAME "/fonts/"), fontName); std::string fullPath = std::format("{}{}.ttf", PLUGIN_PATH((char*)FILE_NAME "/fonts/"), fontName);
ImFont *pFont = io.Fonts->AddFontFromFileTTF(fullPath.c_str(), fontSize); ImFont *pFont = io.Fonts->AddFontFromFileTTF(fullPath.c_str(), fontSize, NULL, GetGlyphRanges());
m_vecFonts.push_back({pFont, fontSize, fontMul, std::string(fontName)}); m_vecFonts.push_back({pFont, fontSize, fontMul, std::string(fontName)});
io.Fonts->Build(); io.Fonts->Build();
@ -41,7 +66,7 @@ void FontMgr::ReloadAll()
{ {
size_t fontSize = static_cast<int>(screen::GetScreenHeight() / 54.85f) * data.m_fMul; size_t fontSize = static_cast<int>(screen::GetScreenHeight() / 54.85f) * data.m_fMul;
std::string fullPath = PLUGIN_PATH((char*)FILE_NAME "/fonts/") + data.m_path + ".ttf"; std::string fullPath = PLUGIN_PATH((char*)FILE_NAME "/fonts/") + data.m_path + ".ttf";
data.m_pFont = io.Fonts->AddFontFromFileTTF(fullPath.c_str(), data.m_nSize); data.m_pFont = io.Fonts->AddFontFromFileTTF(fullPath.c_str(), data.m_nSize, NULL, GetGlyphRanges());
} }
io.FontDefault = Get("text"); io.FontDefault = Get("text");
io.Fonts->Build(); io.Fonts->Build();

View File

@ -26,6 +26,9 @@ public:
// Loads a font into memory // Loads a font into memory
static ImFont* Load(const char* fontName, float fontMul = 1.0f); static ImFont* Load(const char* fontName, float fontMul = 1.0f);
// Get the glyph ranges for our needed fonts
static const ImWchar* GetGlyphRanges();
// Unloads all the loaded fonts from fontmgr // Unloads all the loaded fonts from fontmgr
// ImGui::GetIO().Default font must be loaded after unloading all fonts // ImGui::GetIO().Default font must be loaded after unloading all fonts
static void UnloadAll(); static void UnloadAll();

View File

@ -328,6 +328,7 @@ void Menu::ShowPage()
{ {
CheatMenu::ResetMenuSize(); CheatMenu::ResetMenuSize();
} }
ImGui::Spacing(); ImGui::Spacing();
static int selected = Locale::GetCurrentLocaleIndex(); static int selected = Locale::GetCurrentLocaleIndex();