Imported Upstream version 2.6.7
[platform/upstream/harfbuzz.git] / src / gen-indic-table.py
index 6252664..1746aab 100755 (executable)
@@ -1,12 +1,17 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
-from __future__ import print_function, division, absolute_import
+"""usage: ./gen-indic-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt Blocks.txt
 
-import io, sys
+Input files:
+* https://unicode.org/Public/UCD/latest/ucd/IndicSyllabicCategory.txt
+* https://unicode.org/Public/UCD/latest/ucd/IndicPositionalCategory.txt
+* https://unicode.org/Public/UCD/latest/ucd/Blocks.txt
+"""
+
+import sys
 
 if len (sys.argv) != 4:
-       print ("usage: ./gen-indic-table.py IndicSyllabicCategory.txt IndicPositionalCategory.txt Blocks.txt", file=sys.stderr)
-       sys.exit (1)
+       sys.exit (__doc__)
 
 ALLOWED_SINGLES = [0x00A0, 0x25CC]
 ALLOWED_BLOCKS = [
@@ -32,7 +37,7 @@ ALLOWED_BLOCKS = [
        'Myanmar Extended-A',
 ]
 
-files = [io.open (x, encoding='utf-8') for x in sys.argv[1:]]
+files = [open (x, encoding='utf-8') for x in sys.argv[1:]]
 
 headers = [[f.readline () for i in range (2)] for f in files]
 
@@ -79,10 +84,6 @@ data = combined
 del combined
 num = len (data)
 
-for u in [0x17CD, 0x17CE, 0x17CF, 0x17D0, 0x17D3]:
-       if data[u][0] == 'Other':
-               data[u][0] = "Vowel_Dependent"
-
 # Move the outliers NO-BREAK SPACE and DOTTED CIRCLE out
 singles = {}
 for u in ALLOWED_SINGLES:
@@ -102,7 +103,11 @@ for h in headers:
                print (" * %s" % (l.strip()))
 print (" */")
 print ()
-print ('#include "hb-ot-shape-complex-indic-private.hh"')
+print ('#include "hb.hh"')
+print ()
+print ('#ifndef HB_NO_OT_SHAPE')
+print ()
+print ('#include "hb-ot-shape-complex-indic.hh"')
 print ()
 
 # Shorten values
@@ -131,8 +136,10 @@ for i in range (2):
 
 what = ["INDIC_SYLLABIC_CATEGORY", "INDIC_MATRA_CATEGORY"]
 what_short = ["ISC", "IMC"]
+print ('#pragma GCC diagnostic push')
+print ('#pragma GCC diagnostic ignored "-Wunused-macros"')
+cat_defs = []
 for i in range (2):
-       print ()
        vv = sorted (values[i].keys ())
        for v in vv:
                v_no_and = v.replace ('_And_', '_')
@@ -144,10 +151,18 @@ for i in range (2):
                                raise Exception ("Duplicate short value alias", v, all_shorts[i][s])
                        all_shorts[i][s] = v
                        short[i][v] = s
-               print ("#define %s_%s   %s_%s   %s/* %3d chars; %s */" %
-                       (what_short[i], s, what[i], v.upper (),
-                       '       '* ((48-1 - len (what[i]) - 1 - len (v)) // 8),
-                       values[i][v], v))
+               cat_defs.append ((what_short[i] + '_' + s, what[i] + '_' + v.upper (), str (values[i][v]), v))
+
+maxlen_s = max ([len (c[0]) for c in cat_defs])
+maxlen_l = max ([len (c[1]) for c in cat_defs])
+maxlen_n = max ([len (c[2]) for c in cat_defs])
+for s in what_short:
+       print ()
+       for c in [c for c in cat_defs if s in c[0]]:
+               print ("#define %s %s /* %s chars; %s */" %
+                       (c[0].ljust (maxlen_s), c[1].ljust (maxlen_l), c[2].rjust (maxlen_n), c[3]))
+print ()
+print ('#pragma GCC diagnostic pop')
 print ()
 print ("#define _(S,M) INDIC_COMBINE_CATEGORIES (ISC_##S, IMC_##M)")
 print ()
@@ -246,12 +261,14 @@ print ("}")
 print ()
 print ("#undef _")
 for i in range (2):
-       print
+       print ()
        vv = sorted (values[i].keys ())
        for v in vv:
                print ("#undef %s_%s" %
                        (what_short[i], short[i][v]))
 print ()
+print ('#endif')
+print ()
 print ("/* == End of generated table == */")
 
 # Maintain at least 30% occupancy in the table */