-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtryouts.py
More file actions
executable file
·73 lines (62 loc) · 1.89 KB
/
tryouts.py
File metadata and controls
executable file
·73 lines (62 loc) · 1.89 KB
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
#!/usr/bin/env python3
from PIL import Image, ImageDraw, ImageFont
import io, os, sys
# Decoder:
# timR08 = Times R=regular 08=8 points, which depends on dpi
# helvR08 = Helvetica R=regular
# helvR08 = Helvetica R=regular
#
#
# ucs/100dpi/courR08.bdf
# ucs/100dpi/helvR08.bdf
# ucs/100dpi/lubR08.bdf
# ucs/100dpi/ncenR08.bdf
# ucs/100dpi/timR08.bdf
# ucs/unnec_100dpi/UTB___10.bdf
# assets/8x13.bdf <-- nice, but big
#
#def doit(fn = 'assets/6x10.bdf', screen_size=(128, 32)):
def doit(fn = 'assets/zevv-peep-iso8859-15-10x20.bdf', screen_size=(128, 64)):
# lifted from pilfont.py helper script
from PIL import BdfFontFile
p = BdfFontFile.BdfFontFile(open(fn, 'rb'))
# interface of PIL font stuff is dumb; no way to avoid a filesystem file here!
# XXX also not unicode ready!
p.save("tmp-font.pil")
font = ImageFont.load('tmp-font.pil')
tmp = Image.new('L', screen_size, 255)
dd = ImageDraw.Draw(tmp)
w, line_h = font.getsize('Wjp')
y = 0
for msg in [
"12.business",
"13.abstract",
" 13. english",
'/'.join(fn.split('/')[-2:]),
]:
dd.text( (1,y), msg, font=font, fill=0)
y += line_h
tmp = tmp.convert('1')
tmp.save('example.png')
print("Wrote: example.png")
#tmp.show()
def doit_TTF(fn = 'something.ttf', sz=18):
font = ImageFont.truetype(font = fn, size=sz)
tmp = Image.new('L', (128, 128), 255)
dd = ImageDraw.Draw(tmp)
w, line_h = font.getsize('Wjp')
y = 0
for msg in [
"Test: size=%d" % sz,
fn,
"15dmx8pJZhFBNsZhDune6WKJpS7daePn1w",
" - split - ",
"15dmx8pJZhFBNsZh~",
"~Dune6WKJpS7daePn1w",
]:
dd.text( (0,y), msg, font=font, fill=0)
y += line_h
tmp = tmp.convert('1')
tmp.show()
if __name__ == '__main__':
doit(sys.argv[1]) # need BDF on cmd line