ttCollection: fix 'ResourceWarning: unclosed file'

Thanks Mike L.
This commit is contained in:
Cosimo Lupo 2022-03-10 18:12:23 +00:00
parent ebe313d70e
commit c08bfc1e1a

View File

@ -26,8 +26,10 @@ class TTCollection(object):
assert 'fontNumber' not in kwargs, kwargs
closeStream = False
if not hasattr(file, "read"):
file = open(file, "rb")
closeStream = True
tableCache = {} if shareTables else None
@ -36,6 +38,9 @@ class TTCollection(object):
font = TTFont(file, fontNumber=i, _tableCache=tableCache, **kwargs)
fonts.append(font)
if closeStream:
file.close()
def __enter__(self):
return self