aboutsummaryrefslogtreecommitdiff
path: root/src/system
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-17 03:15:16 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-17 03:15:16 +0100
commitc18f87ad13da518af5ff245dbce2a9e608097ea1 (patch)
tree3ca8a22df68fc1ef7ecd7b9ec449a733b76de67a /src/system
parentccd0e65a0ddccd9c52d4c075ec1cad41ae7edb40 (diff)
Attempt to fix font glyph texture overlap by aligning texture size to
next character size Add function to get the start of a utf8 codepoint (backwards), test utf8 functions
Diffstat (limited to 'src/system')
-rw-r--r--src/system/utf8.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/system/utf8.c b/src/system/utf8.c
index 201fedf..5d5ec79 100644
--- a/src/system/utf8.c
+++ b/src/system/utf8.c
@@ -73,3 +73,20 @@ bool mgl_utf8_decode(const unsigned char *str, size_t size, uint32_t *decoded_co
*decoded_codepoint = codepoint;
return true;
}
+
+/* TODO: Optimize (remove branching, etc) */
+size_t mgl_utf8_get_start_of_codepoint(const unsigned char *str, size_t size, size_t offset) {
+ if(size == 0)
+ return 0;
+
+ if(offset > size - 1)
+ offset = size - 1;
+
+ /* i <= offset is an overflow (underflow?) check */
+ for(size_t i = offset; i <= offset; --i) {
+ if((str[i] & 0xC0) != 0x80)
+ return i;
+ }
+
+ return 0;
+}