Imported Upstream version 2.3.1
[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
8 if len (sys.argv) != 2:
9         print("usage: ./gen-emoji-table.py emoji-data.txt", file=sys.stderr)
10         sys.exit (1)
11
12 f = open(sys.argv[1])
13 header = [f.readline () for _ in range(10)]
14
15 ranges = OrderedDict()
16 for line in f.readlines():
17         line = line.strip()
18         if not line or line[0] == '#':
19                 continue
20         rang, typ = [s.strip() for s in line.split('#')[0].split(';')[:2]]
21
22         rang = [int(s, 16) for s in rang.split('..')]
23         if len(rang) > 1:
24                 start, end = rang
25         else:
26                 start = end = rang[0]
27
28         if typ not in ranges:
29                 ranges[typ] = []
30         if ranges[typ] and ranges[typ][-1][1] == start - 1:
31                 ranges[typ][-1] = (ranges[typ][-1][0], end)
32         else:
33                 ranges[typ].append((start, end))
34
35
36
37 print ("/* == Start of generated table == */")
38 print ("/*")
39 print (" * The following tables are generated by running:")
40 print (" *")
41 print (" *   ./gen-emoji-table.py emoji-data.txt")
42 print (" *")
43 print (" * on file with this header:")
44 print (" *")
45 for l in header:
46         print (" * %s" % (l.strip()))
47 print (" */")
48 print ()
49 print ("#ifndef HB_UNICODE_EMOJI_TABLE_HH")
50 print ("#define HB_UNICODE_EMOJI_TABLE_HH")
51 print ()
52 print ('#include "hb-unicode.hh"')
53 print ()
54
55 for typ,s in ranges.items():
56         if typ != "Extended_Pictographic": continue
57         print()
58         print("static const struct hb_unicode_range_t _hb_unicode_emoji_%s_table[] =" % typ)
59         print("{")
60         for pair in sorted(s):
61                 print("  {0x%04X, 0x%04X}," % pair)
62         print("};")
63
64 print ()
65 print ("#endif /* HB_UNICODE_EMOJI_TABLE_HH */")
66 print ()
67 print ("/* == End of generated table == */")