Make gen-use-table.py py3 compatible (#932)
This commit is contained in:
parent
1c3372786c
commit
a48dd6ef23
|
@ -1,9 +1,10 @@
|
|||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
|
||||
if len (sys.argv) != 5:
|
||||
print >>sys.stderr, "usage: ./gen-use-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt UnicodeData.txt Blocks.txt"
|
||||
print ("usage: ./gen-use-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt UnicodeData.txt Blocks.txt", file=sys.stderr)
|
||||
sys.exit (1)
|
||||
|
||||
BLACKLISTED_BLOCKS = ["Thai", "Lao", "Tibetan"]
|
||||
|
@ -352,21 +353,21 @@ def map_to_use(data):
|
|||
defaults = ('O', 'No_Block')
|
||||
data = map_to_use(data)
|
||||
|
||||
print "/* == Start of generated table == */"
|
||||
print "/*"
|
||||
print " * The following table is generated by running:"
|
||||
print " *"
|
||||
print " * ./gen-use-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt UnicodeData.txt Blocks.txt"
|
||||
print " *"
|
||||
print " * on files with these headers:"
|
||||
print " *"
|
||||
print ("/* == Start of generated table == */")
|
||||
print ("/*")
|
||||
print (" * The following table is generated by running:")
|
||||
print (" *")
|
||||
print (" * ./gen-use-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt UnicodeData.txt Blocks.txt")
|
||||
print (" *")
|
||||
print (" * on files with these headers:")
|
||||
print (" *")
|
||||
for h in headers:
|
||||
for l in h:
|
||||
print " * %s" % (l.strip())
|
||||
print " */"
|
||||
print
|
||||
print '#include "hb-ot-shape-complex-use-private.hh"'
|
||||
print
|
||||
print (" * %s" % (l.strip()))
|
||||
print (" */")
|
||||
print ()
|
||||
print ('#include "hb-ot-shape-complex-use-private.hh"')
|
||||
print ()
|
||||
|
||||
total = 0
|
||||
used = 0
|
||||
|
@ -374,22 +375,22 @@ last_block = None
|
|||
def print_block (block, start, end, data):
|
||||
global total, used, last_block
|
||||
if block and block != last_block:
|
||||
print
|
||||
print
|
||||
print " /* %s */" % block
|
||||
print ()
|
||||
print ()
|
||||
print (" /* %s */" % block)
|
||||
if start % 16:
|
||||
print ' ' * (20 + (start % 16 * 6)),
|
||||
print (' ' * (20 + (start % 16 * 6)), end='')
|
||||
num = 0
|
||||
assert start % 8 == 0
|
||||
assert (end+1) % 8 == 0
|
||||
for u in range (start, end+1):
|
||||
if u % 16 == 0:
|
||||
print
|
||||
print " /* %04X */" % u,
|
||||
print ()
|
||||
print (" /* %04X */" % u, end='')
|
||||
if u in data:
|
||||
num += 1
|
||||
d = data.get (u, defaults)
|
||||
sys.stdout.write ("%6s," % d[0])
|
||||
print ("%6s," % d[0], end='')
|
||||
|
||||
total += end - start + 1
|
||||
used += num
|
||||
|
@ -406,14 +407,14 @@ starts = []
|
|||
ends = []
|
||||
for k,v in sorted(use_mapping.items()):
|
||||
if k in use_positions and use_positions[k]: continue
|
||||
print "#define %s USE_%s /* %s */" % (k, k, v.__name__[3:])
|
||||
print ("#define %s USE_%s /* %s */" % (k, k, v.__name__[3:]))
|
||||
for k,v in sorted(use_positions.items()):
|
||||
if not v: continue
|
||||
for suf in v.keys():
|
||||
tag = k + suf
|
||||
print "#define %s USE_%s" % (tag, tag)
|
||||
print ""
|
||||
print "static const USE_TABLE_ELEMENT_TYPE use_table[] = {"
|
||||
print ("#define %s USE_%s" % (tag, tag))
|
||||
print ("")
|
||||
print ("static const USE_TABLE_ELEMENT_TYPE use_table[] = {")
|
||||
for u in uu:
|
||||
if u <= last:
|
||||
continue
|
||||
|
@ -433,51 +434,51 @@ for u in uu:
|
|||
if last >= 0:
|
||||
ends.append (last + 1)
|
||||
offset += ends[-1] - starts[-1]
|
||||
print
|
||||
print
|
||||
print "#define use_offset_0x%04xu %d" % (start, offset)
|
||||
print ()
|
||||
print ()
|
||||
print ("#define use_offset_0x%04xu %d" % (start, offset))
|
||||
starts.append (start)
|
||||
|
||||
print_block (block, start, end, data)
|
||||
last = end
|
||||
ends.append (last + 1)
|
||||
offset += ends[-1] - starts[-1]
|
||||
print
|
||||
print
|
||||
print ()
|
||||
print ()
|
||||
occupancy = used * 100. / total
|
||||
page_bits = 12
|
||||
print "}; /* Table items: %d; occupancy: %d%% */" % (offset, occupancy)
|
||||
print
|
||||
print "USE_TABLE_ELEMENT_TYPE"
|
||||
print "hb_use_get_category (hb_codepoint_t u)"
|
||||
print "{"
|
||||
print " switch (u >> %d)" % page_bits
|
||||
print " {"
|
||||
print ("}; /* Table items: %d; occupancy: %d%% */" % (offset, occupancy))
|
||||
print ()
|
||||
print ("USE_TABLE_ELEMENT_TYPE")
|
||||
print ("hb_use_get_category (hb_codepoint_t u)")
|
||||
print ("{")
|
||||
print (" switch (u >> %d)" % page_bits)
|
||||
print (" {")
|
||||
pages = set([u>>page_bits for u in starts+ends])
|
||||
for p in sorted(pages):
|
||||
print " case 0x%0Xu:" % p
|
||||
print (" case 0x%0Xu:" % p)
|
||||
for (start,end) in zip (starts, ends):
|
||||
if p not in [start>>page_bits, end>>page_bits]: continue
|
||||
offset = "use_offset_0x%04xu" % start
|
||||
print " if (hb_in_range<hb_codepoint_t> (u, 0x%04Xu, 0x%04Xu)) return use_table[u - 0x%04Xu + %s];" % (start, end-1, start, offset)
|
||||
print " break;"
|
||||
print ""
|
||||
print " default:"
|
||||
print " break;"
|
||||
print " }"
|
||||
print " return USE_O;"
|
||||
print "}"
|
||||
print
|
||||
print (" if (hb_in_range<hb_codepoint_t> (u, 0x%04Xu, 0x%04Xu)) return use_table[u - 0x%04Xu + %s];" % (start, end-1, start, offset))
|
||||
print (" break;")
|
||||
print ("")
|
||||
print (" default:")
|
||||
print (" break;")
|
||||
print (" }")
|
||||
print (" return USE_O;")
|
||||
print ("}")
|
||||
print ()
|
||||
for k in sorted(use_mapping.keys()):
|
||||
if k in use_positions and use_positions[k]: continue
|
||||
print "#undef %s" % k
|
||||
print ("#undef %s" % k)
|
||||
for k,v in sorted(use_positions.items()):
|
||||
if not v: continue
|
||||
for suf in v.keys():
|
||||
tag = k + suf
|
||||
print "#undef %s" % tag
|
||||
print
|
||||
print "/* == End of generated table == */"
|
||||
print ("#undef %s" % tag)
|
||||
print ()
|
||||
print ("/* == End of generated table == */")
|
||||
|
||||
# Maintain at least 50% occupancy in the table */
|
||||
if occupancy < 50:
|
||||
|
|
Loading…
Reference in New Issue