Skip to content

Commit 936b900

Browse files
committed
Add TranslateCommonGlyphRanges / C++ & Python
1 parent b868908 commit 936b900

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/hello_imgui/hello_imgui_font.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ namespace HelloImGui
88
{
99
using ImWcharPair = std::array<ImWchar, 2>;
1010

11-
// Utility to translate DearImGui common Unicode ranges to ImWcharPair
12-
// (GetGlyphRangesJapanese, GetGlyphRangesChinese, GetGlyphRangesCyrillic, ...)
13-
std::vector<ImWcharPair> TranslateCommonGlyphRanges(const std::vector<ImWchar> & glyphRanges);
11+
// Utility to translate DearImGui common Unicode ranges to ImWcharPair (Python)
12+
// (get_glyph_ranges_chinese_simplified_common, get_glyph_ranges_japanese, ...)
13+
std::vector<ImWcharPair> translate_common_glyph_ranges(const std::vector<ImWchar> & glyphRanges);
14+
15+
// Utility to translate DearImGui common Unicode ranges to ImWcharPair (C++)
16+
// (GetGlyphRangesChineseSimplifiedCommon, GetGlyphRangesJapanese, ...)
17+
std::vector<ImWcharPair> TranslateCommonGlyphRanges(const ImWchar* glyphRanges);
1418

1519
// @@md#Fonts
1620

src/hello_imgui/impl/hello_imgui_font.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,20 @@ namespace HelloImGui
328328
return HelloImGui::gDidCallHelloImGuiLoadFontTTF;
329329
}
330330

331-
// Utility to translate DearImGui common Unicode ranges to ImWcharPair
332-
// (GetGlyphRangesJapanese, GetGlyphRangesChinese, GetGlyphRangesCyrillic, ...)
333-
std::vector<ImWcharPair> TranslateCommonGlyphRanges(const std::vector<ImWchar> & glyphRanges)
331+
std::vector<ImWcharPair> TranslateCommonGlyphRanges(const ImWchar* glyphRanges)
332+
{
333+
std::vector<ImWcharPair> glyphRangesPairs;
334+
size_t idx = 0;
335+
while (glyphRanges[idx] != 0)
336+
{
337+
ImWcharPair glyphRangePair = {glyphRanges[idx], glyphRanges[idx + 1]};
338+
glyphRangesPairs.push_back(glyphRangePair);
339+
idx += 2;
340+
}
341+
return glyphRangesPairs;
342+
}
343+
344+
std::vector<ImWcharPair> translate_common_glyph_ranges(const std::vector<ImWchar> & glyphRanges)
334345
{
335346
std::vector<ImWcharPair> glyphRangesPairs;
336347
for (size_t i = 0; i < glyphRanges.size(); i += 2)

0 commit comments

Comments
 (0)