Skip to content

Commit

Permalink
Register lookups under DFLT, too
Browse files Browse the repository at this point in the history
  • Loading branch information
madig committed May 24, 2024
1 parent df592b1 commit 9ff6b49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
30 changes: 25 additions & 5 deletions Lib/ufo2ft/featureWriters/kernFeatureWriter2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions tests/featureWriters/kernFeatureWriter2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9ff6b49

Please sign in to comment.