Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop disabled prefixes, classes, and features in minimal mode #1027

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 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 All @@ -96,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 @@ -107,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 All @@ -118,6 +124,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
55 changes: 55 additions & 0 deletions tests/builder/features_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,61 @@ 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;")
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
Loading