diff --git a/MetaTools/build_otData.py b/MetaTools/build_otData.py new file mode 100755 index 000000000..ffc4c045d --- /dev/null +++ b/MetaTools/build_otData.py @@ -0,0 +1,159 @@ +#! /usr/bin/env python + + +"""This script builds the Lib/fontTools/ttLib/tables/otData.py file +from the OpenType HTML documentation. However, it depends on a slightly +patched version the the HTML, as there are some inconsistencies in the +markup and the naming of certain fields. See doco.diff for differences, +but this is probably against a slightly older version of the documentation +than what is currently online. The documentation was taken from this URL: + http://www.microsoft.com/typography/otspec/default.htm +""" + + +from sgmllib import SGMLParser + + +class HTMLParser(SGMLParser): + + def __init__(self): + SGMLParser.__init__(self) + self.data = None + self.currenttable = None + self.lastcaption = None + + def handle_data(self, data): + if self.data is not None: + self.data.append(data) + + def start_i(self, attrs): + if self.currenttable is None: + self.data = [] + def end_i(self): + if self.currenttable is None: + self.lastcaption = " ".join(self.data) + self.data = None + + def start_b(self, attrs): + if self.currenttable is None: + self.data = [] + def end_b(self): + if self.currenttable is None: + self.lastcaption = " ".join(self.data) + self.data = None + + def start_table(self, attrs): + attrs = dict(attrs) + if attrs.get('width') in ('455', '460'): + #print "---", attrs + self.currenttable = [] + else: + self.currenttable = None + def end_table(self): + if self.currenttable is not None and self.lastcaption is not None: + if self.currenttable[0] == ['Type', 'Name', 'Description'] or \ + self.currenttable[0] == ['Value', 'Type', 'Description']: + caption = self.lastcaption.split() + name = caption[0] + if name == "LookupType" or name == "LookupFlag": + self.currenttable = None + return + elif name == "Device": + if "Tables" in caption: + # XXX skip this one + self.currenttable = None + return + buildTable(name, self.currenttable[1:], self.lastcaption) + self.currenttable = None + + def start_tr(self, attrs): + if self.currenttable is not None: + self.currenttable.append([]) + def end_tr(self): + pass + + def start_td(self, attrs): + self.data = [] + def end_td(self): + if self.currenttable is not None and self.data is not None: + self.currenttable[-1].append(" ".join(self.data)) + self.data = None + + +globalDups = {} +localDups = {} +not3 = [] + +def buildTable(name, table, caption): + if globalDups.has_key(name): + globalDups[name].append(caption) + else: + globalDups[name] = [caption] + print "\t(%s, [" % repr(name) + allFields = {} + for row in table: + row = [" ".join(x.split()) for x in row] + if len(row) <> 3: + not3.append(row) + row = makeRow(row) + fieldName = row[1] + if allFields.has_key(fieldName): + key = (name, fieldName) + localDups[key] = 1 + allFields[fieldName] = 1 + print "\t\t%s," % (tuple(row),) + print "\t])," + print + + +def makeRow(rawRow): + tp, name = rawRow[:2] + name = name.strip() + rest = tuple(rawRow[2:]) + if '[' in name: + name, repeat = name.split("[") + name = name.strip() + assert repeat[-1] == "]" + repeat = repeat[:-1].split() + if repeat[1:]: + repeatOffset = int("".join(repeat[1:])) + else: + repeatOffset = 0 + if not repeat: + repeat = "" + else: + repeat = repeat[0] + else: + repeat = None + repeatOffset = None + row = (tp, name, repeat, repeatOffset) + rest + return row + + +if __name__ == "__main__": + import sys, os + if "-" not in sys.argv: + sys.stdout = open("otData.py", "w") + print "otData = [" + for file in ["chapter2.htm", "gpos.htm", "gsub.htm", "gdef.htm", "base.htm", "jstf.htm"]: + name = os.path.splitext(file)[0] + if name == "chapter2": + name = "common" + print + print "\t#" + print "\t# %s (generated from %s)" % (name, file) + print "\t#" + print + p = HTMLParser() + p.feed(open(file).read()) + p.close() + print "]" + print + for k, v in globalDups.items(): + if len(v) > 1: + print "# XXX duplicate table name:", k, v + for (name, fieldName), v in localDups.items(): + print "# XXX duplicate field name '%s' in table '%s'" % (fieldName, name) + for n in not3: + print "#XXX", not3 + diff --git a/MetaTools/doco.diff b/MetaTools/doco.diff new file mode 100644 index 000000000..007ec28fa --- /dev/null +++ b/MetaTools/doco.diff @@ -0,0 +1,108 @@ +--- htmlorig/gpos.htm Fri Apr 5 23:55:58 2002 ++++ htmlbak/gpos.htm Tue May 7 09:53:30 2002 +@@ -270,7 +270,7 @@ + +

Example 2 at the end of this chapter shows a SinglePosFormat1 subtable used to adjust the placement of subscript glyphs. + +-

SinglePosFormat1 subtable: Single positioning value ++

SinglePosFormat1 subtable: Single positioning value +

+ + +@@ -312,7 +312,7 @@ + +

Example 3 at the end of this chapter shows how to adjust the spacing of three dash glyphs with a SinglePosFormat2 subtable. + +-

SinglePosFormat2 subtable: Array of positioning values ++

SinglePosFormat2 subtable: Array of positioning values +

+ +

+@@ -392,8 +392,8 @@ + + + +- +- ++ ++ + +
uint16PairSetCountNumber of PairSet tables
ValueRecordPairSet
[Offset]
OffsetPairSet
[PairSetCount]
Array of offsets to PairSet tables-from beginning of PairPos subtable-ordered by Coverage Index
+ +@@ -855,7 +855,8 @@ + Offset to Base Mark Coverage table-from beginning of MarkMarkPos subtable + uint16 + ClassCount +-Number of Combining Mark classes defined ++Number of Combining Mark classes defined ++ + Offset + Mark1Array + Offset to MarkArray table for Mark1-from beginning of MarkMarkPos subtable +@@ -1386,19 +1387,19 @@ + BacktrackGlyphCount + Number of glyphs in the backtracking sequence + Offset +-Coverage[BacktrackGlyphCount] ++BacktrackCoverage[BacktrackGlyphCount] + Array of offsets to coverage tables in backtracking sequence, in glyph sequence order + uint16 + InputGlyphCount + Number of glyphs in input sequence + Offset +-Coverage[InputGlyphCount] ++InputCoverage[InputGlyphCount] + Array of offsets to coverage tables in input sequence, in glyph sequence order + uint16 + LookaheadGlyphCount + Number of glyphs in lookahead sequence + Offset +-Coverage[LookaheadGlyphCount] ++LookaheadCoverage[LookaheadGlyphCount] + Array of offsets to coverage tables in lookahead sequence, in glyph sequence order + uint16 + PosCount +diff -u htmlorig/gsub.htm htmlbak/gsub.htm +--- htmlorig/gsub.htm Fri Apr 5 23:55:58 2002 ++++ htmlbak/gsub.htm Tue May 7 09:53:17 2002 +@@ -758,7 +758,7 @@ + +

Example 9 at the end of this chapter substitutes swash glyphs for two out of three glyphs in a sequence. + +-


ChainContextSubstFormat3 subtable: Coverage-based context glyph substitution

++


ContextSubstFormat3 subtable: Coverage-based context glyph substitution

+ + + +@@ -880,7 +880,7 @@ + + + +- ++ + + + +@@ -1023,19 +1023,19 @@ + + + +- ++ + + + + + +- ++ + + + + + +- ++ + + +
LookaheadGlyphCountTotal number of glyphs in the look ahead sequence (number of glyphs to be matched after the input sequence)
GlyphIDLookAhead
[LookAheadGlyphCount]
Lookahead
[LookAheadGlyphCount]
Array of lookahead GlyphID's (to be matched after the input sequence)
uint16SubstCountBacktrackGlyphCountNumber of glyphs in the backtracking sequence
OffsetCoverage[BacktrackGlyphCount]BacktrackCoverage[BacktrackGlyphCount]Array of offsets to coverage tables in backtracking sequence, in glyph sequence order
uint16InputGlyphCountNumber of glyphs in input sequence
OffsetCoverage[InputGlyphCount]InputCoverage[InputGlyphCount]Array of offsets to coverage tables in input sequence, in glyph sequence order
uint16LookaheadGlyphCountNumber of glyphs in lookahead sequence
OffsetCoverage[LookaheadGlyphCount]LookaheadCoverage[LookaheadGlyphCount]Array of offsets to coverage tables in lookahead sequence, in glyph sequence order
uint16SubstCount