4
"""This script builds the Lib/fontTools/ttLib/tables/otData.py file
5
from the OpenType HTML documentation. However, it depends on a slightly
6
patched version the the HTML, as there are some inconsistencies in the
7
markup and the naming of certain fields. See doco.diff for differences,
8
but this is probably against a slightly older version of the documentation
9
than what is currently online. The documentation was taken from this URL:
10
http://www.microsoft.com/typography/otspec/default.htm
14
from sgmllib import SGMLParser
17
class HTMLParser(SGMLParser):
20
SGMLParser.__init__(self)
22
self.currenttable = None
23
self.lastcaption = None
25
def handle_data(self, data):
26
if self.data is not None:
27
self.data.append(data)
29
def start_i(self, attrs):
30
if self.currenttable is None:
33
if self.currenttable is None:
34
self.lastcaption = " ".join(self.data)
37
def start_b(self, attrs):
38
if self.currenttable is None:
41
if self.currenttable is None:
42
self.lastcaption = " ".join(self.data)
45
def start_table(self, attrs):
47
if attrs.get('width') in ('455', '460'):
49
self.currenttable = []
51
self.currenttable = None
53
if self.currenttable is not None and self.lastcaption is not None:
54
if self.currenttable[0] == ['Type', 'Name', 'Description'] or \
55
self.currenttable[0] == ['Value', 'Type', 'Description']:
56
caption = self.lastcaption.split()
58
if name == "LookupType" or name == "LookupFlag":
59
self.currenttable = None
61
elif name == "Device":
62
if "Tables" in caption:
64
self.currenttable = None
66
buildTable(name, self.currenttable[1:], self.lastcaption)
67
self.currenttable = None
69
def start_tr(self, attrs):
70
if self.currenttable is not None:
71
self.currenttable.append([])
75
def start_td(self, attrs):
78
if self.currenttable is not None and self.data is not None:
79
self.currenttable[-1].append(" ".join(self.data))
87
def buildTable(name, table, caption):
88
if globalDups.has_key(name):
89
globalDups[name].append(caption)
91
globalDups[name] = [caption]
92
print "\t(%s, [" % repr(name)
95
row = [" ".join(x.split()) for x in row]
100
if allFields.has_key(fieldName):
101
key = (name, fieldName)
103
allFields[fieldName] = 1
104
print "\t\t%s," % (tuple(row),)
110
tp, name = rawRow[:2]
112
rest = tuple(rawRow[2:])
114
name, repeat = name.split("[")
116
assert repeat[-1] == "]"
117
repeat = repeat[:-1].split()
119
repeatOffset = int("".join(repeat[1:]))
129
row = (tp, name, repeat, repeatOffset) + rest
133
if __name__ == "__main__":
135
if "-" not in sys.argv:
136
sys.stdout = open("otData.py", "w")
138
for file in ["chapter2.htm", "gpos.htm", "gsub.htm", "gdef.htm", "base.htm", "jstf.htm"]:
139
name = os.path.splitext(file)[0]
140
if name == "chapter2":
144
print "\t# %s (generated from %s)" % (name, file)
148
p.feed(open(file).read())
152
for k, v in globalDups.items():
154
print "# XXX duplicate table name:", k, v
155
for (name, fieldName), v in localDups.items():
156
print "# XXX duplicate field name '%s' in table '%s'" % (fieldName, name)