Fixed broken patch
[platform/upstream/harfbuzz.git] / src / gen-emoji-table.py
1 #!/usr/bin/python
2
3 from __future__ import print_function, division, absolute_import
4 import sys
5 import os.path
6 from collections import OrderedDict
7 import packTab
8
9 if len (sys.argv) != 2:
10         print("usage: ./gen-emoji-table.py emoji-data.txt", file=sys.stderr)
11         sys.exit (1)
12
13 f = open(sys.argv[1])
14 header = [f.readline () for _ in range(10)]
15
16 ranges = OrderedDict()
17 for line in f.readlines():
18         line = line.strip()
19         if not line or line[0] == '#':
20                 continue
21         rang, typ = [s.strip() for s in line.split('#')[0].split(';')[:2]]
22
23         rang = [int(s, 16) for s in rang.split('..')]
24         if len(rang) > 1:
25                 start, end = rang
26         else:
27                 start = end = rang[0]
28
29         if typ not in ranges:
30                 ranges[typ] = []
31         if ranges[typ] and ranges[typ][-1][1] == start - 1:
32                 ranges[typ][-1] = (ranges[typ][-1][0], end)
33         else:
34                 ranges[typ].append((start, end))
35
36
37
38 print ("/* == Start of generated table == */")
39 print ("/*")
40 print (" * The following tables are generated by running:")
41 print (" *")
42 print (" *   ./gen-emoji-table.py emoji-data.txt")
43 print (" *")
44 print (" * on file with this header:")
45 print (" *")
46 for l in header:
47         print (" * %s" % (l.strip()))
48 print (" */")
49 print ()
50 print ("#ifndef HB_UNICODE_EMOJI_TABLE_HH")
51 print ("#define HB_UNICODE_EMOJI_TABLE_HH")
52 print ()
53 print ('#include "hb-unicode.hh"')
54 print ()
55
56 for typ, s in ranges.items():
57         if typ != "Extended_Pictographic": continue
58
59         arr = dict()
60         for start,end in s:
61                 for i in range(start,end):
62                         arr[i] = 1
63
64         sol = packTab.pack_table(arr, 0, compression=3)
65         code = packTab.Code('_hb_emoji')
66         sol.genCode(code, 'is_'+typ)
67         code.print_c(linkage='static inline')
68         print()
69
70 print ()
71 print ("#endif /* HB_UNICODE_EMOJI_TABLE_HH */")
72 print ()
73 print ("/* == End of generated table == */")