diff --git a/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py b/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py index de4eb663..230e3bd4 100644 --- a/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py +++ b/Lib/ufo2ft/featureWriters/kernFeatureWriter2.py @@ -523,8 +523,28 @@ def _makeFeatureBlocks(self, lookups): return features def _registerKernLookups(self, feature, lookups): + # InDesign bugfix: register kerning lookups for all LTR scripts under DFLT + # so that the basic composer, without a language selected, will still kern. + # Register LTR lookups if any, otherwise RTL lookups. + dfltLookups = [] + ltrLookups = lookups.get("LTR") + rtlLookups = lookups.get("RTL") if "DFLT" in lookups: - ast.addLookupReferences(feature, lookups["DFLT"]) + dfltLookups.extend(lkp for lkp in lookups["DFLT"]) + dfltLookups.extend( + lkp for lkp in (ltrLookups or rtlLookups) if lkp not in dfltLookups + ) + ast.addLookupReferences(feature, dfltLookups) + ltrLookupsRest = ( + [lkp for lkp in ltrLookups if lkp not in dfltLookups] + if ltrLookups + else None + ) + rtlLookupsRest = ( + [lkp for lkp in rtlLookups if lkp not in dfltLookups] + if rtlLookups + else None + ) scriptGroups = self.context.scriptGroups if "dist" in self.context.todo: @@ -535,8 +555,6 @@ def _registerKernLookups(self, feature, lookups): ltrScripts = kernScripts.get("LTR", []) rtlScripts = kernScripts.get("RTL", []) - ltrLookups = lookups.get("LTR") - rtlLookups = lookups.get("RTL") if ltrLookups and rtlLookups: if ltrScripts and rtlScripts: for script, langs in ltrScripts: @@ -560,14 +578,16 @@ def _registerKernLookups(self, feature, lookups): ) elif ltrLookups: if not (rtlScripts or distScripts): - ast.addLookupReferences(feature, ltrLookups) + if ltrLookupsRest: + ast.addLookupReferences(feature, ltrLookupsRest) else: ast.addLookupReferences(feature, ltrLookups, script="DFLT") for script, langs in ltrScripts: ast.addLookupReferences(feature, ltrLookups, script, langs) elif rtlLookups: if not (ltrScripts or distScripts): - ast.addLookupReferences(feature, rtlLookups) + if rtlLookupsRest: + ast.addLookupReferences(feature, rtlLookupsRest) else: ast.addLookupReferences(feature, rtlLookups, script="DFLT") for script, langs in rtlScripts: diff --git a/tests/featureWriters/kernFeatureWriter2_test.py b/tests/featureWriters/kernFeatureWriter2_test.py index 6230126c..dcd99e6c 100644 --- a/tests/featureWriters/kernFeatureWriter2_test.py +++ b/tests/featureWriters/kernFeatureWriter2_test.py @@ -694,6 +694,7 @@ def test_kern_LTR_and_RTL(self, FontClass): feature kern { lookup kern_dflt; + lookup kern_ltr; script latn; language dflt; lookup kern_ltr; @@ -808,6 +809,8 @@ def test_kern_LTR_and_RTL_with_marks(self, FontClass): feature kern { lookup kern_dflt; + lookup kern_ltr; + lookup kern_ltr_marks; script latn; language dflt; lookup kern_ltr;