Skip to content

Commit

Permalink
Drop disabled prefixes and classes in minimal mode
Browse files Browse the repository at this point in the history
Partially fixes #761 and
#763.
  • Loading branch information
khaledhosny authored and schriftgestalt committed Oct 23, 2024
1 parent 4176d60 commit 691c74a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Lib/glyphsLib/builder/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,22 @@ def _to_ufo_features( # noqa: C901
else:
expander = TokenExpander(font, master)

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)
strings.append(autostr(prefix.automatic))
strings.append(expander.expand(prefix.code))
prefixes.append("".join(strings))

prefix_str = "\n\n".join(prefixes)

class_defs = []
for class_ in font.classes:
if not class_.active: # TODO: (gs) write them commented out as with the features to be able to round trip
if class_.disabled and minimal:
continue
prefix = "@" if not class_.name.startswith("@") else ""
name = prefix + class_.name
Expand Down
36 changes: 36 additions & 0 deletions tests/builder/features_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,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;")
Expand Down

0 comments on commit 691c74a

Please sign in to comment.