diff --git a/src/renderer.cpp b/src/renderer.cpp index 53eb8d25..1bcb9e5f 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -42,24 +42,15 @@ namespace big 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); + file font_file_path = windows_fonts.get_file("./msyh.ttc"); + if (!font_file_path.exists()) + font_file_path = windows_fonts.get_file("./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); font_file.seekg(0); - 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.read(reinterpret_cast(font_data.get()), font_data_size); font_file.close(); auto& io = ImGui::GetIO(); @@ -71,8 +62,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(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->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(); } @@ -83,8 +74,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(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->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(); } @@ -95,8 +86,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(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->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(); } @@ -107,8 +98,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(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->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(); }