Skip to content

Commit

Permalink
Merge branch 'main' into bs-downgrade-panose-checks-to-warn
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstein authored Aug 31, 2023
2 parents 950fd4a + 6c7e00e commit b09d233
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ A more detailed list of changes is available in the corresponding milestones for
#### Added to the Google Fonts Profile
- **[com.google.fonts/check/metadata/primary_script]:** New check that guesses the primary script and compares to METADATA.pb (issue #4109)

#### Added to the UFO Profile
- **[com.thetypefounders/check/features_default_languagesystem]:** Checks if a default languagesystem statement is present in feature files and warns if the compiler will not insert one automatically (issue #4011)

### Changes to existing checks
#### On the Universal profile
- **[com.google.fonts/check/os2_metrics_match_hhea]:** Re-worded rationale text to be vendor-neutral (issue #4206)
Expand Down
49 changes: 48 additions & 1 deletion Lib/fontbakery/profiles/ufo_sources.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import re

from fontbakery.callable import check, condition
from fontbakery.status import ERROR, FAIL, PASS, WARN
from fontbakery.status import ERROR, FAIL, PASS, SKIP, WARN
from fontbakery.section import Section
from fontbakery.message import Message
from fontbakery.fonts_profile import profile_factory
from fontbakery.utils import exit_with_install_instructions


profile = profile_factory(default_section=Section("UFO Sources"))

UFO_PROFILE_CHECKS = [
Expand All @@ -16,6 +19,7 @@
"com.google.fonts/check/designspace_has_default_master",
"com.google.fonts/check/designspace_has_consistent_glyphset",
"com.google.fonts/check/designspace_has_consistent_codepoints",
"com.thetypefounders/check/features_default_languagesystem",
]


Expand Down Expand Up @@ -303,5 +307,48 @@ def com_google_fonts_check_designspace_has_consistent_codepoints(designSpace, co
yield PASS, "Unicode assignments were consistent."


@check(
id="com.thetypefounders/check/features_default_languagesystem",
conditions=["ufo_font"],
rationale="""
The feature file specification strongly recommends to use a
`languagesystem DFLT dflt` statement in your feature file. This
statement is automatically inserted when no `languagesystem`
statements are present in the feature file, *unless* there is
another `languagesystem` statement already present. If this is
the case, this behaviour could lead to unintended side effects.
This check only WARNs when this happen as there are cases where
not having a `languagesystem DFLT dflt` statement in your feature
file is technically correct.
http://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileSpecification.html#4b-language-system
""",
proposal="https://github.com/googlefonts/fontbakery/issues/4011",
)
def com_thetypefounders_check_features_default_languagesystem(ufo_font):
"""Check that languagesystem DFLT dflt is present in the features.fea file."""

if ufo_font.features.text is None:
yield SKIP, "No features.fea file in font."
elif not ufo_font.features.text.strip():
yield PASS, "Default languagesystem inserted by compiler."
else:
tags = re.findall(
# pylint: disable-next=line-too-long
r"languagesystem\s+([A-Za-z0-9\._!$%&*+:?^'|~]{1,4})\s+([A-Za-z0-9\._!$%&*+:?^'|~]{1,4})", # noqa E501
ufo_font.features.text,
)

if len(tags) > 0 and ("DFLT", "dflt") != tags[0]:
tags_str = ", ".join([" ".join(t) for t in tags])
yield WARN, Message(
"default-languagesystem",
f"Default languagesystem not found in: {tags_str}.",
)
else:
yield PASS, "Default languagesystem present or automatically inserted."


profile.auto_register(globals())
profile.test_expected_checks(UFO_PROFILE_CHECKS, exclusive=True)
71 changes: 71 additions & 0 deletions tests/profiles/ufo_sources_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from fontbakery.codetesting import (
assert_PASS,
assert_results_contain,
assert_SKIP,
CheckTester,
TEST_FILE,
)
Expand Down Expand Up @@ -171,3 +172,73 @@ def test_check_designspace_has_consistent_codepoints():
assert_results_contain(check(designspace), FAIL, "inconsistent-codepoints")

# TODO: Fix it and ensure it passes the check


def test_check_default_languagesystem_pass_without_features(empty_ufo_font):
"""Pass if the UFO source has no features."""
check = CheckTester(
ufo_sources_profile, "com.thetypefounders/check/features_default_languagesystem"
)

ufo, _ = empty_ufo_font

assert_SKIP(check(ufo), "No features.fea file in font.")


def test_check_default_languagesystem_pass_with_empty_features(empty_ufo_font):
"""Pass if the UFO source has a feature file but it is empty."""
check = CheckTester(
ufo_sources_profile, "com.thetypefounders/check/features_default_languagesystem"
)

ufo, _ = empty_ufo_font

ufo.features.text = ""

assert_PASS(check(ufo))


def test_check_default_languagesystem_pass_with_features(empty_ufo_font):
"""Pass if the font has features and no default languagesystem statements."""
check = CheckTester(
ufo_sources_profile, "com.thetypefounders/check/features_default_languagesystem"
)

ufo, _ = empty_ufo_font

ufo.features.text = "feature liga { sub f i by f_i; } liga;"

assert_PASS(check(ufo))


def test_check_default_languagesystem_warn_without_default_languagesystem(
empty_ufo_font,
):
"""Warn if `languagesystem DFLT dflt` is not present in the feature file,
but other languagesystem statements are."""
check = CheckTester(
ufo_sources_profile, "com.thetypefounders/check/features_default_languagesystem"
)

ufo, _ = empty_ufo_font

ufo.features.text = (
"languagesystem latn dflt; feature liga { sub f i by f_i; } liga;"
)

assert_results_contain(check(ufo), WARN, "default-languagesystem")


def test_check_default_languagesystem_pass_with_default_languagesystem(empty_ufo_font):
"""Pass if `languagesystem DFLT dflt` is explicitly used in the features."""
check = CheckTester(
ufo_sources_profile, "com.thetypefounders/check/features_default_languagesystem"
)

ufo, _ = empty_ufo_font

ufo.features.text = """languagesystem DFLT dflt;
languagesystem latn dflt;
feature liga { sub f i by f_i; } liga;"""

assert_PASS(check(ufo))

0 comments on commit b09d233

Please sign in to comment.