Added support for displaying non-ASCII characters in decoder view

This requires the user to provide a font that supports these characters as well (for example unifont). The default ImGui font does not have them.
This commit is contained in:
WerWolv
2021-02-14 11:51:05 +01:00
parent b4c2f7d371
commit 1eb6f781b3
2 changed files with 20 additions and 8 deletions

View File

@@ -183,7 +183,19 @@ namespace hex {
// Load font data & build atlas
std::uint8_t *px;
int w, h;
io.Fonts->AddFontFromFileTTF(path.string().c_str(), std::floor(14.0f * this->m_fontScale)); // Needs conversion to char for Windows
ImVector<ImWchar> ranges;
ImFontGlyphRangesBuilder glyphRangesBuilder;
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesDefault());
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesJapanese());
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesChineseFull());
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesCyrillic());
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesKorean());
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesThai());
glyphRangesBuilder.AddRanges(io.Fonts->GetGlyphRangesVietnamese());
glyphRangesBuilder.BuildRanges(&ranges);
io.Fonts->AddFontFromFileTTF(path.string().c_str(), std::floor(14.0f * this->m_fontScale), nullptr, ranges.Data); // Needs conversion to char for Windows
ImGuiFreeType::BuildFontAtlas(io.Fonts, ImGuiFreeType::Monochrome);
io.Fonts->GetTexDataAsRGBA32(&px, &w, &h);