Add with statement context manager like ttFont

This commit is contained in:
msoxzw 2019-10-21 07:03:45 +00:00 committed by GitHub
parent 28b685c9c0
commit fcbbce5ca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,16 @@ class TTCollection(object):
for i in range(header.numFonts):
font = TTFont(file, fontNumber=i, _tableCache=tableCache, **kwargs)
fonts.append(font)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
def close(self):
for font in self.fonts:
font.close()
def save(self, file, shareTables=True):
"""Save the font to disk. Similarly to the constructor,