from __future__ import print_function, division, absolute_import
import io, os.path, sys, re
+import logging
+logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
if len (sys.argv) != 2:
print("usage: ./gen-ucd-table ucd.nonunihan.grouped.xml", file=sys.stderr)
sys.exit(1)
-
# https://github.com/harfbuzz/packtab
import packTab
import packTab.ucdxml
+logging.info('Loading UCDXML...')
ucdxml = packTab.ucdxml.load_ucdxml(sys.argv[1])
ucd = packTab.ucdxml.ucdxml_get_repertoire(ucdxml)
+logging.info('Preparing data tables...')
gc = [u['gc'] for u in ucd]
ccc = [int(u['ccc']) for u in ucd]
COMPACT = 3
+logging.info('Generating output...')
print("/* == Start of generated table == */")
print("/*")
print(" * The following table is generated by running:")
print("#ifndef HB_UCD_TABLE_HH")
print("#define HB_UCD_TABLE_HH")
print()
-
-print()
print('#include "hb.hh"')
print()
dm2_array, _ = code.addArray('uint64_t', 'dm2_map', dm2_array)
code.print_c(linkage='static inline')
+datasets = [
+ ('gc', gc, 'Cn', gc_order),
+ ('ccc', ccc, 0, None),
+ ('bmg', bmg, 0, None),
+ ('sc', sc, 'Zzzz', sc_order),
+ ('dm', dm, None, dm_order),
+]
+
for compression in (DEFAULT, COMPACT):
+ logging.info(' Compression=%d:' % compression)
print()
if compression == DEFAULT:
print('#ifndef HB_OPTIMIZE_SIZE')
code = packTab.Code('_hb_ucd')
- packTab.pack_table(gc, 'Cn', mapping=gc_order, compression=compression).genCode(code, 'gc')
- packTab.pack_table(ccc, 0, compression=compression).genCode(code, 'ccc')
- packTab.pack_table(bmg, 0, compression=compression).genCode(code, 'bmg')
- packTab.pack_table(sc, 'Zzzz', mapping=sc_order, compression=compression).genCode(code, 'sc')
- packTab.pack_table(dm, None, mapping=dm_order, compression=compression).genCode(code, 'dm')
+ for name,data,default,mapping in datasets:
+ sol = packTab.pack_table(data, default, mapping=mapping, compression=compression)
+ logging.info(' Dataset=%-8s FullCost=%d' % (name, sol.fullCost))
+ sol.genCode(code, name)
code.print_c(linkage='static inline')
print("#endif /* HB_UCD_TABLE_HH */")
print()
print("/* == End of generated table == */")
+logging.info('Done.')