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

A couple new checks for the GF Axis Registry #3050

Merged
merged 1 commit into from
Oct 1, 2020
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ A more detailed list of changes is available in the corresponding milestones for


## 0.7.32 (2020-Oct-??)
- ...
### New checks
- **[com.google.fonts/check/metadata/gf-axisregistry_valid_tags]:** VF axis tags are registered on GF Axis Registry (issue #3010)
- **[com.google.fonts/check/metadata/gf-axisregistry_bounds]:** VF axes have ranges compliant to the bounds specified on the GF Axis Registry (issue #3022)


## 0.7.31 (2020-Sept-24)
Expand Down
65 changes: 64 additions & 1 deletion Lib/fontbakery/profiles/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
'com.google.fonts/check/metadata/canonical_style_names',
'com.google.fonts/check/metadata/broken_links',
'com.google.fonts/check/metadata/undeclared_fonts',
'com.google.fonts/check/metadata/category'
'com.google.fonts/check/metadata/category',
'com.google.fonts/check/metadata/gf-axisregistry_valid_tags',
'com.google.fonts/check/metadata/gf-axisregistry_bounds'
]

DESCRIPTION_CHECKS = [
Expand Down Expand Up @@ -4727,6 +4729,67 @@ def com_google_fonts_check_varfont_unsupported_axes(ttFont):
yield PASS, "Looks good!"


@check(
id = 'com.google.fonts/check/metadata/gf-axisregistry_bounds',
rationale = """
Each axis range in a METADATA.pb file must be registered, and within the bounds of the axis definition in the Google Fonts Axis Registry, available at https://github.com/google/fonts/tree/master/axisregistry
""",
conditions = ['is_variable_font',
'gfaxisregistry'],
misc_metadata = {
'request': 'https://github.com/googlefonts/fontbakery/issues/3010'
}
)
def com_google_fonts_check_gf_axisregistry_bounds(family_metadata, gfaxisregistry):
""" Validate METADATA.pb axes values are within gf-axisregistry bounds. """
passed = True
for axis in family_metadata.axes:
if axis.tag in gfaxisregistry.keys():
expected = gfaxisregistry[axis.tag]
if axis.min_value < expected["min"] or axis.max_value > expected["max"]:
passed = False
yield FAIL,\
Message('bad-axis-range',
f"The range in the font variation axis '{axis.tag}' ({expected['displayName']}"
f" min:{axis.min_value} max:{axis.max_value})"
f" does not comply with the expected maximum range, as defined on"
f" gf-axisregistry (min:{expected['min']} max:{expected['max']}).")
if passed:
yield PASS, "OK"


@check(
id = 'com.google.fonts/check/metadata/gf-axisregistry_valid_tags',
rationale = """
Ensure all axes in a METADATA.pb file are registered in the Google Fonts Axis Registry, available at https://github.com/google/fonts/tree/master/axisregistry

Why does Google Fonts have its own Axis Registry?

We support a superset of the OpenType axis registry axis set, and use additional metadata for each axis. Axes present in a font file but not in this registry will not function via our API. No variable font is expected to support all of the axes here.

Any font foundry or distributor library that offers variable fonts has a implicit, latent, de-facto axis registry, which can be extracted by scanning the library for axes' tags, labels, and min/def/max values. While in 2016 Microsoft originally offered to include more axes in the OpenType 1.8 specification (github.com/microsoft/OpenTypeDesignVariationAxisTags), as of August 2020, this effort has stalled. We hope more foundries and distributors will publish documents like this that make their axes explicit, to encourage of adoption of variable fonts throughout the industry, and provide source material for a future update to the OpenType specification's axis registry.
""",
conditions = ['is_variable_font',
'gfaxisregistry'],
misc_metadata = {
'request': 'https://github.com/googlefonts/fontbakery/issues/3022'
}
)
def com_google_fonts_check_gf_axisregistry_valid_tags(family_metadata, gfaxisregistry):
""" Validate METADATA.pb axes tags are defined in gf-axisregistry. """
passed = True
for axis in family_metadata.axes:
if axis.tag not in gfaxisregistry.keys():
passed = False
yield FAIL,\
Message('bad-axis-tag',
f"The font variation axis '{axis.tag}'"
f" is not yet registered on GF Axis Registry.")

if passed:
yield PASS, "OK"


###############################################################################

def is_librebarcode(font):
Expand Down
9 changes: 9 additions & 0 deletions Lib/fontbakery/profiles/googlefonts_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,12 @@ def production_metadata():
meta_url = "http://fonts.google.com/metadata/fonts"
# can't do requests.get("url").json() since request text starts with ")]}'"
return json.loads(requests.get(meta_url).text[5:])


@condition
def gfaxisregistry(production_metadata):
registry = {}
for entry in production_metadata['axisRegistry']:
registry[entry["tag"]] = entry
return registry

38 changes: 38 additions & 0 deletions tests/profiles/googlefonts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3370,3 +3370,41 @@ def test_check_varfont_unsupported_axes():
assert_results_contain(check(ttFont),
FAIL, 'unsupported-slnt')


def test_check_gfaxisregistry_bounds():
"""Validate METADATA.pb axes values are within gf-axisregistry bounds."""
check = CheckTester(googlefonts_profile,
"com.google.fonts/check/metadata/gf-axisregistry_bounds")
# Our reference varfont, CabinVF, has good axes bounds:
ttFont = TTFont(TEST_FILE("cabinvf/Cabin[wdth,wght].ttf"))
assert_PASS(check(ttFont))

# The first axis declared in this family is 'wdth' (Width)
# And the GF Axis Registry expects this axis to have a range
# not broader than min: 50 / max: 200
# So...
md = check["family_metadata"]
md.axes[0].min_value = 30
assert_results_contain(check(ttFont, {"family_metadata": md}),
FAIL, "bad-axis-range")

md.axes[0].min_value = 50
md.axes[0].max_value = 250
assert_results_contain(check(ttFont, {"family_metadata": md}),
FAIL, "bad-axis-range")


def test_check_gf_axisregistry_valid_tags():
"""Validate METADATA.pb axes tags are defined in gf-axisregistry."""
check = CheckTester(googlefonts_profile,
"com.google.fonts/check/metadata/gf-axisregistry_valid_tags")
# The axis tags in our reference varfont, CabinVF,
# are properly defined in the registry:
ttFont = TTFont(TEST_FILE("cabinvf/Cabin[wdth,wght].ttf"))
assert_PASS(check(ttFont))

md = check["family_metadata"]
md.axes[0].tag = "crap" # I'm pretty sure this one wont ever be included in the registry
assert_results_contain(check(ttFont, {"family_metadata": md}),
FAIL, "bad-axis-tag")

2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ commands = pylint --disable={[testenv:pylint]wont_fix},{[testenv:pylint]maybe_so
select = E,F,W

exclude =
# Exclude the entire build directory:
build
# Exclude this auto-generated file that should not be hand-edited:
Lib/fontbakery/fonts_public_pb2.py,
# No need to traverse hidden directories such as .git, .tox
Expand Down