2020-02-19 12:26:55 +01:00
|
|
|
#!/usr/bin/env python3
|
2018-02-27 00:59:32 +01:00
|
|
|
|
2020-05-28 12:31:15 +02:00
|
|
|
"""Generates the code for a sorted unicode range array as used in hb-ot-os2-unicode-ranges.hh
|
Fix various typos
Found via `codespell -q 3 -S ./perf/texts -L actualy,ba,beng,fo,gir,inout,nd,ot,pres,ro,te,teh,timne`
2022-01-16 13:00:53 +01:00
|
|
|
Input is a tab separated list of unicode ranges from the otspec
|
2020-05-28 12:31:15 +02:00
|
|
|
(https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ur).
|
|
|
|
"""
|
2018-02-27 00:59:32 +01:00
|
|
|
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
2018-10-03 17:27:46 +02:00
|
|
|
print ("""static OS2Range _hb_os2_unicode_ranges[] =
|
2018-02-27 02:48:51 +01:00
|
|
|
{""")
|
2018-02-27 00:59:32 +01:00
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
input_file = args[0]
|
|
|
|
|
2020-05-28 21:41:19 +02:00
|
|
|
with open (input_file, mode="r", encoding="utf-8") as f:
|
2018-02-27 00:59:32 +01:00
|
|
|
|
2020-05-28 12:31:15 +02:00
|
|
|
all_ranges = []
|
2018-02-27 00:59:32 +01:00
|
|
|
current_bit = 0
|
|
|
|
while True:
|
|
|
|
line = f.readline().strip()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
fields = re.split(r'\t+', line)
|
|
|
|
if len(fields) == 3:
|
|
|
|
current_bit = fields[0]
|
|
|
|
fields = fields[1:]
|
|
|
|
elif len(fields) > 3:
|
2018-12-30 12:58:34 +01:00
|
|
|
raise Exception("bad input :(.")
|
2018-02-27 00:59:32 +01:00
|
|
|
|
|
|
|
name = fields[0]
|
|
|
|
ranges = re.split("-", fields[1])
|
|
|
|
if len(ranges) != 2:
|
2018-12-30 12:58:34 +01:00
|
|
|
raise Exception("bad input :(.")
|
2018-02-27 00:59:32 +01:00
|
|
|
|
|
|
|
v = tuple((int(ranges[0], 16), int(ranges[1], 16), int(current_bit), name))
|
|
|
|
all_ranges.append(v)
|
|
|
|
|
|
|
|
all_ranges = sorted(all_ranges, key=lambda t: t[0])
|
|
|
|
|
|
|
|
for ranges in all_ranges:
|
|
|
|
start = ("0x%X" % ranges[0]).rjust(8)
|
|
|
|
end = ("0x%X" % ranges[1]).rjust(8)
|
|
|
|
bit = ("%s" % ranges[2]).rjust(3)
|
|
|
|
|
2018-03-29 10:18:47 +02:00
|
|
|
print (" {%s, %s, %s}, // %s" % (start, end, bit, ranges[3]))
|
2018-02-27 00:59:32 +01:00
|
|
|
|
2018-03-29 10:18:47 +02:00
|
|
|
print ("""};""")
|