From 4e294162fbed6bc5674b4795b8d133092badc0aa Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Mon, 19 Feb 2024 05:37:00 -0500 Subject: [PATCH] Added Korean font support. (#2718) --- src/renderer.cpp | 53 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/src/renderer.cpp b/src/renderer.cpp index 4d314750..3ac5f29c 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -34,23 +34,34 @@ namespace big ImGui_ImplDX11_Init(m_d3d_device, m_d3d_device_context); ImGui_ImplWin32_Init(g_pointers->m_hwnd); - folder windows_fonts(std::filesystem::path(std::getenv("SYSTEMROOT")) / "Fonts"); + const auto fonts_folder = std::filesystem::path(std::getenv("SYSTEMROOT")) / "Fonts"; - file font_file_path = windows_fonts.get_file("./msyh.ttc"); - if (!font_file_path.exists()) - font_file_path = windows_fonts.get_file("./msyh.ttf"); - if (!font_file_path.exists()) + file font_file(fonts_folder / "msyh.ttc"); + if (!font_file.exists()) + font_file = file(fonts_folder / "msyh.ttf"); + + if (*g_pointers->m_gta.m_language == 8) + { + font_file = file(fonts_folder / "malgun.ttf"); + if (!font_file.exists()) + { + LOG(WARNING) << "Korean language detected, but failed to find Korean font, you may not be able to read the menu!"; + } + } + + if (!font_file.exists()) { LOG(WARNING) << "Failed to find msyh font, falling back to Arial!"; - font_file_path = windows_fonts.get_file("./arial.ttf"); + font_file = file(fonts_folder / "arial.ttf"); } - auto font_file = std::ifstream(font_file_path.get_path(), std::ios::binary | std::ios::ate); - const auto font_data_size = static_cast(font_file.tellg()); + + auto font_file_stream = std::ifstream(font_file.get_path(), std::ios::binary | std::ios::ate); + const auto font_data_size = static_cast(font_file_stream.tellg()); const auto font_data = std::make_unique(font_data_size); - font_file.seekg(0); - font_file.read(reinterpret_cast(font_data.get()), font_data_size); - font_file.close(); + font_file_stream.seekg(0); + font_file_stream.read(reinterpret_cast(font_data.get()), font_data_size); + font_file_stream.close(); auto& io = ImGui::GetIO(); @@ -65,7 +76,10 @@ namespace big &fnt_cfg, io.Fonts->GetGlyphRangesDefault()); fnt_cfg.MergeMode = true; - io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 20.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); + if (*g_pointers->m_gta.m_language == 8) + io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 20.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesKorean()); + else + io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 20.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 20.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic()); io.Fonts->Build(); } @@ -77,7 +91,10 @@ namespace big g.window.font_title = io.Fonts->AddFontFromMemoryTTF(const_cast(font_storopia), sizeof(font_storopia), 28.f, &fnt_cfg); fnt_cfg.MergeMode = true; - io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 28.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); + if (*g_pointers->m_gta.m_language == 8) + io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 28.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesKorean()); + else + io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 28.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 28.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic()); io.Fonts->Build(); } @@ -89,7 +106,10 @@ namespace big g.window.font_sub_title = io.Fonts->AddFontFromMemoryTTF(const_cast(font_storopia), sizeof(font_storopia), 24.f, &fnt_cfg); fnt_cfg.MergeMode = true; - io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 24.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); + if (*g_pointers->m_gta.m_language == 8) + io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 24.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesKorean()); + else + io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 24.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 24.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic()); io.Fonts->Build(); } @@ -101,7 +121,10 @@ namespace big g.window.font_small = io.Fonts->AddFontFromMemoryTTF(const_cast(font_storopia), sizeof(font_storopia), 18.f, &fnt_cfg); fnt_cfg.MergeMode = true; - io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 18.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); + if (*g_pointers->m_gta.m_language == 8) + io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 18.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesKorean()); + else + io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 18.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); io.Fonts->AddFontFromMemoryTTF(font_data.get(), font_data_size, 18.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic()); io.Fonts->Build(); }