blob: d768313dddea86a085e00bfa4e673fe720b8d36c [file] [log] [blame]
Garret Riegerddc4f2b2018-02-26 15:59:32 -08001# -*- coding: utf-8 -*-
2
3# Generates the code for a sorted unicode range array as used in hb-ot-os2-unicode-ranges.hh
Garret Riegerf1c8fc32018-02-26 17:48:51 -08004# Input is a tab seperated list of unicode ranges from the otspec
5# (https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ulunicoderange1).
Garret Riegerddc4f2b2018-02-26 15:59:32 -08006
Ebrahim Byagowicab2c2c2018-03-29 12:48:47 +04307from __future__ import print_function, division, absolute_import
8
Garret Riegerddc4f2b2018-02-26 15:59:32 -08009import io
10import re
11import sys
12
13reload(sys)
14sys.setdefaultencoding('utf-8')
15
Behdad Esfahbod1dc601b2018-10-03 17:27:46 +020016print ("""static OS2Range _hb_os2_unicode_ranges[] =
Garret Riegerf1c8fc32018-02-26 17:48:51 -080017{""")
Garret Riegerddc4f2b2018-02-26 15:59:32 -080018
19args = sys.argv[1:]
20input_file = args[0]
21
22with io.open(input_file, mode="r", encoding="utf-8") as f:
23
24 all_ranges = [];
25 current_bit = 0
26 while True:
27 line = f.readline().strip()
28 if not line:
29 break
30 fields = re.split(r'\t+', line)
31 if len(fields) == 3:
32 current_bit = fields[0]
33 fields = fields[1:]
34 elif len(fields) > 3:
35 raise Error("bad input :(.")
36
37 name = fields[0]
38 ranges = re.split("-", fields[1])
39 if len(ranges) != 2:
40 raise Error("bad input :(.")
41
42 v = tuple((int(ranges[0], 16), int(ranges[1], 16), int(current_bit), name))
43 all_ranges.append(v)
44
45all_ranges = sorted(all_ranges, key=lambda t: t[0])
46
47for ranges in all_ranges:
48 start = ("0x%X" % ranges[0]).rjust(8)
49 end = ("0x%X" % ranges[1]).rjust(8)
50 bit = ("%s" % ranges[2]).rjust(3)
51
Ebrahim Byagowicab2c2c2018-03-29 12:48:47 +043052 print (" {%s, %s, %s}, // %s" % (start, end, bit, ranges[3]))
Garret Riegerddc4f2b2018-02-26 15:59:32 -080053
Ebrahim Byagowicab2c2c2018-03-29 12:48:47 +043054print ("""};""")