-
Notifications
You must be signed in to change notification settings - Fork 2
/
rein-font.lua
81 lines (76 loc) · 1.44 KB
/
rein-font.lua
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
local bit = require "bit32"
local cp
local mode = 'cp'
local function printf(fmt, ...)
io.stdout:write(string.format(fmt, ...))
end
local function parse_line(l)
local r = 0
for i=l:len(),1, -1 do
local c = string.byte(l, i)
if c == string.byte '-' or c == string.byte ' ' then
r = r*2
else
r = r*2 + 1
end
end
return r
end
local dict = {}
local cur = 0
local max = 15
local h = 1
print "const uint8_t FONT_data[] PROGMEM ={"
for l in io.lines() do
if mode == 'cp' then
if tonumber(l) then
local nr = tonumber(l)
if not cp or nr ~= cp + 1 then
-- print(l)
table.insert(dict, { off = cur, start = nr, range = 1 })
else
local t = dict[#dict]
t.range = t.range + 1
end
cp = nr
printf("\t")
mode = 'sym'
end
elseif mode == 'sym' then
if l == "" then
mode = 'cp'
h = 1
print()
else
if h <= max then
printf("0x%02x, ", parse_line(l))
cur = cur + 1
end
h = h + 1
end
end
end
print ""
print "};"
print "const uint16_t FONT_map[] = {"
for _, v in ipairs(dict) do
printf("\t%d, 0x%04x, %d,\n", v.off, v.start, v.range)
end
print("\t0, 0, 0,")
print "};"
print [[
struct font8 {
const uint8_t *data;
const uint16_t *map;
const int w;
const int h;
};
#define FONT_W 8
#define FONT_H 15
const struct font8 FONT = {
.data = FONT_data,
.map = FONT_map,
.w = FONT_W,
.h = FONT_H,
};
]]