diff options
author | Michael Pavone <pavone@retrodev.com> | 2018-03-06 21:27:12 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2018-03-06 21:27:12 -0800 |
commit | d738c30dec8a7c9f351094851c00a4623f339084 (patch) | |
tree | d74219313a54b16466a53f4be180093cd5775a02 /util.c | |
parent | 94b11b186fa4cf46c64bc3fad55f74c7b5096ffe (diff) |
Added support for TTC and dfont format true type fonts. More robust font selection on Windows
--HG--
branch : nuklear_ui
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -204,6 +204,50 @@ void bin_to_hex(uint8_t *output, uint8_t *input, uint64_t size) *(output++) = 0; } +char *utf16be_to_utf8(uint8_t *buf, uint32_t max_size) +{ + uint8_t *cur = buf; + uint32_t converted_size = 0; + for (uint32_t i = 0; i < max_size; i++, cur+=2) + { + uint16_t code = *cur << 16 | cur[1]; + if (!code) { + break; + } + if (code < 0x80) { + converted_size++; + } else if (code < 0x800) { + converted_size += 2; + } else { + //TODO: Deal with surrogate pairs + converted_size += 3; + } + } + char *out = malloc(converted_size + 1); + char *cur_out = out; + cur = buf; + for (uint32_t i = 0; i < max_size; i++, cur+=2) + { + uint16_t code = *cur << 16 | cur[1]; + if (!code) { + break; + } + if (code < 0x80) { + *(cur_out++) = code; + } else if (code < 0x800) { + *(cur_out++) = 0xC0 | code >> 6; + *(cur_out++) = 0x80 | (code & 0x3F); + } else { + //TODO: Deal with surrogate pairs + *(cur_out++) = 0xF0 | code >> 12; + *(cur_out++) = 0x80 | (code >> 6 & 0x3F); + *(cur_out++) = 0x80 | (code & 0x3F); + } + } + *cur_out = 0; + return out; +} + char is_path_sep(char c) { #ifdef _WIN32 |