def test_known_toString(self): self.entry.tag = Tag('head') self.entry.flags = getKnownTagIndex(self.entry.tag) self.entry.origLength = 54 expectedSize = (woff2FlagsSize + base128Size(self.entry.origLength)) data = self.entry.toString() self.assertEqual(len(data), expectedSize)
def test_loca_zero_transformLength(self): data = bytechr(getKnownTagIndex('loca')) # flags data += packBase128(random.randint(1, 100)) # origLength data += packBase128(1) # non-zero transformLength with self.assertRaisesRegex( ttLib.TTLibError, "transformLength of the 'loca' table must be 0"): self.entry.fromString(data)
def test_transformed_toString(self): self.entry.tag = Tag('glyf') self.entry.flags = getKnownTagIndex(self.entry.tag) self.entry.origLength = random.randint(101, 200) self.entry.length = random.randint(1, 100) expectedSize = (woff2FlagsSize + base128Size(self.entry.origLength) + base128Size(self.entry.length)) data = self.entry.toString() self.assertEqual(len(data), expectedSize)
def test_fromFile(self): unknownTag = Tag('ZZZZ') data = bytechr(getKnownTagIndex(unknownTag)) data += unknownTag.tobytes() data += packBase128(random.randint(1, 100)) expectedPos = len(data) f = BytesIO(data + b'\0'*100) self.entry.fromFile(f) self.assertEqual(f.tell(), expectedPos)
def test_glyf_loca_transform_flags(self): for tag in ("glyf", "loca"): entry = WOFF2DirectoryEntry() entry.tag = Tag(tag) entry.flags = getKnownTagIndex(entry.tag) self.assertEqual(entry.transformVersion, 0) self.assertTrue(entry.transformed) entry.transformed = False self.assertEqual(entry.transformVersion, 3) self.assertEqual(entry.flags & 0b11000000, (3 << 6)) self.assertFalse(entry.transformed)