-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfont2png.py
More file actions
executable file
·49 lines (36 loc) · 874 Bytes
/
Copy pathfont2png.py
File metadata and controls
executable file
·49 lines (36 loc) · 874 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/env python
import sys, struct, string
import Image
if len(sys.argv) <= 1:
print 'Usage: %s font.bin font.png' % sys.argv[0]
sys.exit(1)
f = open(sys.argv[1], 'rb')
def tobitarray(bs):
bits = ''.join(bin(ord(b))[2:].zfill(8) for b in bs)
return map(int, bits)
header = f.read(6)
w, h, start, end, u1, u2 = map(ord, header)
hbytes = h / 8
n = 0
data = []
charws = []
while True:
charw = f.read(1)
if len(charw) == 0:
break
charws.append(ord(charw))
for i in range(w):
col = reversed(f.read(hbytes))
data += tobitarray(col)
n += 1
# gap
data += [0] * 8 * hbytes
n += 1
img = Image.new('1', (8 * hbytes, n))
img.putdata(data)
img = img.rotate(90)
img.save(sys.argv[2], 'PNG')
print 'Bitmap size: %dx%d' % (w, h)
print 'Characters: %s-%s' % (start, end)
print 'Unknown: %d, %d' % (u1, u2)
print 'Widths: %s' % charws