Repository: googlefonts/glyphsLib
Pull request #796 (2022-07-18 12:06:05)

Set feature for designspace rules
Glyphs has a mechanism (the "Feature for Feature Variations" custom parameter) for setting which feature should be used for processing bracket rules. This implements that custom parameter, passing the feature information to designspace. If the user requests `rclt`, we set `processing=last` on the rules tag; otherwise, we use the equivalent designspace lib key `com.github.fonttools.varLib.featureVarsFeatureTag`.


Patch:
diff --git a/Lib/glyphsLib/builder/builders.py b/Lib/glyphsLib/builder/builders.py
index d9fcb420..6ea2476f 100644
--- a/Lib/glyphsLib/builder/builders.py
+++ b/Lib/glyphsLib/builder/builders.py
@@ -22,6 +22,7 @@ from textwrap import dedent
 from typing import Any, Dict
 
 from fontTools import designspaceLib
+from fontTools.varLib import FEAVAR_FEATURETAG_LIB_KEY
 
 from glyphsLib import classes, glyphdata, util
 from .constants import (
@@ -492,6 +493,13 @@ class UFOBuilder(_LoggerMixin):
                 )
                 self._designspace.addRule(rule)
 
+        # Set feature for rules
+        feat = self.font.customParameters["Feature for Feature Variations"]
+        if feat == "rclt":
+            self._designspace.rulesProcessingLast = True
+        elif feat and feat != "rvrn":
+            self._designspace.lib[FEAVAR_FEATURETAG_LIB_KEY] = feat
+
         # Finally, copy bracket layers to their own glyphs.
         self._copy_bracket_layers_to_ufo_glyphs(bracket_layer_map)
 


Test patch:
diff --git a/tests/builder/designspace_gen_test.py b/tests/builder/designspace_gen_test.py
index be8161e6..7c4d0229 100644
--- a/tests/builder/designspace_gen_test.py
+++ b/tests/builder/designspace_gen_test.py
@@ -18,6 +18,7 @@ import io
 import os
 from fontTools.designspaceLib import DesignSpaceDocument
 from xmldiff import main, formatting
+from fontTools.varLib import FEAVAR_FEATURETAG_LIB_KEY
 
 import itertools
 import pytest
@@ -508,3 +509,26 @@ def test_designspace_generation_bracket_glyphs3_simple(datadir, ufo_module):
 
     for source in designspace.sources:
         assert "A.BRACKET.600" in source.font
+
+
+def test_designspace_generation_bracket_rclt_roundtrip(datadir, ufo_module):
+    with open(str(datadir.join("BracketTestFont.glyphs"))) as f:
+        font = glyphsLib.load(f)
+    font.customParameters["Feature for Feature Variations"] = "rclt"
+    designspace = to_designspace(font, ufo_module=ufo_module)
+    assert designspace.rulesProcessingLast
+
+    font_rt = to_glyphs(designspace)
+    assert font_rt.customParameters["Feature for Feature Variations"] == "rclt"
+
+
+def test_designspace_generation_bracket_other_roundtrip(datadir, ufo_module):
+    with open(str(datadir.join("BracketTestFont.glyphs"))) as f:
+        font = glyphsLib.load(f)
+    font.customParameters["Feature for Feature Variations"] = "calt"
+    designspace = to_designspace(font, ufo_module=ufo_module)
+    assert FEAVAR_FEATURETAG_LIB_KEY in designspace.lib
+    assert designspace.lib[FEAVAR_FEATURETAG_LIB_KEY] == "calt"
+
+    font_rt = to_glyphs(designspace)
+    assert font_rt.customParameters["Feature for Feature Variations"] == "calt"