diff --git a/CHANGELOG.md b/CHANGELOG.md index 38c948b9bc..2e1c66b033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,11 @@ A more detailed list of changes is available in the corresponding milestones for ## 0.7.11 (2019-Aug-16) ### Note-worthy code changes - - ... + - Add a few more keywords to log-messages (issue #2558) + ### New checks - **[com.google.fonts/check/metadata/undeclared_fonts]:** "Ensure METADATA.pb lists all font binaries" (issue #2575) + - **[com.google.fonts/check/varfont/slnt_range:]** "The variable font 'slnt' (Slant) axis coordinate specifies positive values in its range?" (issue #2572) ## 0.7.10 (2019-Aug-06) diff --git a/Lib/fontbakery/profiles/fvar.py b/Lib/fontbakery/profiles/fvar.py index 76f9a8c9cc..0a7138d4e5 100644 --- a/Lib/fontbakery/profiles/fvar.py +++ b/Lib/fontbakery/profiles/fvar.py @@ -256,3 +256,38 @@ def com_google_fonts_check_wdth_valid_range(ttFont): if not Failed: yield PASS, ("OK") + + +@check( + id = 'com.google.fonts/check/varfont/slnt_range', + rationale = """ + The OpenType spec says at + https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxistag_slnt that: + + [...] the scale for the Slant axis is interpreted as the angle of slant in + counter-clockwise degrees from upright. This means that a typical, right-leaning + oblique design will have a negative slant value. This matches the scale used for + the italicAngle field in the post table. + """, + conditions = ['is_variable_font', + 'slnt_axis'], + misc_metadata = { + 'request': 'https://github.com/googlefonts/fontbakery/issues/2572' + } +) +def com_google_fonts_check_varfont_slnt_range(ttFont, slnt_axis): + """ The variable font 'slnt' (Slant) axis coordinate + specifies positive values in its range? """ + + if slnt_axis.minValue < 0 and slnt_axis.maxValue >= 0: + yield PASS, "Looks good!" + else: + yield WARN,\ + Message("unusual-range", + f'The range of values for the "slnt" axis in' + f' this font only allows positive coordinates' + f' (from {slnt_axis.minValue} to {slnt_axis.maxValue}),' + f' indicating that this may be a back slanted design,' + f' which is rare. If that\'s not the case, then' + f' the "slant" axis should be a range of' + f' negative values instead.') diff --git a/Lib/fontbakery/profiles/opentype.py b/Lib/fontbakery/profiles/opentype.py index 4df1a78aa9..215fb621d9 100644 --- a/Lib/fontbakery/profiles/opentype.py +++ b/Lib/fontbakery/profiles/opentype.py @@ -45,6 +45,7 @@ 'com.google.fonts/check/varfont/regular_ital_coord', 'com.google.fonts/check/varfont/regular_opsz_coord', 'com.google.fonts/check/varfont/bold_wght_coord', + 'com.google.fonts/check/varfont/slnt_range', 'com.google.fonts/check/loca/maxp_num_glyphs', 'com.adobe.fonts/check/cff2_call_depth', 'com.adobe.fonts/check/cff_call_depth', diff --git a/Lib/fontbakery/profiles/shared_conditions.py b/Lib/fontbakery/profiles/shared_conditions.py index 9fb4ae49c3..d1738d7591 100644 --- a/Lib/fontbakery/profiles/shared_conditions.py +++ b/Lib/fontbakery/profiles/shared_conditions.py @@ -129,6 +129,13 @@ def is_variable_font(ttFont): return "fvar" in ttFont.keys() +@condition +def slnt_axis(ttFont): + for axis in ttFont["fvar"].axes: + if axis.axisTag == "slnt": + return axis + + def get_instance_axis_value(ttFont, instance_name, axis_tag): if not is_variable_font(ttFont): return None diff --git a/data/test/varfont/inter/Inter[slnt,wght].ttf b/data/test/varfont/inter/Inter[slnt,wght].ttf new file mode 100644 index 0000000000..b249391e47 Binary files /dev/null and b/data/test/varfont/inter/Inter[slnt,wght].ttf differ diff --git a/tests/profiles/fvar_test.py b/tests/profiles/fvar_test.py index c4f36c25ef..34176a473f 100644 --- a/tests/profiles/fvar_test.py +++ b/tests/profiles/fvar_test.py @@ -276,3 +276,26 @@ def test_check_wdth_valid_range(): print('Test FAIL with wght=1001...') status, message = list(check(ttFont))[-1] assert status == FAIL and message.code == "out-of-range" + + +def test_check_slnt_range(): + """ The variable font 'slnt' (Slant) axis coordinate + specifies positive values in its range? """ + from fontbakery.profiles.fvar import com_google_fonts_check_varfont_slnt_range as check + from fontbakery.profiles.shared_conditions import slnt_axis + + # Our reference Inter varfont has a bad slnt range + ttFont = TTFont("data/test/varfont/inter/Inter[slnt,wght].ttf") + status, message = list(check(ttFont, slnt_axis(ttFont)))[-1] + assert status == WARN and message.code == "unusual-range" + + # We then fix the font-bug by flipping the slnt axis range: + for i, axis in enumerate(ttFont["fvar"].axes): + if axis.axisTag == "slnt": + minValue, maxValue = axis.minValue, axis.maxValue + ttFont["fvar"].axes[i].minValue = -maxValue + ttFont["fvar"].axes[i].maxValue = -minValue + + # And it must now PASS + status, message = list(check(ttFont, slnt_axis(ttFont)))[-1] + assert status == PASS