From c4f84e1969f4c856a5bf0352e99fcb73a4cf56cf Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 8 Nov 2021 16:03:02 +0100 Subject: Do not check for valid utf8 in set text, render the invalid utf8 instead. Mmap fonts instead of loading the whole font --- src/system/utf8.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/system/utf8.c') diff --git a/src/system/utf8.c b/src/system/utf8.c index 35b0f2f..201fedf 100644 --- a/src/system/utf8.c +++ b/src/system/utf8.c @@ -20,19 +20,31 @@ static inline bool utf8_get_codepoint_length(unsigned char b, size_t *codepoint_ /* TODO: Optimize (remove branching, etc) */ bool mgl_utf8_decode(const unsigned char *str, size_t size, uint32_t *decoded_codepoint, size_t *codepoint_length) { - if(size == 0) + if(size == 0) { + *decoded_codepoint = 0; + *codepoint_length = 0; return false; + } size_t clen; - if(!utf8_get_codepoint_length(str[0], &clen)) + if(!utf8_get_codepoint_length(str[0], &clen)) { + *decoded_codepoint = str[0]; + *codepoint_length = 1; return false; + } - if(size < clen) + if(size < clen) { + *decoded_codepoint = str[0]; + *codepoint_length = 1; return false; + } for(size_t i = 1; i < clen; ++i) { - if((str[i] & 0xC0) != 0x80) + if((str[i] & 0xC0) != 0x80) { + *decoded_codepoint = str[0]; + *codepoint_length = 1; return false; + } } uint32_t codepoint; -- cgit v1.2.3