[AAT] Delegate XML reading and writing to value class converter
Before this change, the code assumed that all values of AAT lookups get internally represented as strings, which is correct for GlyphID values but not generally the case. Also renaming the XML element from `Substitution` to `Lookup` because AAT lookups have other uses beyond glyph substitutions.
This commit is contained in:
parent
228550a1d2
commit
4cf76edd87
@ -762,21 +762,22 @@ class AATLookup(BaseConverter):
|
||||
|
||||
def xmlRead(self, attrs, content, font):
|
||||
value = {}
|
||||
converter = self.tableClass("Lookup", repeat=False, aux=None)
|
||||
for element in content:
|
||||
if isinstance(element, tuple):
|
||||
name, a, eltContent = element
|
||||
if name == "Substitution":
|
||||
value[a["in"]] = a["out"]
|
||||
if name == "Lookup":
|
||||
value[a["glyph"]] = converter.xmlRead(a, eltContent, font)
|
||||
return value
|
||||
|
||||
def xmlWrite(self, xmlWriter, font, value, name, attrs):
|
||||
xmlWriter.begintag(name, attrs)
|
||||
xmlWriter.newline()
|
||||
items = sorted(value.items())
|
||||
for inGlyph, outGlyph in items:
|
||||
xmlWriter.simpletag("Substitution",
|
||||
[("in", inGlyph), ("out", outGlyph)])
|
||||
xmlWriter.newline()
|
||||
converter = self.tableClass(name, repeat=False, aux=None)
|
||||
for glyph, value in sorted(value.items()):
|
||||
converter.xmlWrite(
|
||||
xmlWriter, font, value=value,
|
||||
name="Lookup", attrs=[("glyph", glyph)])
|
||||
xmlWriter.endtag(name)
|
||||
xmlWriter.newline()
|
||||
|
||||
|
@ -331,8 +331,8 @@ class AATLookupTest(unittest.TestCase):
|
||||
|
||||
def test_xmlRead(self):
|
||||
value = self.converter.xmlRead({}, [
|
||||
("Substitution", {"in": "A", "out": "A.alt"}, []),
|
||||
("Substitution", {"in": "B", "out": "B.alt"}, []),
|
||||
("Lookup", {"glyph": "A", "value": "A.alt"}, []),
|
||||
("Lookup", {"glyph": "B", "value": "B.alt"}, []),
|
||||
], self.font)
|
||||
self.assertEqual(value, {"A": "A.alt", "B": "B.alt"})
|
||||
|
||||
@ -344,8 +344,8 @@ class AATLookupTest(unittest.TestCase):
|
||||
xml = writer.file.getvalue().decode("utf-8").splitlines()
|
||||
self.assertEqual(xml, [
|
||||
'<Foo attr="val">',
|
||||
' <Substitution in="A" out="A.alt"/>',
|
||||
' <Substitution in="B" out="B.alt"/>',
|
||||
' <Lookup glyph="A" value="A.alt"/>',
|
||||
' <Lookup glyph="B" value="B.alt"/>',
|
||||
'</Foo>',
|
||||
])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user