From 5e830ac984682aab93d990b203f2c6c39458b529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Fri, 18 Feb 2022 05:11:48 -0300 Subject: [PATCH] Use `gflanguages` module to check sample rendering 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) --- CHANGELOG.md | 4 +++ Lib/fontbakery/profiles/googlefonts.py | 47 ++++++++++++++++++++------ requirements.txt | 1 + setup.py | 1 + 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc1c830675..15ecd40087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Lib/fontbakery/profiles/googlefonts.py b/Lib/fontbakery/profiles/googlefonts.py index 18d02dc024..9c7eac3d61 100644 --- a/Lib/fontbakery/profiles/googlefonts.py +++ b/Lib/fontbakery/profiles/googlefonts.py @@ -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." diff --git a/requirements.txt b/requirements.txt index 1eef1609c8..6a98bd2ea9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/setup.py b/setup.py index 6be24e10ba..868bdd32f8 100644 --- a/setup.py +++ b/setup.py @@ -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