Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old kern writer: register lookups under DFLT, too #844

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions Lib/ufo2ft/featureWriters/kernFeatureWriter2.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,29 @@ def _makeFeatureBlocks(self, lookups):
return features

def _registerKernLookups(self, feature, lookups):
# InDesign bugfix: register kerning lookups for all LTR scripts under DFLT
madig marked this conversation as resolved.
Show resolved Hide resolved
# so that the basic composer, without a language selected, will still kern.
# Register LTR lookups if any, otherwise RTL lookups.
# See https://github.com/googlefonts/ufo2ft/pull/787.
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 +556,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 +579,16 @@ def _registerKernLookups(self, feature, lookups):
)
elif ltrLookups:
if not (rtlScripts or distScripts):
ast.addLookupReferences(feature, ltrLookups)
if ltrLookupsRest:
ast.addLookupReferences(feature, ltrLookupsRest)
anthrotype marked this conversation as resolved.
Show resolved Hide resolved
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm this looks suspicious..
the global languagesystems contain both LTR and RTL scripts in this particular test font (I see both latn and arab), if you register kern_ltr in the top part of the feature block before any explicit script/language declarations then it will be registered for all the globally defined languagesystems, but do we actually want to register the kern_ltr under arab?! Probably not. I don't know if it is benign or just plain wrong

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If kern_ltr includes kerning between common characters (e.g. punctuation or digits) it would be wrong to register it for arab, otherwise it should be redundant and tiny bit slow but otherwise harmless.

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
Loading