From 3946a24208eb1def61b0dbef16081f7a3f5bdde8 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Thu, 29 Aug 2024 12:36:49 +0300 Subject: [PATCH] Drop disabled features entirely in minimal mode Partially fixes https://github.com/googlefonts/glyphsLib/issues/1026 by handling the case where we are building with fontmake. When round tripping is desired, the generated UFO when built with ufo2ft will still have the above issue. --- Lib/glyphsLib/builder/features.py | 4 ++++ tests/builder/features_test.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Lib/glyphsLib/builder/features.py b/Lib/glyphsLib/builder/features.py index 5e69d22a4..8a2109adc 100644 --- a/Lib/glyphsLib/builder/features.py +++ b/Lib/glyphsLib/builder/features.py @@ -58,6 +58,7 @@ def to_ufo_master_features(self, ufo, master): generate_GDEF=self.generate_GDEF, master=master, expand_includes=self.expand_includes, + minimal=self.minimal, ) @@ -84,6 +85,7 @@ def _to_ufo_features( # noqa: C901 generate_GDEF: bool = False, master: GSFontMaster | None = None, expand_includes: bool = False, + minimal: bool = False, ) -> str: """Convert GSFont features, including prefixes and classes, to UFO. @@ -118,6 +120,8 @@ def _to_ufo_features( # noqa: C901 feature_defs = [] for feature in font.features: + if feature.disabled and minimal: + continue code = expander.expand(feature.code) lines = ["feature %s {" % feature.name] notes = feature.notes diff --git a/tests/builder/features_test.py b/tests/builder/features_test.py index d08f1bf8b..837f7b918 100644 --- a/tests/builder/features_test.py +++ b/tests/builder/features_test.py @@ -600,6 +600,25 @@ def test_roundtrip_feature_prefix_with_only_a_comment(ufo_module): assert prefix_r.code == "#include(../family.fea)" +def test_drop_disabled_feature(ufo_module): + font = to_glyphs([ufo_module.Font()]) + feature = classes.GSFeature(name="ccmp", code="sub a by a.ccmp1 a.ccmp2;") + feature.disabled = True + font.features.append(feature) + + feature = classes.GSFeature(name="liga", code="sub f i by f_i;") + font.features.append(feature) + + (ufo,) = to_ufos(font, ufo_module=ufo_module, minimal=True) + assert ufo.features.text == dedent( + """\ + feature liga { + sub f i by f_i; + } liga; + """ + ) + + @pytest.fixture def ufo_with_GDEF(ufo_module): ufo = ufo_module.Font()