forked from adobe-type-tools/aots
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft2yaml.py
41 lines (37 loc) · 898 Bytes
/
ft2yaml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python3
# Structure to JSON
from fontTools.ttLib.tables.otData import otData
import yaml
import sys
typemap = {
"uint16": "USHORT",
"Offset": "Offset16",
"LOffset": "Offset32"
}
table = sys.argv[1]
ot = dict(otData)
if table not in ot:
print("Table not found")
print(sorted(ot.keys()))
sys.exit(1)
fields = []
for line in ot[table]:
mapped_type = line[0]
name = line[1]
if line[0] in typemap:
mapped_type = typemap[line[0]]
if mapped_type == "struct":
mapped_type = name
name = name[0].lower() + name[1:]
field = {"type": mapped_type, "name": name}
if line[2]:
field["count"] = line[2]
field["type"] = mapped_type + "[]"
field["name"] = name + "s"
if "Offset" in mapped_type:
field["to"] = "XXX"
if line[3]:
field["condition"] = line[3]
fields.append(field)
obj = { table: { "fields": fields } }
print(yaml.dump(obj, sort_keys=True, indent=2))