From 3946a24208eb1def61b0dbef16081f7a3f5bdde8 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Thu, 29 Aug 2024 12:36:49 +0300 Subject: [PATCH 1/2] 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() From acac402a3b239d2e47ed4a00874f0364e7692ecf Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Thu, 29 Aug 2024 12:46:45 +0300 Subject: [PATCH 2/2] Drop disabled prefixes and classes in minimal mode Partially fixes https://github.com/googlefonts/glyphsLib/issues/761 and https://github.com/googlefonts/glyphsLib/issues/763. --- Lib/glyphsLib/builder/features.py | 4 ++++ tests/builder/features_test.py | 36 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Lib/glyphsLib/builder/features.py b/Lib/glyphsLib/builder/features.py index 8a2109adc..444e27b0a 100644 --- a/Lib/glyphsLib/builder/features.py +++ b/Lib/glyphsLib/builder/features.py @@ -98,6 +98,8 @@ def _to_ufo_features( # noqa: C901 prefixes = [] for prefix in font.featurePrefixes: + if prefix.disabled and minimal: + continue strings = [] if prefix.name != ANONYMOUS_FEATURE_PREFIX_NAME: strings.append("# Prefix: %s\n" % prefix.name) @@ -109,6 +111,8 @@ def _to_ufo_features( # noqa: C901 class_defs = [] for class_ in font.classes: + if class_.disabled and minimal: + continue prefix = "@" if not class_.name.startswith("@") else "" name = prefix + class_.name class_defs.append( diff --git a/tests/builder/features_test.py b/tests/builder/features_test.py index 837f7b918..7578389e5 100644 --- a/tests/builder/features_test.py +++ b/tests/builder/features_test.py @@ -600,6 +600,42 @@ def test_roundtrip_feature_prefix_with_only_a_comment(ufo_module): assert prefix_r.code == "#include(../family.fea)" +def test_drop_disabled_class(ufo_module): + font = to_glyphs([ufo_module.Font()]) + class_ = classes.GSClass(name="Class1", code="a b") + class_.disabled = True + font.classes.append(class_) + + class_ = classes.GSClass(name="Class2", code="c d") + font.classes.append(class_) + + (ufo,) = to_ufos(font, ufo_module=ufo_module, minimal=True) + assert ufo.features.text == dedent( + """\ + @Class2 = [ c d + ]; + """ + ) + + +def test_drop_disabled_prefix(ufo_module): + font = to_glyphs([ufo_module.Font()]) + prefix = classes.GSFeaturePrefix(name="Prefix1", code="# test 1") + prefix.disabled = True + font.featurePrefixes.append(prefix) + + prefix = classes.GSFeaturePrefix(name="Prefix2", code="# test 2") + font.featurePrefixes.append(prefix) + + (ufo,) = to_ufos(font, ufo_module=ufo_module, minimal=True) + assert ufo.features.text == dedent( + """\ + # Prefix: Prefix2 + # test 2 + """ + ) + + 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;")