feat(Renderer): Added Cyrillic to ImGui font (#578)

This commit is contained in:
Yimura 2022-11-11 23:48:19 +01:00 committed by GitHub
parent aca084109a
commit 6c65b534ec

View File

@ -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<int>(font_file.tellg());
const auto font_data = std::make_unique<std::uint8_t[]>(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<int>(font_file.tellg());
const auto chinese_font_data = std::make_unique<std::uint8_t[]>(chinese_font_data_size);
font_file.seekg(0);
font_file.read(reinterpret_cast<char*>(font_data.get()), font_data_size);
font_file.read(reinterpret_cast<char*>(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<int>(font_file.tellg());
const auto cyrillic_font_data = std::make_unique<std::uint8_t[]>(cyrillic_font_data_size);
font_file.seekg(0);
font_file.read(reinterpret_cast<char*>(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<std::uint8_t*>(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<std::uint8_t*>(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<std::uint8_t*>(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<std::uint8_t*>(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();
}