From 6243a24a0952dfea5373bce5d5dc9f9df1c1822c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 23 Mar 2021 18:13:07 -0700 Subject: [PATCH] [otBase] Delete .Format if was introduced by .preWrite() https://github.com/fonttools/fonttools/pull/2238#issuecomment-805192631 --- Lib/fontTools/ttLib/tables/otBase.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lib/fontTools/ttLib/tables/otBase.py b/Lib/fontTools/ttLib/tables/otBase.py index 5ce32c17b..c47e940f0 100644 --- a/Lib/fontTools/ttLib/tables/otBase.py +++ b/Lib/fontTools/ttLib/tables/otBase.py @@ -654,9 +654,15 @@ class BaseTable(object): def compile(self, writer, font): self.ensureDecompiled() + # TODO Following hack to be removed by rewriting how FormatSwitching tables + # are handled. + # https://github.com/fonttools/fonttools/pull/2238#issuecomment-805192631 if hasattr(self, 'preWrite'): + deleteFormat = not hasattr(self, 'Format') table = self.preWrite(font) + deleteFormat = deleteFormat and hasattr(self, 'Format') else: + deleteFormat = False table = self.__dict__.copy() # some count references may have been initialized in a custom preWrite; we set @@ -740,6 +746,9 @@ class BaseTable(object): if conv.isPropagated: writer[conv.name] = value + if deleteFormat: + del self.Format + def readFormat(self, reader): pass