Skip to content

Commit

Permalink
New check: com.google.fonts/check/STAT_strings
Browse files Browse the repository at this point in the history
Check correctness of name table strings referenced by STAT table
(issue fonttools#2863)
  • Loading branch information
felipesanches committed May 14, 2020
1 parent e9b04fa commit 6f515a9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@ A more detailed list of changes is available in the corresponding milestones for
## 0.7.25 (2020-May-??)
### New checks
- **[com.google.fonts/check/varfont/unsupported_axes]**: Ensure VFs do not contain opsz or ital axes. (issue #2866)
- **[com.google.fonts/check/STAT_strings]**: Check correctness of name table strings referenced by STAT table. (issue #2863)

### Added rationale metadata to these checks
- **com.google.fonts/check/vendor_id**
Expand Down
46 changes: 46 additions & 0 deletions Lib/fontbakery/profiles/universal.py
Expand Up @@ -42,6 +42,7 @@
'com.google.fonts/check/unique_glyphnames',
# 'com.google.fonts/check/glyphnames_max_length',
'com.google.fonts/check/family/vertical_metrics',
'com.google.fonts/check/STAT_strings'
]

@check(
Expand Down Expand Up @@ -545,6 +546,51 @@ def com_google_fonts_check_unwanted_tables(ttFont):
yield PASS, "There are no unwanted tables."


@condition
def STAT_table(ttFont):
return "STAT" in ttFont


@check(
id = 'com.google.fonts/check/STAT_strings',
conditions = ["STAT_table"],
rationale = """
On the STAT table, the "Italic" keyword must not be used on AxisValues for variation axes other than 'ital'.
""",
misc_metadata = {
'requested': "https://github.com/googlefonts/fontbakery/issues/2863"
}
)
def com_google_fonts_check_STAT_strings(ttFont):
""" Check correctness of STAT table strings """
passed = True
ital_axis_index = None
for index, axis in enumerate(ttFont["STAT"].table.DesignAxisRecord.Axis):
if axis.AxisTag == 'ital':
ital_axis_index = index
break

nameIDs = []
for value in ttFont["STAT"].table.AxisValueArray.AxisValue:
if value.AxisIndex != ital_axis_index: nameIDs.append(value.ValueNameID)

bad_values = []
for name in ttFont['name'].names:
if name.nameID in nameIDs and "italic" in name.toUnicode().lower():
passed = False
bad_values.append(name.toUnicode())

if bad_values:
yield FAIL,\
Message("bad-italic",
f'The following AxisValue entries on the STAT table'
f' should not contain "Italic":\n'
f' {bad_values}')

if passed:
yield PASS, "Looks good!"


@check(
id = 'com.google.fonts/check/valid_glyphnames',
rationale = """
Expand Down
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/profiles/universal_test.py
Expand Up @@ -690,3 +690,13 @@ def test_check_superfamily_vertical_metrics(montserrat_ttFonts, cabin_ttFonts, c
status, message = list(check([cabin_ttFonts,
montserrat_ttFonts]))[-1]
assert status == WARN

def test_check_STAT_strings():
from fontbakery.profiles.universal import com_google_fonts_check_STAT_strings as check
print("Test pass...")
status, message = list(check(TTFont(TEST_FILE("ibmplexsans-vf/IBMPlexSansVar-Roman.ttf"))))[-1]
assert status == PASS

print("Test fail...")
status, message = list(check(TTFont(TEST_FILE("ibmplexsans-vf/IBMPlexSansVar-Italic.ttf"))))[-1]
assert status == FAIL

0 comments on commit 6f515a9

Please sign in to comment.