def test_buildPairPosGlyphs(self): d50 = builder.buildValue({"XPlacement": -50}) d8020 = builder.buildValue({"XPlacement": -80, "YPlacement": -20}) subtables = builder.buildPairPosGlyphs( { ("A", "zero"): (None, d50), ("A", "one"): (d8020, d50), }, self.GLYPHMAP) self.maxDiff = None self.assertEqual( ''.join([getXML(t.toXML) for t in subtables]), '<PairPos Format="1">' ' <Coverage>' ' <Glyph value="A"/>' ' </Coverage>' ' <ValueFormat1 value="0"/>' ' <ValueFormat2 value="1"/>' ' <!-- PairSetCount=1 -->' ' <PairSet index="0">' ' <!-- PairValueCount=1 -->' ' <PairValueRecord index="0">' ' <SecondGlyph value="zero"/>' ' <Value2 XPlacement="-50"/>' ' </PairValueRecord>' ' </PairSet>' '</PairPos>' '<PairPos Format="1">' ' <Coverage>' ' <Glyph value="A"/>' ' </Coverage>' ' <ValueFormat1 value="3"/>' ' <ValueFormat2 value="1"/>' ' <!-- PairSetCount=1 -->' ' <PairSet index="0">' ' <!-- PairValueCount=1 -->' ' <PairValueRecord index="0">' ' <SecondGlyph value="one"/>' ' <Value1 XPlacement="-80" YPlacement="-20"/>' ' <Value2 XPlacement="-50"/>' ' </PairValueRecord>' ' </PairSet>' '</PairPos>')
def test_buildPairPosGlyphs(self): d50 = builder.buildValue({"XPlacement": -50}) d8020 = builder.buildValue({"XPlacement": -80, "YPlacement": -20}) subtables = builder.buildPairPosGlyphs( { ("A", "zero"): (None, d50), ("A", "one"): (d8020, d50) }, self.GLYPHMAP) assert sum([getXML(t.toXML) for t in subtables], []) == [ '<PairPos Format="1">', " <Coverage>", ' <Glyph value="A"/>', " </Coverage>", ' <ValueFormat1 value="0"/>', ' <ValueFormat2 value="1"/>', " <!-- PairSetCount=1 -->", ' <PairSet index="0">', " <!-- PairValueCount=1 -->", ' <PairValueRecord index="0">', ' <SecondGlyph value="zero"/>', ' <Value2 XPlacement="-50"/>', " </PairValueRecord>", " </PairSet>", "</PairPos>", '<PairPos Format="1">', " <Coverage>", ' <Glyph value="A"/>', " </Coverage>", ' <ValueFormat1 value="3"/>', ' <ValueFormat2 value="1"/>', " <!-- PairSetCount=1 -->", ' <PairSet index="0">', " <!-- PairValueCount=1 -->", ' <PairValueRecord index="0">', ' <SecondGlyph value="one"/>', ' <Value1 XPlacement="-80" YPlacement="-20"/>', ' <Value2 XPlacement="-50"/>', " </PairValueRecord>", " </PairSet>", "</PairPos>", ]
def build(self): builders = {} builder = None for glyphclass1, value1, glyphclass2, value2 in self.pairs: if glyphclass1 is self.SUBTABLE_BREAK_: if builder is not None: builder.addSubtableBreak() continue val1, valFormat1 = makeOpenTypeValueRecord(value1) val2, valFormat2 = makeOpenTypeValueRecord(value2) builder = builders.get((valFormat1, valFormat2)) if builder is None: builder = ClassPairPosSubtableBuilder(self, valFormat1, valFormat2) builders[(valFormat1, valFormat2)] = builder builder.addPair(glyphclass1, val1, glyphclass2, val2) subtables = [] if self.glyphPairs: subtables.extend(otl.buildPairPosGlyphs(self.glyphPairs, self.glyphMap)) for key in sorted(builders.keys()): subtables.extend(builders[key].subtables()) return self.buildLookup_(subtables)
def test_buildPairPosGlyphs(self): d50 = builder.buildValue({"XPlacement": -50}) d8020 = builder.buildValue({"XPlacement": -80, "YPlacement": -20}) subtables = builder.buildPairPosGlyphs({ ("A", "zero"): (None, d50), ("A", "one"): (d8020, d50), }, self.GLYPHMAP) self.maxDiff = None self.assertEqual(''.join([getXML(t.toXML) for t in subtables]), '<PairPos Format="1">' ' <Coverage>' ' <Glyph value="A"/>' ' </Coverage>' ' <ValueFormat1 value="0"/>' ' <ValueFormat2 value="1"/>' ' <!-- PairSetCount=1 -->' ' <PairSet index="0">' ' <!-- PairValueCount=1 -->' ' <PairValueRecord index="0">' ' <SecondGlyph value="zero"/>' ' <Value2 XPlacement="-50"/>' ' </PairValueRecord>' ' </PairSet>' '</PairPos>' '<PairPos Format="1">' ' <Coverage>' ' <Glyph value="A"/>' ' </Coverage>' ' <ValueFormat1 value="3"/>' ' <ValueFormat2 value="1"/>' ' <!-- PairSetCount=1 -->' ' <PairSet index="0">' ' <!-- PairValueCount=1 -->' ' <PairValueRecord index="0">' ' <SecondGlyph value="one"/>' ' <Value1 XPlacement="-80" YPlacement="-20"/>' ' <Value2 XPlacement="-50"/>' ' </PairValueRecord>' ' </PairSet>' '</PairPos>')
def build(self): builders = {} builder = None for glyphclass1, value1, glyphclass2, value2 in self.pairs: if glyphclass1 is self.SUBTABLE_BREAK_: if builder is not None: builder.addSubtableBreak() continue val1, valFormat1 = makeOpenTypeValueRecord(value1) val2, valFormat2 = makeOpenTypeValueRecord(value2) builder = builders.get((valFormat1, valFormat2)) if builder is None: builder = ClassPairPosSubtableBuilder( self, valFormat1, valFormat2) builders[(valFormat1, valFormat2)] = builder builder.addPair(glyphclass1, val1, glyphclass2, val2) subtables = [] if self.glyphPairs: subtables.extend( otl.buildPairPosGlyphs(self.glyphPairs, self.glyphMap)) for key in sorted(builders.keys()): subtables.extend(builders[key].subtables()) return self.buildLookup_(subtables)