Skip to content

Commit

Permalink
new check: com.google.fonts/check/STAT/axis_order
Browse files Browse the repository at this point in the history
INFO-level check to gather stats on usage of the STAT table AxisOrdering field.
May be updated in the future to enforce some ordering scheme yet to be defined.
(issue fonttools#3049)
  • Loading branch information
felipesanches committed Oct 23, 2020
1 parent 7b047fc commit 5b811a0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A more detailed list of changes is available in the corresponding milestones for
- Now Travis is configured to use pinned versions of dependencies as described on requirements.txt (issue #3058)

### New checks
- **[com.google.fonts/check/STAT/axis_order]:** INFO-level check to gather stats on usage of the STAT table AxisOrdering field. May be updated in the future to enforce some ordering scheme yet to be defined. (issue #3049)
- **[com.google.fonts/check/metadata/consistent_axis_enumeration]:** Validate VF axes on the 'fvar' table match the ones declared on METADATA.pb (issue #3051)
- **[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)
Expand Down
49 changes: 48 additions & 1 deletion Lib/fontbakery/profiles/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@
'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/STAT/gf-axisregistry'
'com.google.fonts/check/STAT/gf-axisregistry',
'com.google.fonts/check/STAT/axis_order'
]

GOOGLEFONTS_PROFILE_CHECKS = \
Expand Down Expand Up @@ -4887,6 +4888,52 @@ def com_google_fonts_check_metadata_consistent_axis_enumeration(family_metadata,
yield PASS, "OK"


@check(
id = 'com.google.fonts/check/STAT/axis_order',
rationale = """
This is (for now) a merely informative check to detect what's the axis ordering declared on the STAT table of fonts in the Google Fonts collection.
We may later update this to enforce some unified axis ordering scheme, yet to be determined.
""",
misc_metadata = {
'request': 'https://github.com/googlefonts/fontbakery/issues/3049'
}
)
def com_google_fonts_check_STAT_axis_order(fonts):
""" Check axis ordering on the STAT table. """
from collections import Counter
from fontTools.ttLib import TTFont

no_stat = 0
summary = []
for font in fonts:
try:
ttFont = TTFont(font)
if 'STAT' in ttFont:
order = {}
for axis in ttFont['STAT'].table.DesignAxisRecord.Axis:
order[axis.AxisTag] = axis.AxisOrdering

summary.append('-'.join(sorted(order.keys(), key=order.get)))
else:
no_stat += 1
yield SKIP,\
Message('missing-STAT',
f"This font does not have a STAT table.")
except:
yield INFO, f"Something wrong with {font}"

report = "\n\t".join(map(str, Counter(summary).most_common()))
yield INFO,\
Message('summary',
f"From a total of {len(fonts)} font files,"
f" {no_stat} of them ({100.0*no_stat/len(fonts):.2f}%)"
f" lack a STAT table.\n"
f"\n"
f"\tAnd these are the most common STAT axis orderings:\n"
f"\t{report}")


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

def is_librebarcode(font):
Expand Down

0 comments on commit 5b811a0

Please sign in to comment.