From 27d40f5160d946c8643d71280bbc3bf6b9dc1438 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Mon, 15 Jan 2018 18:43:10 +0000 Subject: [PATCH] [feaLib.builder] don't error when specific kern pairs conflict Fixes #1147 --- Lib/fontTools/feaLib/builder.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index 4ec7ea9aa..0dd0c283e 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -9,6 +9,10 @@ from fontTools.otlLib import builder as otl from fontTools.ttLib import newTable, getTableModule from fontTools.ttLib.tables import otBase, otTables import itertools +import logging + + +log = logging.getLogger(__name__) def addOpenTypeFeatures(font, featurefile): @@ -1424,15 +1428,20 @@ class PairPosBuilder(LookupBuilder): key = (glyph1, glyph2) oldValue = self.glyphPairs.get(key, None) if oldValue is not None: + # the Feature File spec explicitly allows specific pairs generated + # by an 'enum' rule to be overridden by preceding single pairs; + # we emit a warning and use the previously defined value otherLoc = self.locations[key] - raise FeatureLibError( - 'Already defined position for pair %s %s at %s:%d:%d' - % (glyph1, glyph2, otherLoc[0], otherLoc[1], otherLoc[2]), - location) - val1, _ = makeOpenTypeValueRecord(value1, pairPosContext=True) - val2, _ = makeOpenTypeValueRecord(value2, pairPosContext=True) - self.glyphPairs[key] = (val1, val2) - self.locations[key] = location + log.warning( + 'Already defined position for pair %s %s at %s:%d:%d; ' + 'choosing the first value', + glyph1, glyph2, otherLoc[0], otherLoc[1], otherLoc[2]) + val1, val2 = oldValue + else: + val1, _ = makeOpenTypeValueRecord(value1, pairPosContext=True) + val2, _ = makeOpenTypeValueRecord(value2, pairPosContext=True) + self.glyphPairs[key] = (val1, val2) + self.locations[key] = location def add_subtable_break(self, location): self.pairs.append((self.SUBTABLE_BREAK_, self.SUBTABLE_BREAK_,