Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

UTF 8 Support

Rykehuss edited this page Apr 20, 2017 · 33 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 for Japanese (thanks to 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
};

---Glyphs ranges for different languages and variedsymbol you can find there.

---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
  1. Create nk_font_config structure:
struct nk_font_config config = nk_font_config(14);
config.oversample_h = 1;
config.oversample_v = 1;
  1. 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];
  1. Load font with customized config
nk_sdl_font_stash_begin(&atlas);
struct nk_font *font = nk_font_atlas_add_from_file(atlas, "path_to_your_font", 14, &config);
nk_sdl_font_stash_end();
nk_style_set_font(ctx, &font->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");

UTF-8 Demo

Clone this wiki locally