Skip to content

Commit

Permalink
Check that particle names on STAT table match the fallback names...
Browse files Browse the repository at this point in the history
...in each axis registry at the Google Fonts Axis Registry
(issue #3022)
  • Loading branch information
felipesanches committed Oct 15, 2020
1 parent 8764d16 commit cf2f385
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A more detailed list of changes is available in the corresponding milestones for
### 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)
- **[com.google.fonts/check/STAT/gf-axisregistry]:** Check that particle names and values on STAT table match the fallback names in each axis registry at the Google Fonts Axis Registry (issue #3022)


## 0.7.31 (2020-Sept-24)
Expand Down
52 changes: 51 additions & 1 deletion Lib/fontbakery/profiles/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@
'com.google.fonts/check/varfont_instance_names',
'com.google.fonts/check/varfont_duplicate_instance_names',
'com.google.fonts/check/varfont/consistent_axes',
'com.google.fonts/check/varfont/unsupported_axes'
'com.google.fonts/check/varfont/unsupported_axes',
'com.google.fonts/check/STAT/gf-axisregistry'
]

GOOGLEFONTS_PROFILE_CHECKS = \
Expand Down Expand Up @@ -4790,6 +4791,55 @@ def com_google_fonts_check_gf_axisregistry_valid_tags(family_metadata, GFAxisReg
yield PASS, "OK"


@check(
id = 'com.google.fonts/check/STAT/gf-axisregistry',
rationale = """
Check that particle names and values on STAT table match the fallback names in each axis registry at 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/3022'
}
)
def com_google_fonts_check_STAT_gf_axisregistry_names(ttFont, GFAxisRegistry):
""" Validate STAT particle names and values match the fallback names in GFAxisRegistry. """
passed = True
for axis_value in ttFont['STAT'].table.AxisValueArray.AxisValue:
axis = ttFont['STAT'].table.DesignAxisRecord.Axis[axis_value.AxisIndex]
if axis.AxisTag in GFAxisRegistry.keys():
expected = GFAxisRegistry[axis.AxisTag]
expected_names = [fb.name for fb in expected.fallback]
for name_entry in ttFont['name'].names:
if name_entry.nameID == axis_value.ValueNameID:
# Here "name_entry" has the user-friendly name of the current AxisValue
# We want to ensure that this string shows up as a "fallback" name
# on the GF Axis Registry for this specific variation axis tag.
found_fallback = False
for fb in expected.fallback:
if name_entry.toUnicode() == fb.name:
found_fallback = True
if axis_value.Value != fb.value:
yield FAIL, \
Message("bad-coordinate",
(f"Axis Value for '{fb.name}' is expected to be 'fb.value'"
f" but this font has '{fb.name}'='{axis_value.Value}'."))
break

if not found_fallback:
passed = False
yield FAIL, \
Message('invalid-name',
f"The name '{name_entry.toUnicode()}' is not among the expected ones"
f" according to the Google Fonts Axis Registry:"
f" {expected_names}")
break # Here we assume that it is enough to check for only the first occurence of a given nameID
# It is up to other checks to ensure all different platform/encoding entries with a given nameID
# are consistent in the name table.
if passed:
yield PASS, "OK"


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

def is_librebarcode(font):
Expand Down

0 comments on commit cf2f385

Please sign in to comment.