Allow specifying table type as converter
Needed for upcoming MATH table.
diff --git a/Lib/fontTools/ttLib/tables/otBase.py b/Lib/fontTools/ttLib/tables/otBase.py
index 77f954c..cf4a662 100644
--- a/Lib/fontTools/ttLib/tables/otBase.py
+++ b/Lib/fontTools/ttLib/tables/otBase.py
@@ -627,8 +627,8 @@
def preWrite(self, font):
return self.__dict__.copy()
- def toXML(self, xmlWriter, font, attrs=None):
- tableName = self.__class__.__name__
+ def toXML(self, xmlWriter, font, attrs=None, name=None):
+ tableName = name if name else self.__class__.__name__
if attrs is None:
attrs = []
if hasattr(self, "Format"):
@@ -701,6 +701,9 @@
def writeFormat(self, writer):
writer.writeUShort(self.Format)
+ def toXML(self, xmlWriter, font, attrs=None, name=None):
+ BaseTable.toXML(self, xmlWriter, font, attrs, name=self.__class__.__name__)
+
#
# Support for ValueRecords
diff --git a/Lib/fontTools/ttLib/tables/otConverters.py b/Lib/fontTools/ttLib/tables/otConverters.py
index 871ec1d..788119f 100644
--- a/Lib/fontTools/ttLib/tables/otConverters.py
+++ b/Lib/fontTools/ttLib/tables/otConverters.py
@@ -12,6 +12,7 @@
converters = []
convertersByName = {}
for tp, name, repeat, aux, descr in tableSpec:
+ tableName = name
if name.startswith("ValueFormat"):
assert tp == "uint16"
converterClass = ValueFormat
@@ -25,8 +26,12 @@
elif name == "FeatureParams":
converterClass = FeatureParams
else:
- converterClass = converterMapping[tp]
- tableClass = tableNamespace.get(name)
+ if not tp in converterMapping:
+ tableName = tp
+ converterClass = Struct
+ else:
+ converterClass = converterMapping[tp]
+ tableClass = tableNamespace.get(tableName)
conv = converterClass(name, repeat, aux, tableClass)
if name in ["SubTable", "ExtSubTable"]:
conv.lookupTypes = tableNamespace['lookupTypes']
@@ -40,7 +45,7 @@
for cls in conv.featureParamTypes.values():
convertersByName[cls.__name__] = Table(name, repeat, aux, cls)
converters.append(conv)
- assert name not in convertersByName
+ assert name not in convertersByName, name
convertersByName[name] = conv
return converters, convertersByName
@@ -190,7 +195,7 @@
else:
pass # NULL table, ignore
else:
- value.toXML(xmlWriter, font, attrs)
+ value.toXML(xmlWriter, font, attrs, name=name)
def xmlRead(self, attrs, content, font):
table = self.tableClass()
diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py
index c917598..ca79682 100644
--- a/Lib/fontTools/ttLib/tables/otTables.py
+++ b/Lib/fontTools/ttLib/tables/otTables.py
@@ -20,6 +20,9 @@
assert featureParamTypes.get(writer['FeatureTag'], None) == self.__class__, "Wrong FeatureParams type for feature '%s': %s" % (writer['FeatureTag'], self.__class__.__name__)
BaseTable.compile(self, writer, font)
+ def toXML(self, xmlWriter, font, attrs=None, name=None):
+ BaseTable.toXML(self, xmlWriter, font, attrs, name=self.__class__.__name__)
+
class FeatureParamsSize(FeatureParams):
pass