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 committed Aug 29, 2024
1 parent 3946a24 commit acac402
Show file tree
Hide file tree
Showing 2 changed files with 40 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 @@ -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)
Expand All @@ -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(
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 @@ -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;")
Expand Down

0 comments on commit acac402

Please sign in to comment.