From 936b900e6b2ca02e4d6130e98dc7a89f01c72e44 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Sun, 7 Jul 2024 08:56:04 +0200 Subject: [PATCH] Add TranslateCommonGlyphRanges / C++ & Python --- src/hello_imgui/hello_imgui_font.h | 10 +++++++--- src/hello_imgui/impl/hello_imgui_font.cpp | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/hello_imgui/hello_imgui_font.h b/src/hello_imgui/hello_imgui_font.h index bd3df407..0e9ed949 100644 --- a/src/hello_imgui/hello_imgui_font.h +++ b/src/hello_imgui/hello_imgui_font.h @@ -8,9 +8,13 @@ namespace HelloImGui { using ImWcharPair = std::array; - // Utility to translate DearImGui common Unicode ranges to ImWcharPair - // (GetGlyphRangesJapanese, GetGlyphRangesChinese, GetGlyphRangesCyrillic, ...) - std::vector TranslateCommonGlyphRanges(const std::vector & glyphRanges); + // Utility to translate DearImGui common Unicode ranges to ImWcharPair (Python) + // (get_glyph_ranges_chinese_simplified_common, get_glyph_ranges_japanese, ...) + std::vector translate_common_glyph_ranges(const std::vector & glyphRanges); + + // Utility to translate DearImGui common Unicode ranges to ImWcharPair (C++) + // (GetGlyphRangesChineseSimplifiedCommon, GetGlyphRangesJapanese, ...) + std::vector TranslateCommonGlyphRanges(const ImWchar* glyphRanges); // @@md#Fonts diff --git a/src/hello_imgui/impl/hello_imgui_font.cpp b/src/hello_imgui/impl/hello_imgui_font.cpp index e7c2bfe1..039e4463 100644 --- a/src/hello_imgui/impl/hello_imgui_font.cpp +++ b/src/hello_imgui/impl/hello_imgui_font.cpp @@ -328,9 +328,20 @@ namespace HelloImGui return HelloImGui::gDidCallHelloImGuiLoadFontTTF; } - // Utility to translate DearImGui common Unicode ranges to ImWcharPair - // (GetGlyphRangesJapanese, GetGlyphRangesChinese, GetGlyphRangesCyrillic, ...) - std::vector TranslateCommonGlyphRanges(const std::vector & glyphRanges) + std::vector TranslateCommonGlyphRanges(const ImWchar* glyphRanges) + { + std::vector 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 translate_common_glyph_ranges(const std::vector & glyphRanges) { std::vector glyphRangesPairs; for (size_t i = 0; i < glyphRanges.size(); i += 2)