Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix check/metadata/valid_name_values #4407

Merged
merged 4 commits into from
Jan 11, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ A more detailed list of changes is available in the corresponding milestones for
#### On the OpenType profile
- **[com.adobe.fonts/check/varfont/same_size_instance_records]:** Skip variable fonts without named instances. (issue #4410)

### Changes to existing checks
#### On the Google Fonts Profile
- **[com.google.fonts/check/metadata/valid_name_values]:** Compare METADATA family name against the font's best family name (issue #4262)


## 0.10.8 (2023-Dec-15)
- New status result: "FATAL". To be used when a problem detected is extremely bad and must be imediately addressed. (issue #4374 / Discussion #4364)
Expand Down
25 changes: 10 additions & 15 deletions Lib/fontbakery/profiles/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2585,27 +2585,22 @@ def com_google_fonts_check_metadata_match_filename_postscript(font_metadata):

@check(
id="com.google.fonts/check/metadata/valid_name_values",
conditions=["style", "font_metadata"],
conditions=["ttFont", "font_metadata"],
proposal="legacy:check/098",
)
def com_google_fonts_check_metadata_valid_name_values(
style, font_metadata, font_familynames, typographic_familynames
):
"""METADATA.pb font.name field contains font name in right format?"""
if style in RIBBI_STYLE_NAMES:
familynames = font_familynames
else:
familynames = typographic_familynames

if not any((name in font_metadata.name) for name in familynames):
def com_google_fonts_check_metadata_valid_name_values(ttFont, font_metadata):
"""METADATA.pb font.name field matches font"""
family_name = ttFont["name"].getBestFamilyName()
if family_name != font_metadata.name:
yield FAIL, Message(
"mismatch",
f'METADATA.pb font.name field ("{font_metadata.name}")'
f" does not match"
f' correct font name format ("{", ".join(familynames)}").',
(
f"METADATA.pb font.name field is {font_metadata.name} "
f"but font has {family_name}"
),
)
else:
yield PASS, "METADATA.pb font.name field contains font name in right format."
yield PASS, "METADATA.pb font.name is correct"


@check(
Expand Down
24 changes: 7 additions & 17 deletions tests/profiles/googlefonts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,37 +1986,27 @@ def NOT_IMPLEMENTED_test_check_match_filename_postscript():


def test_check_metadata_valid_name_values():
"""METADATA.pb font.name field contains font name in right format?"""
"""METADATA.pb font.name field matches font"""
check = CheckTester(
googlefonts_profile, "com.google.fonts/check/metadata/valid_name_values"
)

# Our reference Montserrat family is a good 18-styles family:
for font in MONTSERRAT_RIBBI:
for font in MONTSERRAT_RIBBI + MONTSERRAT_NON_RIBBI:
# So it must PASS the check:
assert_PASS(check(font), f"with a good RIBBI font ({font})...")
ttfont = TTFont(font)
assert_PASS(check(ttfont), f"with a good RIBBI font ({font})...")

# And fail if it finds a bad font_familyname:
ttfont["name"].setName("foobar", 1, 3, 1, 0x409)
ttfont["name"].setName("foobar", 16, 3, 1, 0x409)
assert_results_contain(
check(font, {"font_familynames": ["WrongFamilyName"]}),
check(ttfont),
FAIL,
"mismatch",
f"with a bad RIBBI font ({font})...",
)

# We do the same for NON-RIBBI styles:
for font in MONTSERRAT_NON_RIBBI:
# So it must PASS the check:
assert_PASS(check(font), "with a good NON-RIBBI font ({fontfile})...")

# And fail if it finds a bad font_familyname:
assert_results_contain(
check(font, {"typographic_familynames": ["WrongFamilyName"]}),
FAIL,
"mismatch",
f"with a bad NON-RIBBI font ({font})...",
)

# Good font with other language name entries
font = TEST_FILE("bizudpmincho-nameonly/BIZUDPMincho-Regular.ttf")

Expand Down