From e45297bf4bbe76f8fb914c26df5050fc9daebfe9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 3 Feb 2017 14:33:57 -0800 Subject: [PATCH] Populate defaults even for tables that have postRead Implement custom populateDefaults for them. --- Lib/fontTools/ttLib/tables/otConverters.py | 3 ++- Lib/fontTools/ttLib/tables/otTables.py | 29 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Lib/fontTools/ttLib/tables/otConverters.py b/Lib/fontTools/ttLib/tables/otConverters.py index 446c9c7ee..4ff2156ae 100644 --- a/Lib/fontTools/ttLib/tables/otConverters.py +++ b/Lib/fontTools/ttLib/tables/otConverters.py @@ -361,8 +361,9 @@ class Struct(BaseConverter): else: pass + table.populateDefaults(propagator=getattr(font, '_propagator', None)) + if noPostRead: - table.populateDefaults(propagator=getattr(font, '_propagator', None)) if cleanPropagation: for conv in table.getConverters(): if conv.isPropagated: diff --git a/Lib/fontTools/ttLib/tables/otTables.py b/Lib/fontTools/ttLib/tables/otTables.py index c1833e7fe..5bebae809 100644 --- a/Lib/fontTools/ttLib/tables/otTables.py +++ b/Lib/fontTools/ttLib/tables/otTables.py @@ -37,6 +37,10 @@ class Coverage(FormatSwitchingBaseTable): # manual implementation to get rid of glyphID dependencies + def populateDefaults(self, propagator=None): + if not hasattr(self, 'glyphs'): + self.glyphs = [] + def postRead(self, rawTable, font): if self.Format == 1: # TODO only allow glyphs that are valid? @@ -136,6 +140,10 @@ class Coverage(FormatSwitchingBaseTable): class VarIdxMap(BaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, 'mapping'): + self.mapping = [] + def postRead(self, rawTable, font): assert (rawTable['EntryFormat'] & 0xFFC0) == 0 self.mapping = rawTable['mapping'] @@ -221,6 +229,10 @@ class VarData(BaseTable): class SingleSubst(FormatSwitchingBaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, 'mapping'): + self.mapping = {} + def postRead(self, rawTable, font): mapping = {} input = _getGlyphsFromCoverageTable(rawTable["Coverage"]) @@ -295,6 +307,11 @@ class SingleSubst(FormatSwitchingBaseTable): class MultipleSubst(FormatSwitchingBaseTable): + + def populateDefaults(self, propagator=None): + if not hasattr(self, 'mapping'): + self.mapping = {} + def postRead(self, rawTable, font): mapping = {} if self.Format == 1: @@ -368,6 +385,10 @@ class MultipleSubst(FormatSwitchingBaseTable): class ClassDef(FormatSwitchingBaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, 'classDefs'): + self.classDefs = {} + def postRead(self, rawTable, font): classDefs = {} glyphOrder = font.getGlyphOrder() @@ -485,6 +506,10 @@ class ClassDef(FormatSwitchingBaseTable): class AlternateSubst(FormatSwitchingBaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, 'alternates'): + self.alternates = {} + def postRead(self, rawTable, font): alternates = {} if self.Format == 1: @@ -551,6 +576,10 @@ class AlternateSubst(FormatSwitchingBaseTable): class LigatureSubst(FormatSwitchingBaseTable): + def populateDefaults(self, propagator=None): + if not hasattr(self, 'ligatures'): + self.ligatures = {} + def postRead(self, rawTable, font): ligatures = {} if self.Format == 1: