Skip to content

Commit

Permalink
Raise warn when Regular is missing from full name for Regular font style
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rc1e committed Jun 27, 2022
1 parent 4e8e5f6 commit 40b8735
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
27 changes: 19 additions & 8 deletions Lib/fontbakery/profiles/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3234,12 +3234,12 @@ def style_names(nametable):
expected_names = style_names(expected_font_names['name'])

name_ids = {
1: "Family Name",
2: "Subfamily Name",
4: "Full Name",
6: "Poscript Name",
16: "Typographic Family Name",
17: "Typographic Subfamily Name",
NameID.FONT_FAMILY_NAME: "Family Name",
NameID.FONT_SUBFAMILY_NAME: "Subfamily Name",
NameID.FULL_FONT_NAME: "Full Name",
NameID.POSTSCRIPT_NAME: "Poscript Name",
NameID.TYPOGRAPHIC_FAMILY_NAME: "Typographic Family Name",
NameID.TYPOGRAPHIC_SUBFAMILY_NAME: "Typographic Subfamily Name",
}
table = []
for nameID in set(font_names.keys()) | set(expected_names.keys()):
Expand All @@ -3260,8 +3260,19 @@ def style_names(nametable):
same_names = set(font_names) & set(expected_names)

md_table = markdown_table(table)
if any([new_names, missing_names]) or \
any(font_names[i] != expected_names[i] for i in same_names):

passed = True
if new_names or missing_names:
passed = False

for nameID in same_names:
if nameID == NameID.FULL_FONT_NAME and \
font_names[nameID] == expected_names[nameID].replace(" Regular", ""):
yield WARN, Message('lacks-regular', "Regular missing from full name")
elif font_names[nameID] != expected_names[nameID]:
passed = False

if not passed:
yield FAIL, Message('bad-names',
f'Font names are incorrect:\n\n{md_table}')
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/profiles/googlefonts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2466,8 +2466,8 @@ def test_check_metadata_category():
(TEST_FILE("montserrat/Montserrat-ThinItalic.ttf"), {NameID.FONT_SUBFAMILY_NAME: "Not a proper style"}, FAIL),
# tests from test_check_name_fullfontname
(TEST_FILE("cabin/Cabin-Regular.ttf"), {}, PASS),
# todo fix this
(TEST_FILE("cabin/Cabin-Regular.ttf"), {4: "Cabin"}, FAIL),
# warn should be raised since full name is missing Regular
(TEST_FILE("cabin/Cabin-Regular.ttf"), {4: "Cabin"}, WARN),
(TEST_FILE("cabin/Cabin-BoldItalic.ttf"), {}, PASS),
(TEST_FILE("cabin/Cabin-BoldItalic.ttf"), {NameID.FULL_FONT_NAME: "Make it fail"}, FAIL),
(TEST_FILE("abeezee/ABeeZee-Regular.ttf"), {}, PASS),
Expand Down Expand Up @@ -2545,7 +2545,7 @@ def test_check_font_names(fp, mod, result):
"with a good font...")
elif result == WARN:
assert_results_contain(check(ttFont, {"expected_font_names": expected}),
WARN, 'bad-names',
WARN, 'lacks-regular',
f'with bad names')
else:
assert_results_contain(check(ttFont, {"expected_font_names": expected}),
Expand Down

0 comments on commit 40b8735

Please sign in to comment.