Skip to content

Commit

Permalink
googlefonts/axes_match: check added
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rc1e committed Sep 18, 2024
1 parent 400fdab commit 4d5d6db
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Lib/fontbakery/checks/vendorspecific/googlefonts/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,32 @@ def remote_styles(font):
continue
file_obj = download_file(dl_url)
if file_obj:
remote_fonts.append([filename, TTFont(file_obj)])
remote_fonts.append(TTFont(file_obj))

rstyles = {}
for remote_filename, remote_font in remote_fonts:
remote_style = os.path.splitext(remote_filename)[0]
if "-" in remote_style:
remote_style = remote_style.split("-")[1]
rstyles[remote_style] = remote_font
for font in remote_fonts:
if "fvar" in font:
for instance in font["fvar"].instances:
inst_subfamily = font["name"].getName(
instance.subfamilyNameID, 3, 1, 0x409
).toUnicode()
rstyles[inst_subfamily] = font
else:
rstyles[font["name"].getBestSubFamilyName()] = font
return rstyles


@condition(Font)
def remote_style(font):
font_style = font.ttFont["name"].getBestSubFamilyName()
remote_styles = font.remote_styles
if not remote_styles:
return None
if font_style in remote_styles:
return remote_styles[font.style]
return None


@condition(Font)
def regular_remote_style(font):
from fontbakery.checks.conditions import get_instance_axis_value
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 if a.axisTag != "opsz"}

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/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

0 comments on commit 4d5d6db

Please sign in to comment.