Skip to content

Commit

Permalink
New Check: FAIL on bad postscript names
Browse files Browse the repository at this point in the history
- Added to the OpenType Profile
- com.adobe.fonts/check/postscript_name
- Implemented by Josh Hadley at miguelsousa/openbakery#63
- Ported to FontBakery by FSanches.

Note: These validations were previously INFO-level and were
      part of com.google.fonts/check/family_naming_recommendations
      which was also updated.

(issue #4254)
  • Loading branch information
josh-hadley authored and felipesanches committed Sep 8, 2023
1 parent c762bc1 commit a91fba9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 19 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ A more detailed list of changes is available in the corresponding milestones for


## Upcoming release: 0.9.0 (2023-Sep-??)
- ...
### New Checks
#### Added to the OpenType Profile
- **[com.adobe.fonts/check/postscript_name]:** FAIL on bad postscript names (issue #4254).

### Changes to existing checks
#### On the OpenType Profile
- **[com.google.fonts/check/family_naming_recommendations]:** Two validations of PostScript names were moved out of this check and into **com.adobe.fonts/check/postscript_name** which yields FAILs (issue #4254).


## Upcoming release: 0.9.0a3 (2023-Sep-05)
## 0.9.0a3 (2023-Sep-05)
### Note-worthy code changes
- The default log level has been changed to WARN. Now that profiles are big, you don't (by default) want a big long list of everything that is OK about your font; you just want to know the problems to fix. Make WARN the default and have people get a list of PASS if they ask for it. (issue #4186)

Expand Down
3 changes: 2 additions & 1 deletion Lib/fontbakery/profiles/adobefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
SET_EXPLICIT_CHECKS = {
# This is the set of explict checks that will be invoked
# when fontbakery is run with the 'check-adobefonts' subcommand.
# The contents of this set were last updated on April 19, 2023.
# The contents of this set were last updated on September 6, 2023.
#
# =======================================
# From adobefonts.py (this file)
Expand Down Expand Up @@ -132,6 +132,7 @@
"com.adobe.fonts/check/family/max_4_fonts_per_family_name",
"com.adobe.fonts/check/family/consistent_family_name",
"com.adobe.fonts/check/name/empty_records",
"com.adobe.fonts/check/postscript_name",
"com.adobe.fonts/check/name/postscript_name_consistency",
"com.adobe.fonts/check/name/postscript_vs_cff",
"com.google.fonts/check/family_naming_recommendations",
Expand Down
38 changes: 31 additions & 7 deletions Lib/fontbakery/profiles/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,11 @@ def com_google_fonts_check_name_match_familyname_fullfont(ttFont):


@check(
id="com.google.fonts/check/family_naming_recommendations",
proposal="legacy:check/071",
id="com.adobe.fonts/check/postscript_name",
proposal="https://github.com/miguelsousa/openbakery/issues/62",
)
def com_google_fonts_check_family_naming_recommendations(ttFont):
"""Font follows the family naming recommendations?"""
# See http://forum.fontlab.com/index.php?topic=313.0
def com_adobe_fonts_check_postscript_name(ttFont):
"""PostScript name follows OpenType specification requirements?"""
import re
from fontbakery.utils import get_name_entry_strings

Expand All @@ -439,18 +438,43 @@ def com_google_fonts_check_family_naming_recommendations(ttFont):
{
"field": "PostScript Name",
"value": string,
"rec": ("May contain only a-zA-Z0-9 characters and an hyphen."),
"rec": ("May contain only a-zA-Z0-9 characters and a hyphen."),
}
)
if string.count("-") > 1:
bad_entries.append(
{
"field": "Postscript Name",
"value": string,
"rec": ("May contain not more than a single hyphen"),
"rec": ("May contain not more than a single hyphen."),
}
)

if len(bad_entries) > 0:
table = "| Field | Value | Recommendation |\n"
table += "|:----- |:----- |:-------------- |\n"
for bad in bad_entries:
table += "| {} | {} | {} |\n".format(bad["field"], bad["value"], bad["rec"])
yield FAIL, Message(
"bad-psname-entries",
f"PostScript name does not follow requirements:\n\n{table}",
)
else:
yield PASS, Message("psname-ok", "PostScript name follows requirements.")


@check(
id="com.google.fonts/check/family_naming_recommendations",
proposal="legacy:check/071",
)
def com_google_fonts_check_family_naming_recommendations(ttFont):
"""Font follows the family naming recommendations?"""
# See http://forum.fontlab.com/index.php?topic=313.0

from fontbakery.utils import get_name_entry_strings

bad_entries = []

for string in get_name_entry_strings(ttFont, NameID.FULL_FONT_NAME):
if len(string) >= 64:
bad_entries.append(
Expand Down
1 change: 1 addition & 0 deletions Lib/fontbakery/profiles/opentype.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"com.google.fonts/check/glyf_unused_data",
"com.google.fonts/check/family_naming_recommendations",
"com.google.fonts/check/maxadvancewidth",
"com.adobe.fonts/check/postscript_name",
"com.google.fonts/check/points_out_of_bounds",
"com.google.fonts/check/glyf_non_transformed_duplicate_components",
"com.google.fonts/check/code_pages",
Expand Down
2 changes: 1 addition & 1 deletion tests/profiles/adobefonts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_get_family_checks():
def test_profile_check_set():
"""Confirm that the profile has the correct number of checks and the correct
set of check IDs."""
assert len(SET_EXPLICIT_CHECKS) == 80
assert len(SET_EXPLICIT_CHECKS) == 81
explicit_with_overrides = sorted(
f"{check_id}{OVERRIDE_SUFFIX}" if check_id in OVERRIDDEN_CHECKS else check_id
for check_id in SET_EXPLICIT_CHECKS
Expand Down
42 changes: 34 additions & 8 deletions tests/profiles/name_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,10 @@ def name_test(value, expected, keyword=None):
if name.nameID == NameID.POSTSCRIPT_NAME:
print("== NameID.POST_SCRIPT_NAME ==")

print("Test INFO: May contain only a-zA-Z0-9 characters and an hyphen...")
# The '@' and '!' chars here are the expected rule violations:
name_test("B@zinga!", INFO, "bad-entries")

print("Test PASS: A name with a single hyphen is OK...")
# A single hypen in the name is OK:
name_test("Big-Bang", PASS)

print("Test INFO: May not contain more than a single hyphen...")
# The second hyphen char here is the expected rule violation:
name_test("Big-Bang-Theory", INFO, "bad-entries")

print("Test INFO: Exceeds max length (63)...")
name_test("A" * 64, INFO, "bad-entries")

Expand Down Expand Up @@ -654,3 +646,37 @@ def set_name(font, nameID, string):
ttFont = TTFont(TEST_FILE("shantell/ShantellSans-Italic[BNCE,INFM,SPAC,wght].ttf"))
set_name(ttFont, 17, "Light")
assert_results_contain(check(ttFont), FAIL, "bad-typographicsubfamilyname")


def test_check_name_postscript():
check = CheckTester(opentype_profile, "com.adobe.fonts/check/postscript_name")

# Test a font that has OK psname. Check should PASS.
ttFont = TTFont(TEST_FILE("source-sans-pro/OTF/SourceSansPro-Bold.otf"))
assert_PASS(check(ttFont), "psname-ok")

# Change the PostScript name string to more than one hyphen. Should FAIL.
bad_ps_name = "more-than-one-hyphen".encode("utf-16-be")
ttFont["name"].setName(
bad_ps_name,
NameID.POSTSCRIPT_NAME,
PlatformID.WINDOWS,
WindowsEncodingID.UNICODE_BMP,
WindowsLanguageID.ENGLISH_USA,
)
msg = assert_results_contain(check(ttFont), FAIL, "bad-psname-entries")
assert "PostScript name does not follow requirements" in msg
assert "May contain not more than a single hyphen." in msg

# Now change it to a string with illegal characters. Should FAIL.
bad_ps_name = "(illegal) characters".encode("utf-16-be")
ttFont["name"].setName(
bad_ps_name,
NameID.POSTSCRIPT_NAME,
PlatformID.WINDOWS,
WindowsEncodingID.UNICODE_BMP,
WindowsLanguageID.ENGLISH_USA,
)
msg = assert_results_contain(check(ttFont), FAIL, "bad-psname-entries")
assert "PostScript name does not follow requirements" in msg
assert "May contain only a-zA-Z0-9 characters and a hyphen." in msg

0 comments on commit a91fba9

Please sign in to comment.