def test_compile_fromXML(self): mvar = newTable('MVAR') font = TTFont() for name, attrs, content in parseXML(MVAR_XML): mvar.fromXML(name, attrs, content, font=font) data = MVAR_DATA self.assertEqual(hexStr(mvar.compile(font)), hexStr(data))
def testCompile(self): a = otTables.ContextualMorphAction() a.NewState = 0x1234 a.SetMark, a.DontAdvance, a.ReservedFlags = True, True, 0x3117 a.MarkIndex, a.CurrentIndex = 0xDEAD, 0xBEEF writer = OTTableWriter() a.compile(writer, self.font, actionIndex=None) self.assertEqual(hexStr(writer.getAllData()), "1234f117deadbeef")
def testCompile(self): r = otTables.RearrangementMorphAction() r.NewState = 0x1234 r.MarkFirst = r.DontAdvance = r.MarkLast = True r.ReservedFlags, r.Verb = 0x1FF0, 0xD writer = OTTableWriter() r.compile(writer, self.font, actionIndex=None) self.assertEqual(hexStr(writer.getAllData()), "1234fffd")
def testCompileFromXML(self): a = otTables.InsertionMorphAction() for name, attrs, content in parseXML(self.MORPH_ACTION_XML): a.fromXML(name, attrs, content, self.font) writer = OTTableWriter() a.compile(writer, self.font, actionIndex={('B', 'C'): 9, ('B', 'A', 'D'): 7}) self.assertEqual(hexStr(writer.getAllData()), "1234fc4300090007")
def checkFlags(self, flags, textDirection, processingOrder, checkCompile=True): data = bytesjoin([ MORX_REARRANGEMENT_DATA[:28], bytechr(flags << 4), MORX_REARRANGEMENT_DATA[29:]]) xml = [] for line in MORX_REARRANGEMENT_XML: if line.startswith(' <TextDirection '): line = ' <TextDirection value="%s"/>' % textDirection elif line.startswith(' <ProcessingOrder '): line = ' <ProcessingOrder value="%s"/>' % processingOrder xml.append(line) table1 = newTable('morx') table1.decompile(data, self.font) self.assertEqual(getXML(table1.toXML), xml) if checkCompile: table2 = newTable('morx') for name, attrs, content in parseXML(xml): table2.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table2.compile(self.font)), hexStr(data))
def testCompileFromXML(self): a = otTables.InsertionMorphAction() for name, attrs, content in parseXML(self.MORPH_ACTION_XML): a.fromXML(name, attrs, content, self.font) writer = OTTableWriter() a.compile(writer, self.font, actionIndex={ ('B', 'C'): 9, ('B', 'A', 'D'): 7 }) self.assertEqual(hexStr(writer.getAllData()), "1234fc4300090007")
def _writeRowImageData(strikeIndex, glyphName, bitmapObject, writer, ttFont): metrics = bitmapObject.exportMetrics del bitmapObject.exportMetrics bitDepth = bitmapObject.exportBitDepth del bitmapObject.exportBitDepth writer.begintag('rowimagedata', bitDepth=bitDepth, width=metrics.width, height=metrics.height) writer.newline() for curRow in range(metrics.height): rowData = bitmapObject.getRow(curRow, bitDepth=bitDepth, metrics=metrics) writer.simpletag('row', value=hexStr(rowData)) writer.newline() writer.endtag('rowimagedata') writer.newline()
def _writeRowImageData(strikeIndex, glyphName, bitmapObject, writer, ttFont): metrics = bitmapObject.exportMetrics del bitmapObject.exportMetrics bitDepth = bitmapObject.exportBitDepth del bitmapObject.exportBitDepth writer.begintag("rowimagedata", bitDepth=bitDepth, width=metrics.width, height=metrics.height) writer.newline() for curRow in range(metrics.height): rowData = bitmapObject.getRow(curRow, bitDepth=bitDepth, metrics=metrics) writer.simpletag("row", value=hexStr(rowData)) writer.newline() writer.endtag("rowimagedata") writer.newline()
def test_ReservedCoverageFlags(self): # 8A BC DE = TextDirection=Vertical, Reserved=0xABCDE # Note that the lower 4 bits of the first byte are already # part of the Reserved value. We test the full round-trip # to encoding and decoding is quite hairy. data = bytesjoin([ MORX_REARRANGEMENT_DATA[:28], bytechr(0x8A), bytechr(0xBC), bytechr(0xDE), MORX_REARRANGEMENT_DATA[31:]]) table = newTable('morx') table.decompile(data, self.font) subtable = table.table.MorphChain[0].MorphSubtable[0] self.assertEqual(subtable.Reserved, 0xABCDE) xml = getXML(table.toXML) self.assertIn(' <Reserved value="0xabcde"/>', xml) table2 = newTable('morx') for name, attrs, content in parseXML(xml): table2.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table2.compile(self.font)[28:31]), "8abcde")
def test_compile(self): font, gvar = self.makeFont(GVAR_VARIATIONS) self.assertEqual(hexStr(gvar.compile(font)), hexStr(GVAR_DATA))
def test_compile_fromXML(self): table = newTable('morx') for name, attrs, content in parseXML(MORX_INSERTION_XML): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(MORX_INSERTION_DATA))
def test_compile_shared_points(self): font, cvar = self.makeFont() cvar.variations = CVAR_VARIATIONS self.assertEqual(hexStr(cvar.compile(font, useSharedPoints=True)), hexStr(CVAR_DATA))
def test_compile(self): font, cvar = self.makeFont() cvar.variations = CVAR_VARIATIONS self.assertEqual(hexStr(cvar.compile(font)), hexStr(CVAR_PRIVATE_POINT_DATA))
def test_compile_fromXML_format1(self): table = newTable('opbd') for name, attrs, content in parseXML(OPBD_FORMAT_1_XML): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(OPBD_FORMAT_1_DATA))
def test_compile_fromXML(self): table = newTable('morx') for name, attrs, content in parseXML(MORX_NONCONTEXTUAL_XML): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(MORX_NONCONTEXTUAL_DATA))
def test_compile_fromXML_format0(self): table = newTable('opbd') for name, attrs, content in parseXML(OPBD_FORMAT_0_XML): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(OPBD_FORMAT_0_DATA))
def test_compile_fromXML(self): table = newTable('mort') for name, attrs, content in parseXML(MORT_NONCONTEXTUAL_XML): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(MORT_NONCONTEXTUAL_DATA))
def testCompileFromXML(self): table = newTable('cidg') for name, attrs, content in parseXML(CIDG_XML): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(CIDG_DATA))
def compileFromXML(self, xml, data): table = newTable('ankr') for name, attrs, content in parseXML(xml): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(data))
def test_compile_emptyVariations(self): font, gvar = self.makeFont({".notdef": [], "space": [], "I": []}) self.assertEqual(hexStr(gvar.compile(font)), hexStr(GVAR_DATA_EMPTY_VARIATIONS))
def test_compile_noVariations(self): font, gvar = self.makeFont({}) self.assertEqual(hexStr(gvar.compile(font)), hexStr(GVAR_DATA_EMPTY_VARIATIONS))
def test_compile_fromXML_format1(self): table = newTable('prop') for name, attrs, content in parseXML(PROP_FORMAT_1_XML): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(PROP_FORMAT_1_DATA))
def hexencode(s): h = hexStr(s).upper() return ' '.join([h[i:i+2] for i in range(0, len(h), 2)])
def compileFromXML(self, xml, data): table = newTable('bsln') for name, attrs, content in parseXML(xml): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(data))
def test_compile(self): font, cvar = self.makeFont() cvar.variations = CVAR_VARIATIONS self.assertEqual(hexStr(cvar.compile(font)), hexStr(CVAR_DATA))
def testCompileFromXML(self): table = newTable('gcid') for name, attrs, content in parseXML(GCID_XML): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(GCID_DATA))
def test_compile_fromXML_format0(self): table = newTable('lcar') for name, attrs, content in parseXML(LCAR_FORMAT_0_XML): table.fromXML(name, attrs, content, font=self.font) self.assertEqual(hexStr(table.compile(self.font)), hexStr(LCAR_FORMAT_0_DATA))