diff --git a/Lib/fontTools/otlLib/builder.py b/Lib/fontTools/otlLib/builder.py index 64cbc5e81..153e20e6f 100644 --- a/Lib/fontTools/otlLib/builder.py +++ b/Lib/fontTools/otlLib/builder.py @@ -377,12 +377,6 @@ class ChainContextualBuilder(LookupBuilder): candidates = [None, None, None, []] for rule in ruleset.rules: candidates[3].append(self.buildFormat3Subtable(rule, chaining)) - # Check we can build it - try: - self.getCompiledSize_(candidates[3]) - except Exception as e: - log.warning("Contextual format 3 at %s overflowed" % str(self.location)) - candidates[3] = None # Can we express the whole ruleset as a format 2 subtable? classdefs = ruleset.format2ClassDefs() @@ -390,21 +384,19 @@ class ChainContextualBuilder(LookupBuilder): candidates[2] = [ self.buildFormat2Subtable(ruleset, classdefs, chaining) ] - # Check we can build it - try: - self.getCompiledSize_(candidates[2]) - except Exception as e: - log.warning("Contextual format 2 at %s overflowed (%s)" % (str(self.location), e)) - candidates[2] = None if not ruleset.hasAnyGlyphClasses: candidates[1] = [self.buildFormat1Subtable(ruleset, chaining)] - # Check we can build it + + for i in [1, 2, 3]: try: - self.getCompiledSize_(candidates[1]) + self.getCompiledSize_(candidates[i]) except Exception as e: - log.warning("Contextual format 1 at %s overflowed" % str(self.location)) - candidates[1] = None + log.warning( + "Contextual format %i at %s overflowed (%s)" + % (i, str(self.location), e) + ) + candidates[i] = None candidates = [x for x in candidates if x is not None] if not candidates: