-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconvert-font.py
More file actions
executable file
·49 lines (37 loc) · 944 Bytes
/
convert-font.py
File metadata and controls
executable file
·49 lines (37 loc) · 944 Bytes
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
#!/usr/bin/python
import PIL.Image
f = PIL.Image.open("font-src.png")
(w,h) = f.size
d = f.getdata()
inventory = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.!?@/:;()#abcdefghijklmnopqrstuvwxyz,=^|-_+'\""
charData = ['0'] * (8*8*128)
def getRow(x,offset):
global charData
global d
endMarker = False
for y in range(7):
i = w*y + x
if d[i] == (255,0,0):
endMarker = True
elif d[i] == (0,0,0):
charData[offset+y] = '1'
else:
charData[offset+y] = '0'
return not endMarker
x = 0
for c in inventory:
offset = ord(c)*8*8
more = True
while more:
more = getRow(x,offset)
if not more:
charData[offset+7] = '1'
x = x + 1
offset = offset + 8
print """
#include "hfont.h"
uint8_t charData[] PROGMEM = {"""
for i in range(8*128):
sub = charData[i*8:(i+1)*8]
print " 0b"+"".join(sub)+","
print "};"