Skip to content

Commit

Permalink
New Check: check/colorfont_tables
Browse files Browse the repository at this point in the history
"Fonts must have neither or both the tables `COLR` and `SVG`."
com.google.fonts/check/colorfont_tables

Added to the Google Fonts Profile.
(issue #3886)
  • Loading branch information
felipesanches committed Aug 25, 2022
1 parent 2b83c46 commit 58fe813
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ A more detailed list of changes is available in the corresponding milestones for


## Upcoming release: 0.8.11 (2022-Sep-??)
- ...
### New Checks
#### Added to the Google Fonts Profile
- **[com.google.fonts/check/colorfont_tables]:** Fonts must have neither or both the tables `COLR` and `SVG`. (issue #3886)


## 0.8.10 (2022-Aug-25)
Expand Down
24 changes: 24 additions & 0 deletions Lib/fontbakery/profiles/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
'com.google.fonts/check/no_debugging_tables',
'com.google.fonts/check/render_own_name',
'com.google.fonts/check/STAT',
'com.google.fonts/check/colorfont_tables',
]

GOOGLEFONTS_PROFILE_CHECKS = \
Expand Down Expand Up @@ -6147,6 +6148,29 @@ def com_google_fonts_check_metadata_category_hint(family_metadata):
yield PASS, "OK."


@check(
id = "com.google.fonts/check/colorfont_tables",
rationale = """
""", # FIXME: add a rationale text!
proposal = 'https://github.com/googlefonts/fontbakery/issues/3886'
)
def com_google_fonts_check_colorfont_tables(ttFont):
"""Fonts must have neither or both the tables 'COLR' and 'SVG'."""
if 'COLR' in ttFont.keys() and 'SVG' not in ttFont.keys():
yield FAIL,\
Message('missing-table',
"This is a color font (it has a 'COLR' table)"
" but it lacks an 'SVG' table.")
elif 'COLR' not in ttFont.keys() and 'SVG' in ttFont.keys():
yield FAIL,\
Message('missing-table',
"This does not seem to be a color font (it lacks a 'COLR' table)"
" but an 'SVG' table was found.")
else:
yield PASS, "Looks good!"


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

def is_librebarcode(font):
Expand Down
35 changes: 35 additions & 0 deletions tests/profiles/googlefonts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4213,3 +4213,38 @@ def test_check_override_freetype_rasterizer(mock_import_error):
font = TEST_FILE("cabin/Cabin-Regular.ttf")
msg = assert_results_contain(check(font), FAIL, "freetype-not-installed")
assert "FreeType is not available" in msg


def test_check_colorfont_tables():
"""Fonts must have neither or both the tables 'COLR' and 'SVG'."""
check = CheckTester(googlefonts_profile,
"com.google.fonts/check/colorfont_tables")

ttFont = TTFont(TEST_FILE("color_fonts/noto-glyf_colr_1.ttf"))
assert 'COLR' in ttFont.keys()
assert 'SVG' not in ttFont.keys()
assert_results_contain(check(ttFont),
FAIL, 'missing-table',
'with a color font lacking SVG table')

# Fake an SVG table:
ttFont["SVG"] = "fake!"
assert 'SVG' in ttFont.keys()
assert 'COLR' in ttFont.keys()
assert_PASS(check(ttFont),
f'with a font containing both tables.')

# Now remove the COLR one:
del ttFont["COLR"]
assert 'COLR' not in ttFont.keys()
assert 'SVG' in ttFont.keys()
assert_results_contain(check(ttFont),
FAIL, 'missing-table',
'with a font with SVG table but no COLR table.')

# Finally, get rid of both:
del ttFont["SVG"]
assert 'SVG' not in ttFont.keys()
assert 'COLR' not in ttFont.keys()
assert_PASS(check(ttFont),
f'with a good font without SVG or COLR tables.')

0 comments on commit 58fe813

Please sign in to comment.