From 2a041cfbe17314d4d70b703183ca54bc14ef3659 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 23 Jun 2015 14:13:22 -0600 Subject: [PATCH] Added GetGlyphRangesCyrillic() helper (#237) --- imgui.cpp | 18 ++++++++++++++++-- imgui.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index eca97695..3c360aaf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -17,7 +17,7 @@ - Why is my text output blurry? - How can I load a different font than the default? - How can I load multiple fonts? - - How can I display and input Chinese, Japanese, Korean characters? + - How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic? - ISSUES & TODO-LIST - CODE - SAMPLE CODE @@ -309,7 +309,8 @@ // the first loaded font gets used by default // use ImGui::PushFont()/ImGui::PopFont() to change the font at runtime - Q: How can I render and input Chinese, Japanese, Korean characters? + + Q: How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic? A: When loading a font, pass custom Unicode ranges to specify the glyphs to load. ImGui will support UTF-8 encoding across the board. Character input depends on you passing the right character code to io.AddInputCharacter(). The example applications do that. @@ -9737,6 +9738,19 @@ const ImWchar* ImFontAtlas::GetGlyphRangesJapanese() return &ranges[0]; } +const ImWchar* ImFontAtlas::GetGlyphRangesCyrillic() +{ + static const ImWchar ranges[] = + { + 0x0020, 0x00FF, // Basic Latin + Latin Supplement + 0x0400, 0x052F, // Cyrillic + Cyrillic Supplement + 0x2DE0, 0x2DFF, // Cyrillic Extended-A + 0xA640, 0xA69F, // Cyrillic Extended-B + 0, + }; + return &ranges[0]; +} + void ImFont::BuildLookupTable() { int max_codepoint = 0; diff --git a/imgui.h b/imgui.h index 8d6baf25..b0b5914d 100644 --- a/imgui.h +++ b/imgui.h @@ -1089,6 +1089,7 @@ struct ImFontAtlas IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs IMGUI_API const ImWchar* GetGlyphRangesChinese(); // Japanese + full set of about 21000 CJK Unified Ideographs + IMGUI_API const ImWchar* GetGlyphRangesCyrillic(); // Default + about 400 Cyrillic characters // Members // (Access texture data via GetTexData*() calls which will setup a default font for you.)