Repository: googlefonts/ufo2ft
Pull request #740 (2023-04-20 13:00:34)

Kern feature writer: Only use exported glyphs
Noto Sans Balinese isn't compiling today, because some unexpected glyphs are turning up in the generated features file. This turns out to be because of the kern feature writer. This PR makes it only use exported glyphs when forming mark filtering sets.


Patch:
diff --git a/Lib/ufo2ft/__init__.py b/Lib/ufo2ft/__init__.py
index c7b7f05..bdde532 100644
--- a/Lib/ufo2ft/__init__.py
+++ b/Lib/ufo2ft/__init__.py
@@ -223,6 +223,7 @@ compileTTF_args = {
         reverseDirection=True,
         rememberCurveType=True,
         flattenComponents=False,
+        autoUseMyMetrics=True,
     ),
 }
 
@@ -274,6 +275,7 @@ compileInterpolatableTTFs_args = {
         colrLayerReuse=False,
         colrAutoClipBoxes=False,
         extraSubstitutions=None,
+        autoUseMyMetrics=True,
     ),
 }
 
@@ -550,6 +552,7 @@ compileVariableTTF_args = {
         excludeVariationTables=(),
         optimizeGvar=True,
         colrAutoClipBoxes=False,
+        autoUseMyMetrics=True,
     ),
 }
 
diff --git a/Lib/ufo2ft/featureWriters/kernFeatureWriter.py b/Lib/ufo2ft/featureWriters/kernFeatureWriter.py
index 21027a4..a55ac64 100644
--- a/Lib/ufo2ft/featureWriters/kernFeatureWriter.py
+++ b/Lib/ufo2ft/featureWriters/kernFeatureWriter.py
@@ -386,7 +386,10 @@ class KernFeatureWriter(BaseFeatureWriter):
         lookup = ast.LookupBlock(name)
         if ignoreMarks and self.options.ignoreMarks:
             # We only want to filter the spacing marks
-            marks = self.context.gdefClasses.mark
+            marks = set(self.context.gdefClasses.mark or []) & set(
+                self.context.glyphSet.keys()
+            )
+
             spacing = []
             if marks:
                 spacing = [mark for mark in marks if self.context.font[mark].width != 0]
diff --git a/Lib/ufo2ft/outlineCompiler.py b/Lib/ufo2ft/outlineCompiler.py
index 16615a6..438d475 100644
--- a/Lib/ufo2ft/outlineCompiler.py
+++ b/Lib/ufo2ft/outlineCompiler.py
@@ -1414,6 +1414,30 @@ class OutlineTTFCompiler(BaseOutlineCompiler):
         "prep",
     }
 
+    def __init__(
+        self,
+        font,
+        glyphSet=None,
+        glyphOrder=None,
+        tables=None,
+        notdefGlyph=None,
+        colrLayerReuse=True,
+        colrAutoClipBoxes=True,
+        colrClipBoxQuantization=colrClipBoxQuantization,
+        autoUseMyMetrics=True,
+    ):
+        super().__init__(
+            font,
+            glyphSet=glyphSet,
+            glyphOrder=glyphOrder,
+            tables=tables,
+            notdefGlyph=notdefGlyph,
+            colrLayerReuse=colrLayerReuse,
+            colrAutoClipBoxes=colrAutoClipBoxes,
+            colrClipBoxQuantization=colrClipBoxQuantization,
+        )
+        self.autoUseMyMetrics = autoUseMyMetrics
+
     def compileGlyphs(self):
         """Compile and return the TrueType glyphs for this font."""
         allGlyphs = self.allGlyphs


Test patch:
diff --git a/tests/outlineCompiler_test.py b/tests/outlineCompiler_test.py
index bb357c3..7e43873 100644
--- a/tests/outlineCompiler_test.py
+++ b/tests/outlineCompiler_test.py
@@ -119,6 +119,11 @@ class OutlineTTFCompilerTest:
         for component in ttf["glyf"]["romanthree"].components:
             assert not (component.flags & USE_MY_METRICS)
 
+    def test_autoUseMyMetrics_False(self, use_my_metrics_ufo):
+        compiler = OutlineTTFCompiler(use_my_metrics_ufo, autoUseMyMetrics=False)
+        ttf = compiler.compile()
+        assert not (ttf["glyf"]["Iacute"].components[1].flags & USE_MY_METRICS)
+
     def test_autoUseMyMetrics_None(self, use_my_metrics_ufo):
         compiler = OutlineTTFCompiler(use_my_metrics_ufo)
         # setting 'autoUseMyMetrics' attribute to None disables the feature