Skip to content

Commit

Permalink
Use gflanguages module to check sample rendering
Browse files Browse the repository at this point in the history
com.google.fonts/check/metadata/can_render_samples

Check that the fonts can render the sample texts for all languages specified on METADATA.pb, by using the new `gflanguages` module.
(issue fonttools#3605)
  • Loading branch information
felipesanches committed Feb 18, 2022
1 parent dd5d924 commit 5e830ac
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ A more detailed list of changes is available in the corresponding milestones for
### Noteworthy code-changes
- On the GitHub Markdown reporter, checks which produce all the same output for a range of fonts are now automatically clustered into a family check result. (PR #3610)

### Changes to existing checks
#### On the Google Fonts Profile
- **[com.google.fonts/check/metadata/can_render_samples]:** Check that the fonts can render the sample texts for all languages specified on METADATA.pb, by using the new `gflanguages` module (issue #3605)


## 0.8.7 (2022-Feb-17)
### Noteworthy code-changes
Expand Down
47 changes: 36 additions & 11 deletions Lib/fontbakery/profiles/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5892,26 +5892,51 @@ def com_google_fonts_check_repo_sample_image(readme_contents, readme_directory,
In order to prevent tofu from being seen on fonts.google.com, this check verifies that all samples provided on METADATA.pb can be properly rendered by the font.
""",
conditions = ["family_metadata"],
proposal = 'https://github.com/googlefonts/fontbakery/issues/3419',
proposal = ['https://github.com/googlefonts/fontbakery/issues/3419',
'https://github.com/googlefonts/fontbakery/issues/3605']
)
def com_google_fonts_check_metadata_can_render_samples(ttFont, family_metadata):
"""Check samples can be rendered."""
from fontbakery.utils import can_shape
from gflanguages import lang_support

passed = True
if not family_metadata.sample_glyphs:
yield SKIP,\
passed = False
yield INFO,\
Message('no-samples',
'No sample_glyphs on METADATA.pb')
return
else:
for name, glyphs in family_metadata.sample_glyphs.items():
if not can_shape(ttFont, glyphs):
passed = False
yield FAIL,\
Message('sample-glyphs',
f"Font can't render the following sample glyphs:\n"
f"'{name}': '{glyphs}'")

languages = lang_support.LoadLanguages()
for lang in family_metadata.languages:
# Note: checking agains all samples often results in
# a way too verbose output. That's why I only left
# the "tester" string for now.
SAMPLES = {
#'styles': languages[lang].sample_text.styles,
'tester': languages[lang].sample_text.tester,
#'specimen_16': languages[lang].sample_text.specimen_16,
#'specimen_21': languages[lang].sample_text.specimen_21,
#'specimen_32': languages[lang].sample_text.specimen_32,
#'specimen_36': languages[lang].sample_text.specimen_36,
#'specimen_48': languages[lang].sample_text.specimen_48
}
for sample_type, sample_text in SAMPLES.items():
if not can_shape(ttFont, sample_text):
passed = False
yield FAIL,\
Message('sample-text',
f'Font can\'t render "{lang}" sample text:\n'
f'"{sample_text}"\n')

passed = True
for name, glyphs in family_metadata.sample_glyphs.items():
if not can_shape(ttFont, glyphs):
passed = False
yield FAIL,\
Message('sample-glyphs',
f"Font can't render the following sample glyphs:\n"
f"'{name}': '{glyphs}'")
if passed:
yield PASS, "OK."

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defcon==0.10.0
dehinter==4.0.0
fontTools[ufo,lxml,unicode]==4.29.1
font-v==2.1.0
gflanguages==0.1.1
glyphsets==0.2.1
lxml==4.8.0
opentype-sanitizer==8.2.1
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
'dehinter>=3.1.0', # 3.1.0 added dehinter.font.hint function
'fontTools[ufo,lxml,unicode]>=3.34', # 3.34 fixed some CFF2 issues, including calcBounds
'font-v',
'gflanguages>=0.1.1', # 0.1.0 had a crash bug (see: https://github.com/felipesanches/gflanguages/pull/3)
'glyphsets',
'lxml',
'opentype-sanitizer>=7.1.9', # 7.1.9 fixes caret value format = 3 bug
Expand Down

0 comments on commit 5e830ac

Please sign in to comment.