Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A more detailed list of changes is available in the corresponding milestones for
## Upcoming release: 0.8.11 (2022-Oct-??)
### 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)
- **[com.google.fonts/check/colorfont_tables]:** Check if fonts contain the correct color tables. (issue #3886)
- **[com.google.fonts/check/description/noto_has_article]:** Noto fonts must have an ARTICLE.en_us.html file. (issue #3841)
- **[com.google.fonts/check/slant_direction]:** Check slant direction of outline to match values of slnt axis extrema. (PR #3910)
- **[com.google.fonts/check/color_cpal_brightness]:** Warn if COLRv0 layers are colored too dark or too bright instead of foreground color. (PR #3908)
Expand Down
55 changes: 32 additions & 23 deletions Lib/fontbakery/profiles/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6220,34 +6220,43 @@ def com_google_fonts_check_metadata_category_hint(family_metadata):
@check(
id = "com.google.fonts/check/colorfont_tables",
rationale = """
No one color font format supports all major user agents, but the combination
of COLR & SVG tables is pretty good.
Colr v0 fonts are widely supported in most browsers so they do not require
an SVG color table. However, Colr v1 is only well supported in Chrome so
we need to add an SVG table to these fonts.

A smart server could prune away one or the other based on user agent,
and a dumb server will at least have something that works.

Fonts that do not pass this check can be fixed with the maximum_color tool
available at https://github.com/googlefonts/nanoemoji
To add an SVG table, run the maximum_color tool in Nano Emoji,
https://github.com/googlefonts/nanoemoji
""",
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 '."""
SUGGESTED_FIX = ("To fix this, please run the font through the maximum_color tool"
" that installs as part of the nanoemoji package"
" (https://github.com/googlefonts/nanoemoji)")
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. " + SUGGESTED_FIX)
elif 'COLR' not in ttFont.keys() and 'SVG ' in ttFont.keys():
yield FAIL,\
Message('missing-table',
"This is a color font (it has a 'SVG ' table)"
" but it lacks an 'COLR' table. " + SUGGESTED_FIX)
else:
yield PASS, "Looks good!"
"""Check font has the expected color font tables"""
if "COLR" in ttFont:
colr_table = ttFont["COLR"]
if colr_table.version == 0 and "SVG " in ttFont:
yield FAIL, Message(
Comment thread
m4rc1e marked this conversation as resolved.
"drop-svg",
"Font has a COLR v0 table, which is already widely supported, "
"so the SVG table isn't needed."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adobe CC does not support COLR table (and probably will not do any time soon, given the Adobe’s history with SVG table), so if a font for GF want to also support Adobe CC, do you want to force it to ship to versions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm fair enough.. I would demote that check to a WARNING, saying that COLRv0-only is OK for browser use, unless you really need SVG support for desktop apps that don't support COLR. They probably want to keep things simple and not allow too many options when onboarding new color fonts. /cc @rsheeter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khaledhosny maybe file a separate issue so we can discuss there

)
return
elif colr_table.version == 1 and "SVG " not in ttFont:
yield FAIL, Message(
"add-svg",
"Font has COLRv1 but no SVG table; for CORLv1, we require "
"that an SVG table is present to support environments where "
"the former is not supported yet."
)
return
elif "SVG " in ttFont:
if "COLR" not in ttFont:
yield FAIL, Message(
"add-colr",
"Font only has an SVG table. Please add a COLR table as well. "
)
return
yield PASS, "Looks Good!"



@check(
Expand Down
28 changes: 19 additions & 9 deletions tests/profiles/googlefonts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4227,33 +4227,43 @@ def test_check_override_freetype_rasterizer(mock_import_error):


def test_check_colorfont_tables():
"""Fonts must have neither or both the tables 'COLR' and 'SVG '."""
"""Fonts must have neither or both the tables 'COLR' and 'SVG'."""
from fontTools.ttLib import newTable
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 'COLR' in ttFont.keys()
# Check colr v1 font has an svg table. Will fail since font
# doesn't have one.
assert_results_contain(check(ttFont),
FAIL, 'missing-table',
FAIL, 'add-svg',
'with a color font lacking SVG table')

# Fake an SVG table:
ttFont["SVG "] = "fake!"
ttFont["SVG "] = newTable('SVG ')
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:
# Now downgrade to colr table to v0:
ttFont["COLR"].version = 0
assert 'SVG ' in ttFont.keys()
assert_results_contain(check(ttFont),
FAIL, 'drop-svg',
'with a font which should not have an SVG table')

# Delete colr table and keep SVG:
del ttFont["COLR"]
assert 'COLR' not in ttFont.keys()
assert 'SVG ' in ttFont.keys()
assert 'COLR' not in ttFont.keys()
assert_results_contain(check(ttFont),
FAIL, 'missing-table',
'with a font with SVG table but no COLR table.')
FAIL, 'add-colr',
'with a font which should have a COLR table')

# Finally, get rid of both:
#finally delete both color font tables
del ttFont["SVG "]
assert 'SVG ' not in ttFont.keys()
assert 'COLR' not in ttFont.keys()
Expand Down