-
Notifications
You must be signed in to change notification settings - Fork 0
/
genfont.py
executable file
·33 lines (33 loc) · 1.01 KB
/
genfont.py
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
#!/usr/bin/env python3
import binascii
f = open("font.bin", "wb")
f.write(b"FONT")
fin = open("unifont.hex", "r")
lines = fin.readlines()
font = {}
for l in lines:
font[int.from_bytes(binascii.unhexlify(
l[:4]), byteorder="big")] = binascii.unhexlify(l[5:-1])
f.write(len(font).to_bytes(4, byteorder="little"))
f.write(int(16).to_bytes(4, byteorder="little"))
f.write(int(0).to_bytes(4, byteorder="little"))
for id, fo in font.items():
fullwidth = True
if len(fo) == 16:
fullwidth = False
temp = b''
for b in fo:
temp += bytes([b, 0])
fo = temp
f.write(int(8).to_bytes(4, byteorder="little"))
else:
f.write(int(16).to_bytes(4, byteorder="little"))
temp = b''
for i in range(16):
b = '{:016b}'.format(int.from_bytes(
bytes([fo[i * 2 + 1], fo[i * 2]]), byteorder="little"))
temp += int(b[::-1], 2).to_bytes(2, byteorder="little")
f.write(id.to_bytes(4, byteorder="little"))
f.write(temp)
f.close()
fin.close()