diff util.c @ 1572:5efeca06d942

Scale UI font size based on window size and start basing widget sizes based on font size
author Michael Pavone <pavone@retrodev.com>
date Tue, 24 Apr 2018 20:31:18 -0700
parents e94cff9cb625
children 7121daaa48c2
line wrap: on
line diff
--- a/util.c	Sat Apr 21 14:48:01 2018 -0700
+++ b/util.c	Tue Apr 24 20:31:18 2018 -0700
@@ -248,6 +248,41 @@
 	return out;
 }
 
+int utf8_codepoint(const char **text)
+{
+	uint8_t initial = **text;
+	(*text)++;
+	if (initial < 0x80) {
+		return initial;
+	}
+	int base;
+	uint8_t extended_bytes;
+	if ((initial & 0xE0) == 0xC0) {
+		base = 0x80;
+		initial &= 0x1F;
+		extended_bytes = 1;
+	} else if ((initial & 0xF0) == 0xE0) {
+		base = 0x800;
+		initial &= 0xF;
+		extended_bytes = 2;
+	} else if ((initial & 0xF8) == 0xF0) {
+		base = 0x10000;
+		initial &= 0x7;
+		extended_bytes = 3;
+	}
+	int value = initial;
+	for (uint8_t i = 0; i < extended_bytes; i++)
+	{
+		if ((**text & 0xC0) != 0x80) {
+			return -1;
+		}
+		value = value << 6;
+		value |= (**text) & 0x3F;
+		(*text)++;
+	}
+	return value + base;
+}
+
 char is_path_sep(char c)
 {
 #ifdef _WIN32