[feaLib.builder] don't error when specific kern pairs conflict

Fixes #1147
This commit is contained in:
Cosimo Lupo 2018-01-15 18:43:10 +00:00
parent 60f2c741c3
commit 27d40f5160
No known key found for this signature in database
GPG Key ID: 59D54DB0C9976482

View File

@ -9,6 +9,10 @@ from fontTools.otlLib import builder as otl
from fontTools.ttLib import newTable, getTableModule from fontTools.ttLib import newTable, getTableModule
from fontTools.ttLib.tables import otBase, otTables from fontTools.ttLib.tables import otBase, otTables
import itertools import itertools
import logging
log = logging.getLogger(__name__)
def addOpenTypeFeatures(font, featurefile): def addOpenTypeFeatures(font, featurefile):
@ -1424,15 +1428,20 @@ class PairPosBuilder(LookupBuilder):
key = (glyph1, glyph2) key = (glyph1, glyph2)
oldValue = self.glyphPairs.get(key, None) oldValue = self.glyphPairs.get(key, None)
if oldValue is not 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] otherLoc = self.locations[key]
raise FeatureLibError( log.warning(
'Already defined position for pair %s %s at %s:%d:%d' 'Already defined position for pair %s %s at %s:%d:%d; '
% (glyph1, glyph2, otherLoc[0], otherLoc[1], otherLoc[2]), 'choosing the first value',
location) glyph1, glyph2, otherLoc[0], otherLoc[1], otherLoc[2])
val1, _ = makeOpenTypeValueRecord(value1, pairPosContext=True) val1, val2 = oldValue
val2, _ = makeOpenTypeValueRecord(value2, pairPosContext=True) else:
self.glyphPairs[key] = (val1, val2) val1, _ = makeOpenTypeValueRecord(value1, pairPosContext=True)
self.locations[key] = location val2, _ = makeOpenTypeValueRecord(value2, pairPosContext=True)
self.glyphPairs[key] = (val1, val2)
self.locations[key] = location
def add_subtable_break(self, location): def add_subtable_break(self, location):
self.pairs.append((self.SUBTABLE_BREAK_, self.SUBTABLE_BREAK_, self.pairs.append((self.SUBTABLE_BREAK_, self.SUBTABLE_BREAK_,