Skip to content
Rykehuss edited this page Apr 20, 2017 · 5 revisions

One of Nuklear significant features is UTF-8 support. For use it you may complete several steps: 1. Obtain font, which contain characters you may use.

2. Create glyph range table for your language. As [example](https://gist.github.com/vaiorabbit/e36c7c04f7f3dddadf14653f31eb3faf) for Japanese (thanks to [vaiorabbit](https://gist.github.com/vaiorabbit)):

`const nk_rune nk_font_japanese_glyph_ranges[] = {'

' 0x0020, 0x00FF,`

{{{` 0x2200, 0x22FF, // Mathematical Operators`}}} {{{` 0x3000, 0x303F, // CJK Symbols and Punctuation`}}} {{{` 0x3040, 0x309F, // Hiragana`}}} {{{` 0x30A0, 0x30FF, // Katakana`}}} {{{` 0x0370, 0x03FF, // Greek and Coptic`}}} {{{` 0xFF00, 0xFFEF, // Halfwidth and Fullwidth Forms`}}} {{{` 0x4E00, 0x9FFF, // CJK Unified Ideographs`}}} {{{` 0`}}} {{{`};`}}}

Nuklear have some functions for creating glyph codepoint's by default: `nk_font_chinese_glyph_ranges()` for Chinese `nk_font_cyrillic_glyph_ranges()` for Cirillic `nk_font_korean_glyph_ranges()` for Korean

3. Create nk_font_config structure: `struct nk_font_config config = nk_font_config(14);` `config.oversample_h = 1;` `config.oversample_v = 1;`

4. Set glyph range table to config

  • for built-in functions `config.range = nk_font_cyrillic_glyph_ranges();`
  • for custom table `config.range = &nk_font_japanese_glyph_ranges[0];`

5. Load font with customized config `nk_sdl_font_stash_begin(&atlas);` `struct nk_font *ubuntu = nk_font_atlas_add_from_file(atlas, "path_to_your_font", 14, &config);` `nk_sdl_font_stash_end();` `nk_style_set_font(ctx, &ubuntu->handle);`

Thats all! Now you can use UTF-8 encoding symbols in your's apps. `if (nk_button_label(ctx, u8"Кнопка"))` ` fprintf(stdout, "button pressed\n");`

Clone this wiki locally