return self so one can do font=TTFont(file).ensureDecompiled()

This commit is contained in:
Cosimo Lupo 2022-03-17 15:44:02 +00:00
parent 46f33357cb
commit 61e7b29448
4 changed files with 10 additions and 1 deletions

View File

@ -162,6 +162,7 @@ class table__c_m_a_p(DefaultTable.DefaultTable):
def ensureDecompiled(self):
for st in self.tables:
st.ensureDecompiled()
return self
def compile(self, ttFont):
self.tables.sort() # sort according to the spec; see CmapSubtable.__lt__()
@ -245,6 +246,7 @@ class CmapSubtable(object):
self.data = None # Once this table has been decompiled, make sure we don't
# just return the original data. Also avoids recursion when
# called with an attribute that the cmap subtable doesn't have.
return self
def __getattr__(self, attr):
# allow lazy decompilation of subtables.

View File

@ -115,6 +115,7 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
def ensureDecompiled(self):
for glyph in self.glyphs.values():
glyph.expand(self)
return self
def compile(self, ttFont):
if not hasattr(self, "glyphOrder"):

View File

@ -110,6 +110,7 @@ class BaseTTXConverter(DefaultTable):
def ensureDecompiled(self):
self.table.ensureDecompiled(recurse=True)
return self
# https://github.com/fonttools/fonttools/pull/2285#issuecomment-834652928
@ -609,6 +610,7 @@ class BaseTable(object):
if recurse:
for subtable in self.iterSubTables():
subtable.ensureDecompiled(recurse)
return self
@classmethod
def getRecordSize(cls, reader):

View File

@ -379,12 +379,16 @@ class TTFont(object):
return ["GlyphOrder"] + keys
def ensureDecompiled(self):
"""Decompile all the tables, even if a TTFont was opened in 'lazy' mode."""
"""Decompile all the tables, even if a TTFont was opened in 'lazy' mode.
Returns the same TTFont instance, fully decompiled.
"""
for tag in self.keys():
table = self[tag]
if self.lazy is not False and hasattr(table, "ensureDecompiled"):
table.ensureDecompiled()
self.lazy = False
return self
def __len__(self):
return len(list(self.keys()))