Skip to content

Commit

Permalink
new check: com.google.fonts/check/glyf_nested_components
Browse files Browse the repository at this point in the history
"Check that components do not reference glyphs which are themselves compontents"
(issue #2961)
  • Loading branch information
simoncozens authored Nov 10, 2020
1 parent 3fb45d1 commit 8cf2698
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ A more detailed list of changes is available in the corresponding milestones for
- **[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)
- **[com.google.fonts/check/STAT/gf-axisregistry]:** Check that particle names and values on STAT table match the fallback names in each axis registry at the Google Fonts Axis Registry (issue #3022)
- **[com.google.fonts/check/glyf_nested_components]:** Check that components do not reference glyphs which are themselves compontents (issue #2961)

### Changes to existing checks
- **[com.google.fonts/check/family/win_ascent_and_descent]**: Skip if font is cjk
Expand Down
31 changes: 31 additions & 0 deletions Lib/fontbakery/profiles/glyf.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,34 @@ def com_google_fonts_check_glyf_non_transformed_duplicate_components(ttFont):
else:
yield PASS, ("Glyphs do not contain duplicate components which have"
" the same x,y coordinates.")

@check(
id = 'com.google.fonts/check/glyf_nested_components',
rationale = "There have been bugs rendering variable fonts with nested components. Additionally, some static fonts with nested components have been reported to have rendering and printing issues. (See googlefonts/fontbakery#2961 and arrowtype/recursive#412.)",
conditions = ['is_ttf'],
misc_metadata = {
'request': 'https://github.com/googlefonts/fontbakery/issues/2961'
}
)
def com_google_fonts_check_glyf_nested_components(ttFont):
"""Check glyphs do not have components which are themselves components."""
from fontbakery.utils import pretty_print_list
failed = []
for glyph_name in ttFont['glyf'].keys():
glyph = ttFont['glyf'][glyph_name]
if not glyph.isComposite():
continue
for comp in glyph.components:
if ttFont['glyf'][comp.glyphName].isComposite():
failed.append(glyph_name)
if failed:
formatted_list = "\t* " + pretty_print_list(failed,
shorten=10,
sep="\n\t* ")
yield FAIL, \
Message('found-nested-components',
f"The following glyphs have components which"
f" themselves are component glyphs:\n"
f"{formatted_list}")
else:
yield PASS, ("Glyphs do not contain nested components.")
1 change: 1 addition & 0 deletions Lib/fontbakery/profiles/opentype.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
'com.google.fonts/check/maxadvancewidth',
'com.google.fonts/check/points_out_of_bounds',
'com.google.fonts/check/glyf_non_transformed_duplicate_components',
'com.google.fonts/check/glyf_nested_components',
'com.google.fonts/check/all_glyphs_have_codepoints',
'com.google.fonts/check/code_pages',
]
Expand Down
15 changes: 15 additions & 0 deletions tests/profiles/glyf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,18 @@ def test_check_glyf_non_transformed_duplicate_components():
assert_results_contain(check(ttFont),
FAIL, 'found-duplicates')


def test_check_glyf_nested_components():
"""Check glyphs do not have nested components."""
check = CheckTester(opentype_profile,
"com.google.fonts/check/glyf_nested_components")

ttFont = TTFont(TEST_FILE("nunito/Nunito-Regular.ttf"))
assert_PASS(check(ttFont))

# We need to create a nested component. "second" has components, so setting
# one of "quotedbl"'s components to "second" should do it.
ttFont['glyf']['quotedbl'].components[0].glyphName = "second"

assert_results_contain(check(ttFont),
FAIL, 'found-nested-components')

0 comments on commit 8cf2698

Please sign in to comment.