Repository: googlefonts/ufo2ft

Issue:
Kern writer fails when script tag not in `unicodedata.ot_tag_to_script`
The following OpenType script tags:

* byzm
* jamo
* math
* musc

return `None` when passed to `unicodedata.ot_tag_to_script`. (`byzm`/`math`/`musc` are considered Common script, so there's no sensible Unicode script tag to map them to, and `Jamo` should be manually mapped to 'Hang' but it isn't.)

This means that if any of them appear in a languagesystem statement, `ast.getScriptLanguageSystems` returns a dictionary with `None` keys:

https://github.com/googlefonts/ufo2ft/blob/0ee84954455cb3f451b32ab8df8509cefe025c72/Lib/ufo2ft/featureWriters/ast.py#L36-L38

and *that* means that `_groupScriptsByTagAndDirection` passes `None` to `unicodedata.script_horizontal_direction`

https://github.com/googlefonts/ufo2ft/blob/0ee84954455cb3f451b32ab8df8509cefe025c72/Lib/ufo2ft/featureWriters/kernFeatureWriter.py#L339-L340

and *that* causes a KeyError in the kern writer.

As a workaround, all of these are left-to-right when used as a primary script, so if we get a `None`, we might want to just force the direction to be `LTR`.

Discussion:

Patch:
diff --git a/Lib/ufo2ft/featureWriters/kernFeatureWriter.py b/Lib/ufo2ft/featureWriters/kernFeatureWriter.py
index 29b4833..aa08493 100644
--- a/Lib/ufo2ft/featureWriters/kernFeatureWriter.py
+++ b/Lib/ufo2ft/featureWriters/kernFeatureWriter.py
@@ -337,7 +337,10 @@ class KernFeatureWriter(BaseFeatureWriter):
         # direction (DFLT is excluded)
         scriptGroups = {}
         for scriptCode, scriptLangSys in feaScripts.items():
-            direction = unicodedata.script_horizontal_direction(scriptCode)
+            if scriptCode:
+                direction = unicodedata.script_horizontal_direction(scriptCode)
+            else:
+                direction = "LTR"
             if scriptCode in DIST_ENABLED_SCRIPTS:
                 tag = "dist"
             else:
diff --git a/requirements.txt b/requirements.txt
index 543339f..cffb47d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
 fonttools[ufo,lxml]==4.28.5
-defcon==0.9.0
+defcon==0.10.0
 cu2qu==1.6.7.post1
 compreffor==0.5.1.post1
 booleanOperations==0.9.0


Test patch:
diff --git a/tests/featureWriters/kernFeatureWriter_test.py b/tests/featureWriters/kernFeatureWriter_test.py
index fc2906f..a7fe869 100644
--- a/tests/featureWriters/kernFeatureWriter_test.py
+++ b/tests/featureWriters/kernFeatureWriter_test.py
@@ -499,6 +499,7 @@ class KernFeatureWriterTest(FeatureWriterTest):
             languagesystem arab URD;
             languagesystem deva dflt;
             languagesystem dev2 dflt;
+            languagesystem math dflt;
             """
         )
 
@@ -507,7 +508,10 @@ class KernFeatureWriterTest(FeatureWriterTest):
         scriptGroups = KernFeatureWriter._groupScriptsByTagAndDirection(scripts)
 
         assert "kern" in scriptGroups
-        assert list(scriptGroups["kern"]["LTR"]) == [("latn", ["dflt", "TRK "])]
+        assert list(scriptGroups["kern"]["LTR"]) == [
+            ("latn", ["dflt", "TRK "]),
+            ("math", ["dflt"]),
+        ]
         assert list(scriptGroups["kern"]["RTL"]) == [("arab", ["dflt", "URD "])]
 
         assert "dist" in scriptGroups