def test_toXML2(self): writer = XMLWriter(StringIO()) table = otTables.AlternateSubst() table.alternates = {"G": ["G.alt2", "G.alt1"], "Z": ["Z.fina"]} table.toXML2(writer, self.font) self.assertEqual(writer.file.getvalue().splitlines()[1:], [ '<AlternateSet glyph="G">', ' <Alternate glyph="G.alt2"/>', ' <Alternate glyph="G.alt1"/>', '</AlternateSet>', '<AlternateSet glyph="Z">', ' <Alternate glyph="Z.fina"/>', '</AlternateSet>' ])
def test_preWrite_format1(self): table = otTables.AlternateSubst() table.alternates = {"G": ["G.alt2", "G.alt1"], "Z": ["Z.fina"]} rawTable = table.preWrite(self.font) self.assertEqual(table.Format, 1) self.assertEqual(rawTable["Coverage"].glyphs, ["G", "Z"]) [g, z] = rawTable["AlternateSet"] self.assertIsInstance(g, otTables.AlternateSet) self.assertEqual(g.Alternate, ["G.alt2", "G.alt1"]) self.assertIsInstance(z, otTables.AlternateSet) self.assertEqual(z.Alternate, ["Z.fina"])
def build(self): lookup = otTables.Lookup() lookup.SubTable = [] st = otTables.AlternateSubst() st.Format = 1 st.alternates = self.alternates lookup.SubTable.append(st) lookup.LookupFlag = self.lookup_flag lookup.LookupType = self.lookup_type lookup.SubTableCount = len(lookup.SubTable) return lookup
def test_fromXML(self): table = otTables.AlternateSubst() for name, attrs, content in parseXML('<AlternateSet glyph="G">' ' <Alternate glyph="G.alt2"/>' ' <Alternate glyph="G.alt1"/>' '</AlternateSet>' '<AlternateSet glyph="Z">' ' <Alternate glyph="Z.fina"/>' '</AlternateSet>'): table.fromXML(name, attrs, content, self.font) self.assertEqual(table.alternates, { "G": ["G.alt2", "G.alt1"], "Z": ["Z.fina"] })
def test_postRead_format1(self): table = otTables.AlternateSubst() table.Format = 1 rawTable = { "Coverage": makeCoverage(["G", "Z"]), "AlternateSet": [ self.makeAlternateSet("G.alt2 G.alt1"), self.makeAlternateSet("Z.fina") ] } table.postRead(rawTable, self.font) self.assertEqual(table.alternates, { "G": ["G.alt2", "G.alt1"], "Z": ["Z.fina"] })
def build(self): subtable = otTables.AlternateSubst() subtable.Format = 1 subtable.alternates = self.alternates return self.buildLookup_([subtable])
def test_postRead_formatUnknown(self): table = otTables.AlternateSubst() table.Format = 987 self.assertRaises(AssertionError, table.postRead, {}, self.font)
def buildAlternateSubstSubtable(mapping): if not mapping: return None self = ot.AlternateSubst() self.alternates = dict(mapping) return self