Skip to content

Commit

Permalink
new check: googlefonts/axes_match
Browse files Browse the repository at this point in the history
"Check the font isn't missing any axes and the axes have the same range as the Google Fonts version."
Added to the Google Fonts profile.

(PR #4836)
  • Loading branch information
m4rc1e authored and felipesanches committed Sep 19, 2024
1 parent 4701794 commit 1c87ecc
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ A more detailed list of changes is available in the corresponding milestones for
- As this is the **"a0" pre-release**, there may be additional migrations and renames of checks, before we make an actual **v0.13.0** release. Please open an issue if you have suggestions of better names or better profile allocations.
- **[FontBakeryCondition:remote_styles]:** Use the Google Fonts family name to fetch the family. (PR #4838)

### New checks
#### Added to the Google Fonts profile
- **[googlefonts/axes_match]**: Check the font isn't missing any axes and the axes have the same range as the Google Fonts version. (PR #4836)

### Changes to existing checks
#### On the Google Fonts profile
- **[googlefonts/glyphsets/shape_languages]:** Improve formatting of output to avoid excessively long reports. (issue #4781)
Expand Down
45 changes: 45 additions & 0 deletions Lib/fontbakery/checks/vendorspecific/googlefonts/varfont.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,51 @@
from fontbakery.utils import markdown_table


@check(
id="googlefonts/axes_match",
conditions=["remote_style"],
rationale="""
An updated font family must include the same axes found in the Google "
Fonts version, with the same axis ranges.
""",
)
def check_axes_match(ttFont, remote_style):
"""Check if the axes match between the font and the Google Fonts version."""
remote_axes = {
a.axisTag: (a.minValue, a.maxValue) for a in remote_style["fvar"].axes
}
font_axes = {a.axisTag: (a.minValue, a.maxValue) for a in ttFont["fvar"].axes}

missing_axes = []
for axis, remote_axis_range in remote_axes.items():
if axis not in font_axes:
missing_axes.append(axis)
continue
axis_range = font_axes[axis]
axis_min, axis_max = axis_range
remote_axis_min, remote_axis_max = remote_axis_range
if axis_min > remote_axis_min:
yield FAIL, Message(
"axis-min-out-of-range",
f"Axis '{axis}' min value is out of range."
f" Expected '{remote_axis_min}', got '{axis_min}'.",
)
if axis_max < remote_axis_max:
yield FAIL, Message(
"axis-max-out-of-range",
f"Axis {axis} max value is out of range."
f" Expected {remote_axis_max}, got {axis_max}.",
)

if missing_axes:
yield FAIL, Message(
"missing-axes",
f"Missing axes: {', '.join(missing_axes)}",
)
else:
yield PASS, "Axes match Google Fonts version."


@check(
id="googlefonts/STAT",
conditions=["is_variable_font", "expected_font_names"],
Expand Down
1 change: 1 addition & 0 deletions Lib/fontbakery/profiles/fontwerk.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"fontdata_namecheck",
],
"pending_review": [
"googlefonts/axes_match",
"typographic_family_name",
"vtt_volt_data", # very similar to vttclean, may be a good idea to merge them.
#
Expand Down
1 change: 1 addition & 0 deletions Lib/fontbakery/profiles/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"googlefonts/version_bump",
"googlefonts/vertical_metrics",
"googlefonts/vertical_metrics_regressions",
"googlefonts/axes_match",
],
},
"configuration_defaults": {
Expand Down
50 changes: 50 additions & 0 deletions tests/test_checks_googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3932,6 +3932,56 @@ def test_check_fvar_instances(fp, mod, result):
)


@pytest.mark.parametrize(
"""fp,mod,result,code""",
[
(TEST_FILE("cabinvf/Cabin[wdth,wght].ttf"), [], PASS, None),
# Drop weight has so this should fail since gf version has it
(
TEST_FILE("cabinvf/Cabin[wdth,wght].ttf"),
["wght", None, None],
FAIL,
"missing-axes",
),
# Change ranges of weight axis to 500-600, this should fail since gf version has 400-700
(
TEST_FILE("cabinvf/Cabin[wdth,wght].ttf"),
["wght", 500, None],
FAIL,
"axis-min-out-of-range",
),
(
TEST_FILE("cabinvf/Cabin[wdth,wght].ttf"),
["wght", None, 600],
FAIL,
"axis-max-out-of-range",
),
],
)
def test_check_axes_match(fp, mod, result, code):
"""Check if the axes match between the font and the Google Fonts version."""
check = CheckTester("googlefonts/axes_match")
ttFont = TTFont(fp)
if mod:
name, min_val, max_val = mod
if not min_val and not max_val:
ttFont["fvar"].axes = [a for a in ttFont["fvar"].axes if a.axisTag != name]
else:
axis = next(a for a in ttFont["fvar"].axes if a.axisTag == name)
axis.minValue = min_val or axis.minValue
axis.maxValue = max_val or axis.maxValue

if result == PASS:
assert_PASS(check(ttFont), "with a good font")
elif result == FAIL:
assert_results_contain(
check(ttFont),
FAIL,
code,
"with a bad font",
)


@pytest.mark.parametrize(
"""fps,new_stat,result""",
[
Expand Down

0 comments on commit 1c87ecc

Please sign in to comment.