Skip to content

Commit

Permalink
new check: com.google.fonts/check/varfont/slnt_range
Browse files Browse the repository at this point in the history
The variable font 'slnt' (Slant) axis coordinate
specifies positive values in its range?
(issue fonttools#2572)
  • Loading branch information
felipesanches committed Aug 9, 2019
1 parent 5440a62 commit a0fb6ca
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions Lib/fontbakery/profiles/fvar.py
Expand Up @@ -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.')
1 change: 1 addition & 0 deletions Lib/fontbakery/profiles/opentype.py
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions Lib/fontbakery/profiles/shared_conditions.py
Expand Up @@ -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
Expand Down
Binary file added data/test/varfont/inter/Inter[slnt,wght].ttf
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/profiles/fvar_test.py
Expand Up @@ -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

0 comments on commit a0fb6ca

Please sign in to comment.