From 811662396ceb428f4415614d4877ff301b3c5df4 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Tue, 19 Sep 2023 21:03:38 +0100 Subject: [PATCH 1/8] When reporting font_codepoints, look beyond the BMP --- Lib/fontbakery/profiles/googlefonts.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Lib/fontbakery/profiles/googlefonts.py b/Lib/fontbakery/profiles/googlefonts.py index 79742635c1..5bc1fcd828 100644 --- a/Lib/fontbakery/profiles/googlefonts.py +++ b/Lib/fontbakery/profiles/googlefonts.py @@ -1043,14 +1043,7 @@ def com_google_fonts_check_vendor_id(ttFont, registered_vendor_ids): @condition def font_codepoints(ttFont): - codepoints = set() - for table in ttFont["cmap"].tables: - if ( - table.platformID == PlatformID.WINDOWS - and table.platEncID == WindowsEncodingID.UNICODE_BMP - ): - codepoints.update(table.cmap.keys()) - return codepoints + return set(ttFont.getBestCmap().keys()) @check( From 062dccb13057f5d46c77f938e82fdf40fd418c98 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Tue, 19 Sep 2023 21:04:27 +0100 Subject: [PATCH 2/8] Report codepoints with no subset definition at all --- Lib/fontbakery/profiles/googlefonts.py | 29 +++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Lib/fontbakery/profiles/googlefonts.py b/Lib/fontbakery/profiles/googlefonts.py index 5bc1fcd828..338118d228 100644 --- a/Lib/fontbakery/profiles/googlefonts.py +++ b/Lib/fontbakery/profiles/googlefonts.py @@ -1180,12 +1180,6 @@ def com_google_fonts_check_metadata_unreachable_subsetting( yield PASS, "OK" return - message = """The following codepoints supported by the font are not covered by - any subsets defined in the font's metadata file, and will never - be served. You can solve this by either manually adding additional - subset declarations to METADATA.pb, or by editing the glyphset - definitions.\n\n""" - unreachable = [] subsets_for_cps = defaultdict(set) # This is faster than calling SubsetsForCodepoint for each codepoint @@ -1195,23 +1189,30 @@ def com_google_fonts_check_metadata_unreachable_subsetting( subsets_for_cps[cp].add(subset) for codepoint in sorted(font_codepoints): - subsets = subsets_for_cps[codepoint] - if not subsets: - continue + subsets_for_cp = subsets_for_cps[codepoint] - if len(subsets) > 1: - subsets = "one of: " + ", ".join(subsets) + if len(subsets_for_cp) == 0: + message = "not included in any glyphset definition" + elif len(subsets_for_cp) == 1: + message = "try adding " + ", ".join(subsets_for_cp) else: - subsets = ", ".join(subsets) + message = "try adding one of: " + ", ".join(subsets_for_cp) try: name = unicodedata2.name(chr(codepoint)) except Exception: name = "" - unreachable.append(" * U+%04X %s: try adding %s" % (codepoint, name, subsets)) + unreachable.append(" * U+%04X %s: %s" % (codepoint, name, message)) + + + message = """The following codepoints supported by the font are not covered by + any subsets defined in the font's metadata file, and will never + be served. You can solve this by either manually adding additional + subset declarations to METADATA.pb, or by editing the glyphset + definitions.\n\n""" - subsets = ", ".join(f"`{s}`" for s in family_metadata.subsets) + subsets = ", ".join(f"`{s}`" for s in subsets) message += pretty_print_list(config, unreachable, sep="\n", glue="\n") message += ( f"\n\nOr you can add the above codepoints to one" From 9059a8340ce898ffde76afa3f7a8ff7434b87c77 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Tue, 19 Sep 2023 21:04:45 +0100 Subject: [PATCH 3/8] When we don't have a METADATA.pb (we are upstream), work out what subsets apply --- Lib/fontbakery/profiles/googlefonts.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Lib/fontbakery/profiles/googlefonts.py b/Lib/fontbakery/profiles/googlefonts.py index 338118d228..bd3337f72d 100644 --- a/Lib/fontbakery/profiles/googlefonts.py +++ b/Lib/fontbakery/profiles/googlefonts.py @@ -1159,21 +1159,39 @@ def com_google_fonts_check_metadata_unsupported_subsets( will not be served in the subsetted fonts, and so will be unreachable to the end user. """, - conditions=["family_metadata"], proposal="https://github.com/fonttools/fontbakery/issues/4097", severity=2, ) def com_google_fonts_check_metadata_unreachable_subsetting( - family_metadata, ttFont, font_codepoints, config + family_directory, font, ttFont, font_codepoints, config ): """Check for codepoints not covered by METADATA subsets.""" from glyphsets import codepoints from fontbakery.utils import pretty_print_list + from fontbakery.profiles.googlefonts_conditions import ( + metadata_file, + family_metadata, + ) import unicodedata2 codepoints.set_encoding_path(codepoints.nam_dir) - for subset in family_metadata.subsets: + # Use the METADATA.pb subsets if we have them + metadatapb = metadata_file(family_directory) + if metadatapb: + metadata = family_metadata(metadatapb) + if metadata: + subsets = metadata.subsets + else: + yield FAIL, Message( + "unparsable-metadata", "Could not parse metadata.pb file" + ) + return + else: + # Follow what the packager would do + subsets = [s[0] for s in codepoints.SubsetsInFont(font, 50, 0.01)] + + for subset in subsets: font_codepoints = font_codepoints - set(codepoints.CodepointsInSubset(subset)) if not font_codepoints: @@ -1205,7 +1223,6 @@ def com_google_fonts_check_metadata_unreachable_subsetting( unreachable.append(" * U+%04X %s: %s" % (codepoint, name, message)) - message = """The following codepoints supported by the font are not covered by any subsets defined in the font's metadata file, and will never be served. You can solve this by either manually adding additional From 6959673d0e6937c83f50790e0c596b65fc3102d7 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Tue, 19 Sep 2023 21:06:40 +0100 Subject: [PATCH 4/8] Test using a directory with no METADATA.pb --- tests/profiles/googlefonts_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/profiles/googlefonts_test.py b/tests/profiles/googlefonts_test.py index 6934c557c4..439f075171 100644 --- a/tests/profiles/googlefonts_test.py +++ b/tests/profiles/googlefonts_test.py @@ -5188,6 +5188,14 @@ def test_check_metadata_unreachable_subsetting(): check(font), WARN, "unreachable-subsetting", "with a bad font" ) + font = TEST_FILE("playfair/Playfair-Italic[opsz,wdth,wght].ttf") + assert_results_contain( + check(font), + WARN, + "unreachable-subsetting", + "with a bad font and no METADATA.pb", + ) + def test_check_alt_caron(): """Check accent of Lcaron, dcaron, lcaron, tcaron""" From 4396cc0b74566f8aeec8b6c2c4714db24f6758a4 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Tue, 19 Sep 2023 21:15:36 +0100 Subject: [PATCH 5/8] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf534cf0f..ed9ed89c24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ A more detailed list of changes is available in the corresponding milestones for #### Added to the Google Fonts Profile - **[com.google.fonts/check/metadata/primary_script]:** New check that guesses the primary script and compares to METADATA.pb (issue #4109) + - **[com.google.fonts/check/metadata/unreachable_subsetting]:** Report codepoints in supplementary Unicode planes, and codepoints with no glyphset support at all (PR #4273) #### Added to the UFO Profile - **[com.thetypefounders/check/features_default_languagesystem]:** Checks if a default languagesystem statement is present in feature files and warns if the compiler will not insert one automatically (issue #4011) From 4d32f5a69f93a0d6187fc9171985c4930ae218e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Wed, 20 Sep 2023 02:53:50 +0100 Subject: [PATCH 6/8] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed9ed89c24..899c7760cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ A more detailed list of changes is available in the corresponding milestones for ### Bug Fixes #### On the Universal Profile - **[com.google.fonts/check/font_is_centered_vertically]:** Fix yet another error on fonts without ASCII letters (issue #4269) - +#### On the Google Fonts Profile + - **[com.google.fonts/check/metadata/unreachable_subsetting]:** Report codepoints in supplementary Unicode planes, and codepoints with no glyphset support at all (PR #4273) ## 0.9.1 (2023-Sep-19) ### Stable release notes @@ -76,7 +77,6 @@ A more detailed list of changes is available in the corresponding milestones for #### Added to the Google Fonts Profile - **[com.google.fonts/check/metadata/primary_script]:** New check that guesses the primary script and compares to METADATA.pb (issue #4109) - - **[com.google.fonts/check/metadata/unreachable_subsetting]:** Report codepoints in supplementary Unicode planes, and codepoints with no glyphset support at all (PR #4273) #### Added to the UFO Profile - **[com.thetypefounders/check/features_default_languagesystem]:** Checks if a default languagesystem statement is present in feature files and warns if the compiler will not insert one automatically (issue #4011) From 473a2369e72100fd7b865bf26e63f8f3db053b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Wed, 20 Sep 2023 12:05:35 +0100 Subject: [PATCH 7/8] Additional proposal URL to check/unreachable_subsetting (PR #4273) --- Lib/fontbakery/profiles/googlefonts.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/fontbakery/profiles/googlefonts.py b/Lib/fontbakery/profiles/googlefonts.py index bd3337f72d..ee51f85ef9 100644 --- a/Lib/fontbakery/profiles/googlefonts.py +++ b/Lib/fontbakery/profiles/googlefonts.py @@ -1159,7 +1159,10 @@ def com_google_fonts_check_metadata_unsupported_subsets( will not be served in the subsetted fonts, and so will be unreachable to the end user. """, - proposal="https://github.com/fonttools/fontbakery/issues/4097", + proposal=[ + "https://github.com/fonttools/fontbakery/issues/4097", + "https://github.com/fonttools/fontbakery/pull/4273", + ], severity=2, ) def com_google_fonts_check_metadata_unreachable_subsetting( From 86691d82a81906dc1afb06fc0e6de5452b4dfbbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Corr=C3=AAa=20da=20Silva=20Sanches?= Date: Wed, 20 Sep 2023 14:16:19 +0100 Subject: [PATCH 8/8] avoid setuptools_scm version 8.0.0 due to the bug described at https://github.com/pypa/setuptools_scm/issues/905 --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d5d8d66c7a..129b7a9ef4 100644 --- a/setup.py +++ b/setup.py @@ -158,7 +158,8 @@ python_requires=">=3.8", setup_requires=[ "setuptools>=61.2", - "setuptools_scm[toml]>=6.2", + "setuptools_scm[toml]>=6.2, !=8.0.0", # version 8.0.0 had a bug as described at + # https://github.com/pypa/setuptools_scm/issues/905 ], install_requires=[ # ---