[gen-ucd] Generate decomposition tables

Code is ugly.  Ugh.
This commit is contained in:
Behdad Esfahbod 2019-05-21 16:43:14 -04:00
parent 8a48c88fa9
commit a03ed95e7d
1 changed files with 20 additions and 20 deletions

View File

@ -14,29 +14,26 @@ ucd = youseedy.load_ucdxml (sys.argv[1])
gc = [u['gc'] for u in ucd] gc = [u['gc'] for u in ucd]
ccc = [int(u['ccc']) for u in ucd] ccc = [int(u['ccc']) for u in ucd]
sc = [u['sc'] for u in ucd]
bmg = [int(v, 16) - int(u) if v else 0 for u,v in enumerate(u['bmg'] for u in ucd)] bmg = [int(v, 16) - int(u) if v else 0 for u,v in enumerate(u['bmg'] for u in ucd)]
#gc_ccc_non0 = set((cat,klass) for cat,klass in zip(gc,ccc) if klass)
#gc_bmg_non0 = set((cat,mirr) for cat,mirr in zip(gc, bmg) if mirr)
sc = [u['sc'] for u in ucd]
dm = {i:tuple(int(v, 16) for v in u['dm'].split()) for i,u in enumerate(ucd) dm = {i:tuple(int(v, 16) for v in u['dm'].split()) for i,u in enumerate(ucd)
if u['dm'] != '#' and u['dt'] == 'can' and not (0xAC00 <= i < 0xAC00+11172)} if u['dm'] != '#' and u['dt'] == 'can' and not (0xAC00 <= i < 0xAC00+11172)}
assert not any(v for v in dm.values() if len(v) not in (1,2))
gc_set = set(gc) dm1 = sorted(set(v for v in dm.values() if len(v) == 1))
gc_ccc_non0 = set((cat,klass) for cat,klass in zip(gc,ccc) if klass) dm1_array = ['0x%04Xu' % v for v in dm1]
gc_bmg_non0 = set((cat,mirr) for cat,mirr in zip(gc, bmg) if mirr) dm1_order = {v:i+1 for i,v in enumerate(dm1)}
dm2 = set(v for v in dm.values() if len(v) == 2) dm2 = sorted((v, i) for i,v in dm.items() if len(v) == 2)
dm1 = set(v[0] for i,v in dm.items() if len(v) == 1) dm2 = [("_HB_UCD_ENCODE3 (0x%04Xu, 0x%04Xu, 0x%04Xu)" % (v+(i,)), v) for v,i in dm2]
dmx = set(v for v in dm.values() if len(v) not in (1,2)) dm2_array = [s for s,v in dm2]
assert not dmx l = 1 + len(dm1_array)
dm2_order = {v[1]:i+l for i,v in enumerate(dm2)}
#print(len(sorted(gc_set))) dm_order = {None: 0}
#print(len(sorted(gc_ccc_non0))) dm_order.update(dm1_order)
#print(len(sorted(gc_bmg_non0))) dm_order.update(dm2_order)
#print("GC, CCC, and BMG fit in one byte. Compress together.")
#print()
#print(len(dm))
#print(len(dm1), min(dm1), max(dm1))
#print(len(dm2))
#print(len(sorted(set(v // 512 for v in dm1))))
gc_order = packTab.AutoMapping() gc_order = packTab.AutoMapping()
for _ in ('Cc', 'Cf', 'Cn', 'Co', 'Cs', 'Ll', 'Lm', 'Lo', 'Lt', 'Lu', for _ in ('Cc', 'Cf', 'Cn', 'Co', 'Cs', 'Ll', 'Lm', 'Lo', 'Lt', 'Lu',
@ -67,6 +64,8 @@ print('#include <stdint.h>')
print() print()
code = packTab.Code('_hb_ucd') code = packTab.Code('_hb_ucd')
sc_array, _, _ = code.addArray('hb_script_t', 'sc_map', sc_array) sc_array, _, _ = code.addArray('hb_script_t', 'sc_map', sc_array)
dm1_array, _, _ = code.addArray('hb_codepoint_t', 'dm1_map', dm1_array)
dm2_array, _, _ = code.addArray('uint64_t', 'dm2_map', dm2_array)
code.print_c(linkage='static inline') code.print_c(linkage='static inline')
for compression in (DEFAULT, COMPACT): for compression in (DEFAULT, COMPACT):
@ -83,6 +82,7 @@ for compression in (DEFAULT, COMPACT):
packTab.pack_table(ccc, 0, compression=compression).genCode(code, 'ccc') packTab.pack_table(ccc, 0, compression=compression).genCode(code, 'ccc')
packTab.pack_table(bmg, 0, compression=compression).genCode(code, 'bmg') 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(sc, 'Zzzz', mapping=sc_order, compression=compression).genCode(code, 'sc')
packTab.pack_table(dm, None, mapping=dm_order, compression=compression).genCode(code, 'dm')
code.print_c(linkage='static inline') code.print_c(linkage='static inline')