summaryrefslogtreecommitdiff
path: root/scripts/glyphdump.py
blob: a63df95fb67f627051b3950e3c7646f4725e11fd (plain)
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
74
75
76
77
#!/usr/bin/python

import sys

agl = []
agltab = []
aglmap = {}

print "/*"

f = open("glyphlist.txt", "r")
for line in f.readlines():
	if line[0] == '#':
		print line.strip()
		continue
	line = line[:-1]
	name, list = line.split(';')
	list = map(lambda x: int(x, 16), list.split(' '))
	agl.append((name, list))

for name, ucslist in agl:
	num = len(ucslist)
	ucs = ucslist[0]
	agltab.append((name, ucs))
	if ucs not in aglmap:
		aglmap[ucs] = []
	aglmap[ucs].append(name)

print "*/"
print

def dumplist(list):
	n = 0;
	for item in list:
		n += len(item) + 1
		if n > 78:
			sys.stdout.write("\n")
			n = len(item) + 1
		sys.stdout.write(item)
		sys.stdout.write(",")
	sys.stdout.write("\n")

agltab.sort()
namelist = []
codelist = []
for name, ucs in agltab:
	namelist.append("\"%s\"" % name)
	codelist.append("%d" % ucs)

keys = aglmap.keys()
keys.sort()
dupoffsets = []
dupnames = []
for ucs in keys:
	list = aglmap[ucs]
	ofs = len(dupnames)
	if len(list) > 1:
		dupoffsets.append("%d,%d" % (ucs, ofs))
		for name in list:
			dupnames.append("\"%s\"" % name)
		dupnames.append("0")

print "static const char *agl_name_list[] = {"
dumplist(namelist)
print "};"
print
print "static const unsigned short agl_code_list[] = {"
dumplist(codelist)
print "};"
print
print "static const unsigned short agl_dup_offsets[] = {"
dumplist(dupoffsets)
print "};"
print
print "static const char *agl_dup_names[] = {"
dumplist(dupnames)
print "};"