Skip to content

Commit

Permalink
Add TranslateCommonGlyphRanges / C++ & Python
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jul 7, 2024
1 parent b868908 commit 936b900
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/hello_imgui/hello_imgui_font.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ namespace HelloImGui
{
using ImWcharPair = std::array<ImWchar, 2>;

// Utility to translate DearImGui common Unicode ranges to ImWcharPair
// (GetGlyphRangesJapanese, GetGlyphRangesChinese, GetGlyphRangesCyrillic, ...)
std::vector<ImWcharPair> TranslateCommonGlyphRanges(const std::vector<ImWchar> & glyphRanges);
// Utility to translate DearImGui common Unicode ranges to ImWcharPair (Python)
// (get_glyph_ranges_chinese_simplified_common, get_glyph_ranges_japanese, ...)
std::vector<ImWcharPair> translate_common_glyph_ranges(const std::vector<ImWchar> & glyphRanges);

// Utility to translate DearImGui common Unicode ranges to ImWcharPair (C++)
// (GetGlyphRangesChineseSimplifiedCommon, GetGlyphRangesJapanese, ...)
std::vector<ImWcharPair> TranslateCommonGlyphRanges(const ImWchar* glyphRanges);

// @@md#Fonts

Expand Down
17 changes: 14 additions & 3 deletions src/hello_imgui/impl/hello_imgui_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,20 @@ namespace HelloImGui
return HelloImGui::gDidCallHelloImGuiLoadFontTTF;
}

// Utility to translate DearImGui common Unicode ranges to ImWcharPair
// (GetGlyphRangesJapanese, GetGlyphRangesChinese, GetGlyphRangesCyrillic, ...)
std::vector<ImWcharPair> TranslateCommonGlyphRanges(const std::vector<ImWchar> & glyphRanges)
std::vector<ImWcharPair> TranslateCommonGlyphRanges(const ImWchar* glyphRanges)
{
std::vector<ImWcharPair> glyphRangesPairs;
size_t idx = 0;
while (glyphRanges[idx] != 0)
{
ImWcharPair glyphRangePair = {glyphRanges[idx], glyphRanges[idx + 1]};
glyphRangesPairs.push_back(glyphRangePair);
idx += 2;
}
return glyphRangesPairs;
}

std::vector<ImWcharPair> translate_common_glyph_ranges(const std::vector<ImWchar> & glyphRanges)
{
std::vector<ImWcharPair> glyphRangesPairs;
for (size_t i = 0; i < glyphRanges.size(); i += 2)
Expand Down

0 comments on commit 936b900

Please sign in to comment.