1 # -*- coding: utf-8 -*-
3 # Generates the code for a sorted unicode range array as used in hb-ot-os2-unicode-ranges.hh
4 # Input is a tab seperated list of unicode ranges from the otspec
5 # (https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ulunicoderange1).
7 from __future__ import print_function, division, absolute_import
15 sys.setdefaultencoding('utf-8')
19 print ("""static OS2Range _hb_os2_unicode_ranges[] =
25 with io.open(input_file, mode="r", encoding="utf-8") as f:
30 line = f.readline().strip()
33 fields = re.split(r'\t+', line)
35 current_bit = fields[0]
38 raise Exception("bad input :(.")
41 ranges = re.split("-", fields[1])
43 raise Exception("bad input :(.")
45 v = tuple((int(ranges[0], 16), int(ranges[1], 16), int(current_bit), name))
48 all_ranges = sorted(all_ranges, key=lambda t: t[0])
50 for ranges in all_ranges:
51 start = ("0x%X" % ranges[0]).rjust(8)
52 end = ("0x%X" % ranges[1]).rjust(8)
53 bit = ("%s" % ranges[2]).rjust(3)
55 print (" {%s, %s, %s}, // %s" % (start, end, bit, ranges[3]))