Skip to content

Commit

Permalink
Drop disabled features entirely in minimal mode
Browse files Browse the repository at this point in the history
Partially fixes #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.
  • Loading branch information
khaledhosny committed Aug 29, 2024
1 parent 7041311 commit 3946a24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Lib/glyphsLib/builder/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/builder/features_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3946a24

Please sign in to comment.