commit 8dc8932

seiko  ·  2026-05-29 13:32:58 +0000 UTC
parent 7a5f4cd
add bdf detection
1 files changed,  +55, -0
+55, -0
 1@@ -1,10 +1,65 @@
 2+#include <ctype.h>
 3 #include <math.h>
 4+#include <stdio.h>
 5 #include <stdlib.h>
 6 #include <string.h>
 7 
 8 #include "font.h"
 9 #include "schrift.h"
10 
11+static int strcicmp(char const* a, char const* b);
12+static int type(const char* path);
13+
14+/**
15+ * @brief case insensitive string compare
16+ *
17+ * @param a string1 to compare
18+ * @param b string2 to compare
19+ *
20+ * @return -1=(a<b), 0=(a==b), 1=(a>b)
21+ */
22+static int strcicmp(char const* a, char const* b)
23+{
24+	int la;
25+	int lb;
26+	while (*a && *b) {
27+		la = tolower((unsigned char)*a);
28+		lb = tolower((unsigned char)*b);
29+		if (la != lb)
30+			return la - lb;
31+		a++;
32+		b++;
33+	}
34+
35+	return tolower((unsigned char)*a) - tolower((unsigned char)*b);
36+}
37+
38+/**
39+ * @brief determine the type of font being used
40+ * 
41+ * @note only BDF or !BDF right now
42+ *
43+ * @param path path to font
44+ *
45+ * @return -1=failed to determine, 0=BDF, 1=!BDF
46+ */
47+static int type(const char* path)
48+{
49+	size_t pl = strlen(path);
50+
51+	if (pl < 3)
52+		return -1;
53+
54+	char ext[4];
55+	memcpy(ext, path + pl - 3, 3);
56+	ext[3] = '\0';
57+
58+	if (strcicmp(ext, "bdf") == 0)
59+		return 0; /* BDF */
60+
61+	return 1; /* not BDF */
62+}
63+
64 int font_load(Fontface* f, const char* path, double size)
65 {
66 	SFT_LMetrics lm;