-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.c
32 lines (27 loc) · 785 Bytes
/
font.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
* File: font.c
* Author: torsten.roemer@luniks.net
*
* Created on 25. April 2023, 21:00
*/
#include <stdio.h>
#include "font.h"
const __flash Glyph* getGlyphAddress(const __flash Font *font, code_t code) {
// https://en.wikipedia.org/wiki/Binary_search_algorithm
code_t l = 0;
code_t r = font->length - 1;
while (l <= r) {
code_t m = (l + r) / 2;
const __flash Glyph *pglyph = &font->glyphs[m];
if (pglyph->code < code) {
l = m + 1;
} else if (pglyph->code > code) {
r = m - 1;
} else {
// found code point, return address of glyph
return pglyph;
}
}
// return question mark if unknown code point
return getGlyphAddress(font, 0x003f);
}