Home | History | Annotate | Download | only in tables
      1 import sys
      2 from unicode_parse_common import *
      3 
      4 # http://www.unicode.org/Public/5.1.0/ucd/Scripts.txt
      5 
      6 script_to_harfbuzz = {
      7   # This is the list of HB_Script_* at the time of writing
      8   'Common': 'HB_Script_Common',
      9   'Greek': 'HB_Script_Greek',
     10   'Cyrillic': 'HB_Script_Cyrillic',
     11   'Armenian': 'HB_Script_Armenian',
     12   'Hebrew': 'HB_Script_Hebrew',
     13   'Arabic': 'HB_Script_Arabic',
     14   'Syriac': 'HB_Script_Syriac',
     15   'Thaana': 'HB_Script_Thaana',
     16   'Devanagari': 'HB_Script_Devanagari',
     17   'Bengali': 'HB_Script_Bengali',
     18   'Gurmukhi': 'HB_Script_Gurmukhi',
     19   'Gujarati': 'HB_Script_Gujarati',
     20   'Oriya': 'HB_Script_Oriya',
     21   'Tamil': 'HB_Script_Tamil',
     22   'Telugu': 'HB_Script_Telugu',
     23   'Kannada': 'HB_Script_Kannada',
     24   'Malayalam': 'HB_Script_Malayalam',
     25   'Sinhala': 'HB_Script_Sinhala',
     26   'Thai': 'HB_Script_Thai',
     27   'Lao': 'HB_Script_Lao',
     28   'Tibetan': 'HB_Script_Tibetan',
     29   'Myanmar': 'HB_Script_Myanmar',
     30   'Georgian': 'HB_Script_Georgian',
     31   'Hangul': 'HB_Script_Hangul',
     32   'Ogham': 'HB_Script_Ogham',
     33   'Runic': 'HB_Script_Runic',
     34   'Khmer': 'HB_Script_Khmer',
     35   'Inherited': 'HB_Script_Inherited',
     36 }
     37 
     38 class ScriptDict(object):
     39   def __init__(self, base):
     40     self.base = base
     41 
     42   def __getitem__(self, key):
     43     r = self.base.get(key, None)
     44     if r is None:
     45       return 'HB_Script_Common'
     46     return r
     47 
     48 def main(infile, outfile):
     49   ranges = unicode_file_parse(infile,
     50                               ScriptDict(script_to_harfbuzz),
     51                               'HB_Script_Common')
     52   ranges = sort_and_merge(ranges)
     53 
     54   print >>outfile, '// Generated from Unicode script tables\n'
     55   print >>outfile, '#ifndef SCRIPT_PROPERTIES_H_'
     56   print >>outfile, '#define SCRIPT_PROPERTIES_H_\n'
     57   print >>outfile, '#include <stdint.h>'
     58   print >>outfile, '#include "harfbuzz-shaper.h"\n'
     59   print >>outfile, 'struct script_property {'
     60   print >>outfile, '  uint32_t range_start;'
     61   print >>outfile, '  uint32_t range_end;'
     62   print >>outfile, '  HB_Script script;'
     63   print >>outfile, '};\n'
     64   print >>outfile, 'static const struct script_property script_properties[] = {'
     65   for (start, end, value) in ranges:
     66     print >>outfile, '  {0x%x, 0x%x, %s},' % (start, end, value)
     67   print >>outfile, '};\n'
     68   print >>outfile, 'static const unsigned script_properties_count = %d;\n' % len(ranges)
     69   print >>outfile, '#endif  // SCRIPT_PROPERTIES_H_'
     70 
     71 if __name__ == '__main__':
     72   if len(sys.argv) != 3:
     73     print 'Usage: %s <input .txt> <output .h>' % sys.argv[0]
     74   else:
     75     main(file(sys.argv[1], 'r'), file(sys.argv[2], 'w+'))
     76