This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
forked from RazorbladeByte/ddhack
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakefixed.py
67 lines (59 loc) · 2.01 KB
/
makefixed.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
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
import xml.dom.minidom
import re
from PIL import Image
print "#include <hash_map>"
print
print "static unsigned char *fixed_data[0x7f - 0x20];"
print "static unsigned int fixed_width[0x7f - 0x20];"
print "static unsigned int fixed_height[0x7f - 0x20];"
print "static unsigned int fixed_aw[0x7f - 0x20];"
print "static std::hash_map<short, int> fixed_kernings;"
print
print "#define X 1,"
print "#define _ 0,"
print
im = Image.open("test-0.png")
doc = xml.dom.minidom.parse("test.xml")
for i in doc.getElementsByTagName("glyph"):
r = re.compile('[,x]')
charcode = int(i.getAttribute("code"), 16)
x, y = r.split(i.getAttribute("origin"))
width, height = r.split(i.getAttribute("size"))
x = int(x)
y = int(y)
width = int(width)
height = int(height)
aw = int(i.getAttribute("aw"))
print "static unsigned char fixed_{:02x}_data[] = {{".format(charcode)
for j in range(y, y + height):
for k in range(x, x + width):
pixel = im.getpixel((k, j))
if pixel == (0, 0, 0, 0):
pixel = "_"
else:
pixel = "X"
print "{}".format(pixel),
print
print "};"
print "static unsigned int fixed_{:02x}_width = {};".format(charcode, width)
print "static unsigned int fixed_{:02x}_height = {};".format(charcode, height)
print "static unsigned int fixed_{:02x}_aw = {};".format(charcode, aw)
print
print "#undef X"
print "#undef _"
print
print "void fixed_kernings_setup()"
print "{"
for i in range(0x20, 0x7f):
print " fixed_data[{:#04x}] = fixed_{:02x}_data;".format(i - 0x20, i)
print " fixed_width[{:#04x}] = fixed_{:02x}_width;".format(i - 0x20, i)
print " fixed_height[{:#04x}] = fixed_{:02x}_height;".format(i - 0x20, i)
print " fixed_aw[{:#04x}] = fixed_{:02x}_aw;".format(i - 0x20, i)
print
for i in doc.getElementsByTagName("kernpair"):
left = ord(i.getAttribute("left"))
right = ord(i.getAttribute("right"))
adjust = int(i.getAttribute("adjust"))
kerncode = left | (right << 8)
print " fixed_kernings[{:#06x}] = {};".format(kerncode, adjust)
print "}"