diff --git a/src/renderer.cpp b/src/renderer.cpp index 5a425220..53eb8d25 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -38,15 +38,28 @@ namespace big ImGui_ImplDX11_Init(m_d3d_device.Get(), m_d3d_device_context.Get()); ImGui_ImplWin32_Init(g_pointers->m_hwnd); - file font_file_path("C:/Windows/Fonts/msyh.ttc"); - if (!font_file_path.exists()) - font_file_path = { "C:/Windows/Fonts/msyh.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()); - const auto font_data = std::make_unique(font_data_size); + folder windows_fonts( + std::filesystem::path(std::getenv("SYSTEMROOT")) / "Fonts" + ); + + file chinese_font_file = windows_fonts.get_file("./msyh.ttc"); + if (!chinese_font_file.exists()) + chinese_font_file = windows_fonts.get_file("./msyh.ttf"); + auto font_file = std::ifstream(chinese_font_file.get_path(), std::ios::binary | std::ios::ate); + const auto chinese_font_data_size = static_cast(font_file.tellg()); + const auto chinese_font_data = std::make_unique(chinese_font_data_size); font_file.seekg(0); - font_file.read(reinterpret_cast(font_data.get()), font_data_size); + font_file.read(reinterpret_cast(chinese_font_data.get()), chinese_font_data_size); + font_file.close(); + + file cyrillic_font_file = windows_fonts.get_file("./Segoeui.ttf"); + font_file.open(cyrillic_font_file.get_path(), std::ios::binary | std::ios::ate); + const auto cyrillic_font_data_size = static_cast(font_file.tellg()); + const auto cyrillic_font_data = std::make_unique(cyrillic_font_data_size); + + font_file.seekg(0); + font_file.read(reinterpret_cast(cyrillic_font_data.get()), cyrillic_font_data_size); font_file.close(); auto& io = ImGui::GetIO(); @@ -58,7 +71,8 @@ namespace big io.Fonts->AddFontFromMemoryTTF(const_cast(font_storopia), sizeof(font_storopia), 20.f, &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()); + io.Fonts->AddFontFromMemoryTTF(chinese_font_data.get(), chinese_font_data_size, 20.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); + io.Fonts->AddFontFromMemoryTTF(cyrillic_font_data.get(), cyrillic_font_data_size, 20.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic()); io.Fonts->Build(); } @@ -69,7 +83,8 @@ 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()); + io.Fonts->AddFontFromMemoryTTF(chinese_font_data.get(), chinese_font_data_size, 28.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); + io.Fonts->AddFontFromMemoryTTF(cyrillic_font_data.get(), cyrillic_font_data_size, 28.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic()); io.Fonts->Build(); } @@ -80,7 +95,8 @@ 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()); + io.Fonts->AddFontFromMemoryTTF(chinese_font_data.get(), chinese_font_data_size, 24.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); + io.Fonts->AddFontFromMemoryTTF(cyrillic_font_data.get(), cyrillic_font_data_size, 24.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic()); io.Fonts->Build(); } @@ -91,7 +107,8 @@ 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()); + io.Fonts->AddFontFromMemoryTTF(chinese_font_data.get(), chinese_font_data_size, 18.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesChineseSimplifiedCommon()); + io.Fonts->AddFontFromMemoryTTF(cyrillic_font_data.get(), cyrillic_font_data_size, 18.f, &fnt_cfg, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic()); io.Fonts->Build(); }