root / proj / font / split_font.py @ 182
History | View | Annotate | Download (920 Bytes)
1 |
import os |
---|---|
2 |
import glob |
3 |
from PIL import Image |
4 |
|
5 |
im = Image.open("Consolas.png")
|
6 |
|
7 |
W, H = im.size |
8 |
|
9 |
Nw = 16
|
10 |
Nh = 6
|
11 |
|
12 |
i = 32
|
13 |
|
14 |
with open("font.h", 'w') as f: |
15 |
includes = ""
|
16 |
lst = ""
|
17 |
|
18 |
for j in range(i): |
19 |
if lst != "": lst += "," |
20 |
lst += "NULL"
|
21 |
|
22 |
|
23 |
for h in range(Nh): |
24 |
t = int(H/Nh)*h
|
25 |
b = int(H/Nh)*(h+1) |
26 |
for w in range(Nw): |
27 |
#l = int((W*w)/Nw)
|
28 |
#r = int((W*(w+1))/Nw)
|
29 |
l = 59*w
|
30 |
r = 59*(w+1) |
31 |
im1 = im.crop((l,t,r,b)) |
32 |
im1.save("png/ascii%03d.png"%i)
|
33 |
os.system("convert png/ascii%03d.png xpm/ascii%03d.xpm"%(i,i))
|
34 |
|
35 |
|
36 |
includes += '#include "%03d.xpm"\n'%i
|
37 |
if lst != "": lst += "," |
38 |
lst += "%03d_xpm"%i
|
39 |
|
40 |
#DEV
|
41 |
os.system("rm png/ascii%03d.png"%i)
|
42 |
|
43 |
i += 1
|
44 |
|
45 |
f.write(includes) |
46 |
f.write("xpm_map_t font[] = {"+lst+"}\n") |