@@ -37,6 +37,17 @@ typedef struct ImgObject
37
37
unsigned char * data;
38
38
} ImgObject;
39
39
40
+ enum ExtImGuiGlyphRanges {
41
+ ExtImGuiGlyphRanges_Default,
42
+ ExtImGuiGlyphRanges_Greek,
43
+ ExtImGuiGlyphRanges_Korean,
44
+ ExtImGuiGlyphRanges_Japanese,
45
+ ExtImGuiGlyphRanges_ChineseFull,
46
+ ExtImGuiGlyphRanges_ChineseSimplifiedCommon,
47
+ ExtImGuiGlyphRanges_Cyrillic,
48
+ ExtImGuiGlyphRanges_Thai,
49
+ ExtImGuiGlyphRanges_Vietnamese
50
+ };
40
51
41
52
static bool g_imgui_NewFrame = false ;
42
53
static char * g_imgui_TextBuffer = 0 ;
@@ -2242,14 +2253,55 @@ static ImFont* imgui_GetFont(int index)
2242
2253
return 0 ;
2243
2254
}
2244
2255
2256
+ ImWchar* LuaToGlyphRanges (lua_State * L, int index) {
2257
+ const ImWchar* glyph_ranges = NULL ;
2258
+ if (!lua_isnil (L, index)) {
2259
+ ImGuiIO& io = ImGui::GetIO ();
2260
+ ExtImGuiGlyphRanges range = (ExtImGuiGlyphRanges)lua_tointeger (L, index);
2261
+ switch (range) {
2262
+ case ExtImGuiGlyphRanges_Greek:
2263
+ glyph_ranges = io.Fonts ->GetGlyphRangesGreek ();
2264
+ break ;
2265
+ case ExtImGuiGlyphRanges_Korean:
2266
+ glyph_ranges = io.Fonts ->GetGlyphRangesKorean ();
2267
+ break ;
2268
+ case ExtImGuiGlyphRanges_Japanese:
2269
+ glyph_ranges = io.Fonts ->GetGlyphRangesJapanese ();
2270
+ break ;
2271
+ case ExtImGuiGlyphRanges_ChineseFull:
2272
+ glyph_ranges = io.Fonts ->GetGlyphRangesChineseFull ();
2273
+ break ;
2274
+ case ExtImGuiGlyphRanges_ChineseSimplifiedCommon:
2275
+ glyph_ranges = io.Fonts ->GetGlyphRangesChineseSimplifiedCommon ();
2276
+ break ;
2277
+ case ExtImGuiGlyphRanges_Cyrillic:
2278
+ glyph_ranges = io.Fonts ->GetGlyphRangesCyrillic ();
2279
+ break ;
2280
+ case ExtImGuiGlyphRanges_Thai:
2281
+ glyph_ranges = io.Fonts ->GetGlyphRangesThai ();
2282
+ break ;
2283
+ case ExtImGuiGlyphRanges_Vietnamese:
2284
+ glyph_ranges = io.Fonts ->GetGlyphRangesVietnamese ();
2285
+ break ;
2286
+ default :
2287
+ case ExtImGuiGlyphRanges_Default:
2288
+ glyph_ranges = io.Fonts ->GetGlyphRangesDefault ();
2289
+ break ;
2290
+ }
2291
+ }
2292
+ return (ImWchar*)glyph_ranges;
2293
+ }
2294
+
2245
2295
static int imgui_FontAddTTFFile (lua_State * L)
2246
2296
{
2247
2297
DM_LUA_STACK_CHECK (L, 1 );
2248
2298
const char * ttf_filename = luaL_checkstring (L, 1 );
2249
2299
float font_size = luaL_checknumber (L, 2 );
2300
+ const ImFontConfig* font_cfg = NULL ;
2301
+ const ImWchar* glyph_ranges = LuaToGlyphRanges (L, 3 );
2250
2302
2251
2303
ImGuiIO& io = ImGui::GetIO ();
2252
- ImFont* font = io.Fonts ->AddFontFromFileTTF (ttf_filename, font_size);
2304
+ ImFont* font = io.Fonts ->AddFontFromFileTTF (ttf_filename, font_size, font_cfg, glyph_ranges );
2253
2305
// Put font in map.
2254
2306
if (font != NULL )
2255
2307
{
@@ -2270,12 +2322,14 @@ static int imgui_FontAddTTFData(lua_State * L)
2270
2322
int ttf_data_size = luaL_checknumber (L, 2 );
2271
2323
float font_size = luaL_checknumber (L, 3 );
2272
2324
int font_pixels = luaL_checknumber (L, 4 );
2325
+ const ImFontConfig* font_cfg = NULL ;
2326
+ const ImWchar* glyph_ranges = LuaToGlyphRanges (L, 5 );
2273
2327
2274
2328
char *ttf_data_cpy = (char *)calloc (ttf_data_size, sizeof (char ));
2275
2329
memcpy (ttf_data_cpy, ttf_data, ttf_data_size);
2276
2330
2277
2331
ImGuiIO& io = ImGui::GetIO ();
2278
- ImFont* font = io.Fonts ->AddFontFromMemoryTTF ((void *)ttf_data_cpy, ttf_data_size, font_pixels);
2332
+ ImFont* font = io.Fonts ->AddFontFromMemoryTTF ((void *)ttf_data_cpy, ttf_data_size, font_pixels, font_cfg, glyph_ranges );
2279
2333
// Put font in map.
2280
2334
if (font != NULL )
2281
2335
{
@@ -2670,6 +2724,7 @@ static const luaL_reg Module_methods[] =
2670
2724
{" set_key_modifier_alt" , imgui_SetKeyModifierAlt},
2671
2725
{" set_key_modifier_super" , imgui_SetKeyModifierSuper},
2672
2726
{" add_input_character" , imgui_AddInputCharacter},
2727
+ {" add_input_characters" , imgui_AddInputCharacters},
2673
2728
{" want_mouse_input" , imgui_WantCaptureMouse},
2674
2729
{" want_keyboard_input" , imgui_WantCaptureKeyboard},
2675
2730
{" want_text_input" , imgui_WantCaptureText},
@@ -2988,6 +3043,16 @@ static void LuaInit(lua_State* L)
2988
3043
lua_setfieldstringint (L, " DIR_UP" , ImGuiDir_Up);
2989
3044
lua_setfieldstringint (L, " DIR_DOWN" , ImGuiDir_Down);
2990
3045
3046
+ lua_setfieldstringint (L, " GLYPH_RANGES_DEFAULT" , ExtImGuiGlyphRanges_Default); // Basic Latin, Extended Latin
3047
+ lua_setfieldstringint (L, " GLYPH_RANGES_GREEK" , ExtImGuiGlyphRanges_Greek); // Default + Greek and Coptic
3048
+ lua_setfieldstringint (L, " GLYPH_RANGES_KOREAN" , ExtImGuiGlyphRanges_Korean); // Default + Korean characters
3049
+ lua_setfieldstringint (L, " GLYPH_RANGES_JAPANESE" , ExtImGuiGlyphRanges_Japanese); // Default + Hiragana, Katakana, Half-Width, Selection of 2999 Ideographs
3050
+ lua_setfieldstringint (L, " GLYPH_RANGES_CHINESEFULL" , ExtImGuiGlyphRanges_ChineseFull); // Default + Half-Width + Japanese Hiragana/Katakana + full set of about 21000 CJK Unified Ideographs
3051
+ lua_setfieldstringint (L, " GLYPH_RANGES_CHINESESIMPLIFIEDCOMMON" , ExtImGuiGlyphRanges_ChineseSimplifiedCommon);// Default + Half-Width + Japanese Hiragana/Katakana + set of 2500 CJK Unified Ideographs for common simplified Chinese
3052
+ lua_setfieldstringint (L, " GLYPH_RANGES_CYRILLIC" , ExtImGuiGlyphRanges_Cyrillic); // Default + about 400 Cyrillic characters
3053
+ lua_setfieldstringint (L, " GLYPH_RANGES_THAI" , ExtImGuiGlyphRanges_Thai); // Default + Thai characters
3054
+ lua_setfieldstringint (L, " GLYPH_RANGES_VIETNAMESE" , ExtImGuiGlyphRanges_Vietnamese); // Default + Vietnamese characters
3055
+
2991
3056
lua_pop (L, 1 );
2992
3057
assert (top == lua_gettop (L));
2993
3058
}
0 commit comments