未验证 提交 cab2c2c0 编写于 作者: E Ebrahim Byagowi 提交者: GitHub

Make more gen-* scripts py3 compatible (#940)

上级 5f7f0bfa
...@@ -295,7 +295,7 @@ arabic-table: gen-arabic-table.py ArabicShaping.txt UnicodeData.txt Blocks.txt ...@@ -295,7 +295,7 @@ arabic-table: gen-arabic-table.py ArabicShaping.txt UnicodeData.txt Blocks.txt
$(AM_V_GEN) $(builddir)/$^ > hb-ot-shape-complex-arabic-table.hh \ $(AM_V_GEN) $(builddir)/$^ > hb-ot-shape-complex-arabic-table.hh \
|| ($(RM) hb-ot-shape-complex-arabic-table.hh; false) || ($(RM) hb-ot-shape-complex-arabic-table.hh; false)
indic-table: gen-indic-table.py IndicSyllabicCategory-7.0.0.txt IndicMatraCategory-7.0.0.txt Blocks.txt indic-table: gen-indic-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt Blocks.txt
$(AM_V_GEN) $(builddir)/$^ > hb-ot-shape-complex-indic-table.cc \ $(AM_V_GEN) $(builddir)/$^ > hb-ot-shape-complex-indic-table.cc \
|| ($(RM) hb-ot-shape-complex-indic-table.cc; false) || ($(RM) hb-ot-shape-complex-indic-table.cc; false)
......
#!/usr/bin/python #!/usr/bin/env python
from __future__ import print_function, division, absolute_import
import sys import sys
import os.path import os.path
if len (sys.argv) != 4: if len (sys.argv) != 4:
print >>sys.stderr, "usage: ./gen-arabic-table.py ArabicShaping.txt UnicodeData.txt Blocks.txt" print ("usage: ./gen-arabic-table.py ArabicShaping.txt UnicodeData.txt Blocks.txt", file=sys.stderr)
sys.exit (1) sys.exit (1)
files = [file (x) for x in sys.argv[1:]] files = [file (x) for x in sys.argv[1:]]
...@@ -65,9 +67,9 @@ def print_joining_table(f): ...@@ -65,9 +67,9 @@ def print_joining_table(f):
assert short not in short_value.values() assert short not in short_value.values()
short_value[value] = short short_value[value] = short
print print ()
for value,short in short_value.items(): for value,short in short_value.items():
print "#define %s %s" % (short, value) print ("#define %s %s" % (short, value))
uu = sorted(values.keys()) uu = sorted(values.keys())
num = len(values) num = len(values)
...@@ -82,15 +84,15 @@ def print_joining_table(f): ...@@ -82,15 +84,15 @@ def print_joining_table(f):
ranges.append([u,u]) ranges.append([u,u])
last = u last = u
print print ()
print "static const uint8_t joining_table[] =" print ("static const uint8_t joining_table[] =")
print "{" print ("{")
last_block = None last_block = None
offset = 0 offset = 0
for start,end in ranges: for start,end in ranges:
print print ()
print "#define joining_offset_0x%04xu %d" % (start, offset) print ("#define joining_offset_0x%04xu %d" % (start, offset))
for u in range(start, end+1): for u in range(start, end+1):
...@@ -99,53 +101,53 @@ def print_joining_table(f): ...@@ -99,53 +101,53 @@ def print_joining_table(f):
if block != last_block or u == start: if block != last_block or u == start:
if u != start: if u != start:
print print ()
if block in all_blocks: if block in all_blocks:
print "\n /* %s */" % block print ("\n /* %s */" % block)
else: else:
print "\n /* FILLER */" print ("\n /* FILLER */")
last_block = block last_block = block
if u % 32 != 0: if u % 32 != 0:
print print ()
print " /* %04X */" % (u//32*32), " " * (u % 32), print (" /* %04X */" % (u//32*32), " " * (u % 32), end="")
if u % 32 == 0: if u % 32 == 0:
print print ()
print " /* %04X */ " % u, print (" /* %04X */ " % u, end="")
sys.stdout.write("%s," % short_value[value]) print ("%s," % short_value[value], end="")
print print ()
offset += end - start + 1 offset += end - start + 1
print print ()
occupancy = num * 100. / offset occupancy = num * 100. / offset
print "}; /* Table items: %d; occupancy: %d%% */" % (offset, occupancy) print ("}; /* Table items: %d; occupancy: %d%% */" % (offset, occupancy))
print print ()
page_bits = 12; page_bits = 12;
print print ()
print "static unsigned int" print ("static unsigned int")
print "joining_type (hb_codepoint_t u)" print ("joining_type (hb_codepoint_t u)")
print "{" print ("{")
print " switch (u >> %d)" % page_bits print (" switch (u >> %d)" % page_bits)
print " {" print (" {")
pages = set([u>>page_bits for u in [s for s,e in ranges]+[e for s,e in ranges]]) pages = set([u>>page_bits for u in [s for s,e in ranges]+[e for s,e in ranges]])
for p in sorted(pages): for p in sorted(pages):
print " case 0x%0Xu:" % p print (" case 0x%0Xu:" % p)
for (start,end) in ranges: for (start,end) in ranges:
if p not in [start>>page_bits, end>>page_bits]: continue if p not in [start>>page_bits, end>>page_bits]: continue
offset = "joining_offset_0x%04xu" % start offset = "joining_offset_0x%04xu" % start
print " if (hb_in_range<hb_codepoint_t> (u, 0x%04Xu, 0x%04Xu)) return joining_table[u - 0x%04Xu + %s];" % (start, end, start, offset) print (" if (hb_in_range<hb_codepoint_t> (u, 0x%04Xu, 0x%04Xu)) return joining_table[u - 0x%04Xu + %s];" % (start, end, start, offset))
print " break;" print (" break;")
print "" print ("")
print " default:" print (" default:")
print " break;" print (" break;")
print " }" print (" }")
print " return X;" print (" return X;")
print "}" print ("}")
print print ()
for value,short in short_value.items(): for value,short in short_value.items():
print "#undef %s" % (short) print ("#undef %s" % (short))
print print ()
def print_shaping_table(f): def print_shaping_table(f):
...@@ -186,9 +188,9 @@ def print_shaping_table(f): ...@@ -186,9 +188,9 @@ def print_shaping_table(f):
shapes[items[0]] = {} shapes[items[0]] = {}
shapes[items[0]][shape] = c shapes[items[0]][shape] = c
print print ()
print "static const uint16_t shaping_table[][4] =" print ("static const uint16_t shaping_table[][4] =")
print "{" print ("{")
keys = shapes.keys () keys = shapes.keys ()
min_u, max_u = min (keys), max (keys) min_u, max_u = min (keys), max (keys)
...@@ -196,13 +198,13 @@ def print_shaping_table(f): ...@@ -196,13 +198,13 @@ def print_shaping_table(f):
s = [shapes[u][shape] if u in shapes and shape in shapes[u] else 0 s = [shapes[u][shape] if u in shapes and shape in shapes[u] else 0
for shape in ['initial', 'medial', 'final', 'isolated']] for shape in ['initial', 'medial', 'final', 'isolated']]
value = ', '.join ("0x%04Xu" % c for c in s) value = ', '.join ("0x%04Xu" % c for c in s)
print " {%s}, /* U+%04X %s */" % (value, u, names[u] if u in names else "") print (" {%s}, /* U+%04X %s */" % (value, u, names[u] if u in names else ""))
print "};" print ("};")
print print ()
print "#define SHAPING_TABLE_FIRST 0x%04Xu" % min_u print ("#define SHAPING_TABLE_FIRST 0x%04Xu" % min_u)
print "#define SHAPING_TABLE_LAST 0x%04Xu" % max_u print ("#define SHAPING_TABLE_LAST 0x%04Xu" % max_u)
print print ()
ligas = {} ligas = {}
for pair in ligatures.keys (): for pair in ligatures.keys ():
...@@ -218,52 +220,51 @@ def print_shaping_table(f): ...@@ -218,52 +220,51 @@ def print_shaping_table(f):
ligas[liga[0]] = [] ligas[liga[0]] = []
ligas[liga[0]].append ((liga[1], c)) ligas[liga[0]].append ((liga[1], c))
max_i = max (len (ligas[l]) for l in ligas) max_i = max (len (ligas[l]) for l in ligas)
print print ()
print "static const struct ligature_set_t {" print ("static const struct ligature_set_t {")
print " uint16_t first;" print (" uint16_t first;")
print " struct ligature_pairs_t {" print (" struct ligature_pairs_t {")
print " uint16_t second;" print (" uint16_t second;")
print " uint16_t ligature;" print (" uint16_t ligature;")
print " } ligatures[%d];" % max_i print (" } ligatures[%d];" % max_i)
print "} ligature_table[] =" print ("} ligature_table[] =")
print "{" print ("{")
keys = ligas.keys () keys = ligas.keys ()
keys.sort () keys.sort ()
for first in keys: for first in keys:
print " { 0x%04Xu, {" % (first) print (" { 0x%04Xu, {" % (first))
for liga in ligas[first]: for liga in ligas[first]:
print " { 0x%04Xu, 0x%04Xu }, /* %s */" % (liga[0], liga[1], names[liga[1]]) print (" { 0x%04Xu, 0x%04Xu }, /* %s */" % (liga[0], liga[1], names[liga[1]]))
print " }}," print (" }},")
print "};" print ("};")
print print ()
print "/* == Start of generated table == */" print ("/* == Start of generated table == */")
print "/*" print ("/*")
print " * The following table is generated by running:" print (" * The following table is generated by running:")
print " *" print (" *")
print " * ./gen-arabic-table.py ArabicShaping.txt UnicodeData.txt Blocks.txt" print (" * ./gen-arabic-table.py ArabicShaping.txt UnicodeData.txt Blocks.txt")
print " *" print (" *")
print " * on files with these headers:" print (" * on files with these headers:")
print " *" print (" *")
for h in headers: for h in headers:
for l in h: for l in h:
print " * %s" % (l.strip()) print (" * %s" % (l.strip()))
print " */" print (" */")
print print ()
print "#ifndef HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH" print ("#ifndef HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH")
print "#define HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH" print ("#define HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH")
print print ()
read_blocks (files[2]) read_blocks (files[2])
print_joining_table (files[0]) print_joining_table (files[0])
print_shaping_table (files[1]) print_shaping_table (files[1])
print print ()
print "#endif /* HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH */" print ("#endif /* HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH */")
print print ()
print "/* == End of generated table == */" print ("/* == End of generated table == */")
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function, division, absolute_import
import io, os, re, sys import io, os, re, sys
......
#!/usr/bin/python #!/usr/bin/env python
from __future__ import print_function, division, absolute_import
import sys import sys
if len (sys.argv) != 4: if len (sys.argv) != 4:
print >>sys.stderr, "usage: ./gen-indic-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt Blocks.txt" print ("usage: ./gen-indic-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt Blocks.txt", file=sys.stderr)
sys.exit (1) sys.exit (1)
ALLOWED_SINGLES = [0x00A0, 0x25CC] ALLOWED_SINGLES = [0x00A0, 0x25CC]
...@@ -87,21 +89,21 @@ for u in ALLOWED_SINGLES: ...@@ -87,21 +89,21 @@ for u in ALLOWED_SINGLES:
singles[u] = data[u] singles[u] = data[u]
del data[u] del data[u]
print "/* == Start of generated table == */" print ("/* == Start of generated table == */")
print "/*" print ("/*")
print " * The following table is generated by running:" print (" * The following table is generated by running:")
print " *" print (" *")
print " * ./gen-indic-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt Blocks.txt" print (" * ./gen-indic-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt Blocks.txt")
print " *" print (" *")
print " * on files with these headers:" print (" * on files with these headers:")
print " *" print (" *")
for h in headers: for h in headers:
for l in h: for l in h:
print " * %s" % (l.strip()) print (" * %s" % (l.strip()))
print " */" print (" */")
print print ()
print '#include "hb-ot-shape-complex-indic-private.hh"' print ('#include "hb-ot-shape-complex-indic-private.hh"')
print print ()
# Shorten values # Shorten values
short = [{ short = [{
...@@ -130,7 +132,7 @@ for i in range (2): ...@@ -130,7 +132,7 @@ for i in range (2):
what = ["INDIC_SYLLABIC_CATEGORY", "INDIC_MATRA_CATEGORY"] what = ["INDIC_SYLLABIC_CATEGORY", "INDIC_MATRA_CATEGORY"]
what_short = ["ISC", "IMC"] what_short = ["ISC", "IMC"]
for i in range (2): for i in range (2):
print print ()
vv = values[i].keys () vv = values[i].keys ()
vv.sort () vv.sort ()
for v in vv: for v in vv:
...@@ -143,14 +145,14 @@ for i in range (2): ...@@ -143,14 +145,14 @@ for i in range (2):
raise Exception ("Duplicate short value alias", v, all_shorts[i][s]) raise Exception ("Duplicate short value alias", v, all_shorts[i][s])
all_shorts[i][s] = v all_shorts[i][s] = v
short[i][v] = s short[i][v] = s
print "#define %s_%s %s_%s %s/* %3d chars; %s */" % \ print ("#define %s_%s %s_%s %s/* %3d chars; %s */" %
(what_short[i], s, what[i], v.upper (), \ (what_short[i], s, what[i], v.upper (),
' '* ((48-1 - len (what[i]) - 1 - len (v)) / 8), \ ' '* ((48-1 - len (what[i]) - 1 - len (v)) // 8),
values[i][v], v) values[i][v], v))
print print ()
print "#define _(S,M) INDIC_COMBINE_CATEGORIES (ISC_##S, IMC_##M)" print ("#define _(S,M) INDIC_COMBINE_CATEGORIES (ISC_##S, IMC_##M)")
print print ()
print print ()
total = 0 total = 0
used = 0 used = 0
...@@ -158,20 +160,20 @@ last_block = None ...@@ -158,20 +160,20 @@ last_block = None
def print_block (block, start, end, data): def print_block (block, start, end, data):
global total, used, last_block global total, used, last_block
if block and block != last_block: if block and block != last_block:
print print ()
print print ()
print " /* %s */" % block print (" /* %s */" % block)
num = 0 num = 0
assert start % 8 == 0 assert start % 8 == 0
assert (end+1) % 8 == 0 assert (end+1) % 8 == 0
for u in range (start, end+1): for u in range (start, end+1):
if u % 8 == 0: if u % 8 == 0:
print print ()
print " /* %04X */" % u, print (" /* %04X */" % u, end="")
if u in data: if u in data:
num += 1 num += 1
d = data.get (u, defaults) d = data.get (u, defaults)
sys.stdout.write ("%9s" % ("_(%s,%s)," % (short[0][d[0]], short[1][d[1]]))) print ("%9s" % ("_(%s,%s)," % (short[0][d[0]], short[1][d[1]])), end="")
total += end - start + 1 total += end - start + 1
used += num used += num
...@@ -186,7 +188,7 @@ num = 0 ...@@ -186,7 +188,7 @@ num = 0
offset = 0 offset = 0
starts = [] starts = []
ends = [] ends = []
print "static const INDIC_TABLE_ELEMENT_TYPE indic_table[] = {" print ("static const INDIC_TABLE_ELEMENT_TYPE indic_table[] = {")
for u in uu: for u in uu:
if u <= last: if u <= last:
continue continue
...@@ -206,54 +208,54 @@ for u in uu: ...@@ -206,54 +208,54 @@ for u in uu:
if last >= 0: if last >= 0:
ends.append (last + 1) ends.append (last + 1)
offset += ends[-1] - starts[-1] offset += ends[-1] - starts[-1]
print print ()
print print ()
print "#define indic_offset_0x%04xu %d" % (start, offset) print ("#define indic_offset_0x%04xu %d" % (start, offset))
starts.append (start) starts.append (start)
print_block (block, start, end, data) print_block (block, start, end, data)
last = end last = end
ends.append (last + 1) ends.append (last + 1)
offset += ends[-1] - starts[-1] offset += ends[-1] - starts[-1]
print print ()
print print ()
occupancy = used * 100. / total occupancy = used * 100. / total
page_bits = 12 page_bits = 12
print "}; /* Table items: %d; occupancy: %d%% */" % (offset, occupancy) print ("}; /* Table items: %d; occupancy: %d%% */" % (offset, occupancy))
print print ()
print "INDIC_TABLE_ELEMENT_TYPE" print ("INDIC_TABLE_ELEMENT_TYPE")
print "hb_indic_get_categories (hb_codepoint_t u)" print ("hb_indic_get_categories (hb_codepoint_t u)")
print "{" print ("{")
print " switch (u >> %d)" % page_bits print (" switch (u >> %d)" % page_bits)
print " {" print (" {")
pages = set([u>>page_bits for u in starts+ends+singles.keys()]) pages = set([u>>page_bits for u in starts+ends+singles.keys()])
for p in sorted(pages): for p in sorted(pages):
print " case 0x%0Xu:" % p print (" case 0x%0Xu:" % p)
for u,d in singles.items (): for u,d in singles.items ():
if p != u>>page_bits: continue if p != u>>page_bits: continue
print " if (unlikely (u == 0x%04Xu)) return _(%s,%s);" % (u, short[0][d[0]], short[1][d[1]]) print (" if (unlikely (u == 0x%04Xu)) return _(%s,%s);" % (u, short[0][d[0]], short[1][d[1]]))
for (start,end) in zip (starts, ends): for (start,end) in zip (starts, ends):
if p not in [start>>page_bits, end>>page_bits]: continue if p not in [start>>page_bits, end>>page_bits]: continue
offset = "indic_offset_0x%04xu" % start offset = "indic_offset_0x%04xu" % start
print " if (hb_in_range<hb_codepoint_t> (u, 0x%04Xu, 0x%04Xu)) return indic_table[u - 0x%04Xu + %s];" % (start, end-1, start, offset) print (" if (hb_in_range<hb_codepoint_t> (u, 0x%04Xu, 0x%04Xu)) return indic_table[u - 0x%04Xu + %s];" % (start, end-1, start, offset))
print " break;" print (" break;")
print "" print ("")
print " default:" print (" default:")
print " break;" print (" break;")
print " }" print (" }")
print " return _(x,x);" print (" return _(x,x);")
print "}" print ("}")
print print ()
print "#undef _" print ("#undef _")
for i in range (2): for i in range (2):
print print
vv = values[i].keys () vv = values[i].keys ()
vv.sort () vv.sort ()
for v in vv: for v in vv:
print "#undef %s_%s" % \ print ("#undef %s_%s" %
(what_short[i], short[i][v]) (what_short[i], short[i][v]))
print print ()
print "/* == End of generated table == */" print ("/* == End of generated table == */")
# Maintain at least 30% occupancy in the table */ # Maintain at least 30% occupancy in the table */
if occupancy < 30: if occupancy < 30:
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
# Input is a tab seperated list of unicode ranges from the otspec # Input is a tab seperated list of unicode ranges from the otspec
# (https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ulunicoderange1). # (https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ulunicoderange1).
from __future__ import print_function, division, absolute_import
import io import io
import re import re
import sys import sys
...@@ -11,7 +13,7 @@ import sys ...@@ -11,7 +13,7 @@ import sys
reload(sys) reload(sys)
sys.setdefaultencoding('utf-8') sys.setdefaultencoding('utf-8')
print (u"""static Range os2UnicodeRangesSorted[] = print ("""static Range os2UnicodeRangesSorted[] =
{""") {""")
args = sys.argv[1:] args = sys.argv[1:]
...@@ -47,6 +49,6 @@ for ranges in all_ranges: ...@@ -47,6 +49,6 @@ for ranges in all_ranges:
end = ("0x%X" % ranges[1]).rjust(8) end = ("0x%X" % ranges[1]).rjust(8)
bit = ("%s" % ranges[2]).rjust(3) bit = ("%s" % ranges[2]).rjust(3)
print " {%s, %s, %s}, // %s" % (start, end, bit, ranges[3]) print (" {%s, %s, %s}, // %s" % (start, end, bit, ranges[3]))
print (u"""};"""); print ("""};""")
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function, division, absolute_import
import sys import sys
if len (sys.argv) != 5: if len (sys.argv) != 5:
......
...@@ -430,7 +430,6 @@ hb_indic_get_categories (hb_codepoint_t u) ...@@ -430,7 +430,6 @@ hb_indic_get_categories (hb_codepoint_t u)
} }
#undef _ #undef _
#undef ISC_A #undef ISC_A
#undef ISC_Bi #undef ISC_Bi
#undef ISC_BJN #undef ISC_BJN
...@@ -466,7 +465,6 @@ hb_indic_get_categories (hb_codepoint_t u) ...@@ -466,7 +465,6 @@ hb_indic_get_categories (hb_codepoint_t u)
#undef ISC_Vo #undef ISC_Vo
#undef ISC_M #undef ISC_M
#undef ISC_VI #undef ISC_VI
#undef IMC_B #undef IMC_B
#undef IMC_BL #undef IMC_BL
#undef IMC_BR #undef IMC_BR
......
#!/usr/bin/python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import print_function from __future__ import print_function, division, absolute_import
import sys import sys
import array import array
from gi.repository import HarfBuzz as hb from gi.repository import HarfBuzz as hb
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function, division, absolute_import
import sys, os, subprocess import sys, os, subprocess
srcdir = os.environ.get ("srcdir", ".") srcdir = os.environ.get ("srcdir", ".")
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function, division, absolute_import
import sys, os, subprocess import sys, os, subprocess
srcdir = os.environ.get ("srcdir", ".") srcdir = os.environ.get ("srcdir", ".")
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function, division, absolute_import
import sys import sys
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function, division, absolute_import
import sys, os, re, difflib, unicodedata, errno, cgi import sys, os, re, difflib, unicodedata, errno, cgi
from itertools import * from itertools import *
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function, division, absolute_import
import sys, os, subprocess import sys, os, subprocess
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# Runs a subsetting test suite. Compares the results of subsetting via harfbuz # Runs a subsetting test suite. Compares the results of subsetting via harfbuz
# to subsetting via fonttools. # to subsetting via fonttools.
from __future__ import print_function from __future__ import print_function, division, absolute_import
import io import io
from difflib import unified_diff from difflib import unified_diff
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册