Skip to content

Commit dccf815

Browse files
bramsteinfelipesanches
authored andcommitted
Add configurable check for OS/2 achVendID.
com.thetypefounders/check/vendor_id When a font project's Vendor ID is specified explicitely on FontBakery's configuration file, all binaries must have a matching vendor identifier value in the OS/2 table. (PR fonttools#3941)
1 parent 63ab8b9 commit dccf815

4 files changed

Lines changed: 66 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ A more detailed list of changes is available in the corresponding milestones for
77
#### Added to the Universal Profile
88
- **[com.google.fonts/check/interpolation_issues]:** Check for shape order or curve start point interpolation issues within a variable font. (issue #3930)
99

10+
#### Added to the Open Type Profile
11+
- **[com.thetypefounders/check/vendor_id]:** When a font project's Vendor ID is specified explicitely on FontBakery's configuration file, all binaries must have a matching vendor identifier value in the OS/2 table. (PR #3941)
12+
1013
#### Added to the Google Fonts Profile
1114
- **[com.google.fonts/check/colorfont_tables]:** Check if fonts contain the correct color tables. (issue #3886)
1215
- **[com.google.fonts/check/description/noto_has_article]:** Noto fonts must have an ARTICLE.en_us.html file. (issue #3841)

Lib/fontbakery/profiles/opentype.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
'com.adobe.fonts/check/varfont/same_size_instance_records',
8484
'com.adobe.fonts/check/varfont/distinct_instance_records',
8585
'com.adobe.fonts/check/stat_has_axis_value_tables',
86+
'com.thetypefounders/check/vendor_id',
8687
]
8788

8889
profile.auto_register(globals())

Lib/fontbakery/profiles/os2.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from fontbakery.callable import check
2-
from fontbakery.status import FAIL, PASS, WARN, INFO
2+
from fontbakery.status import FAIL, PASS, WARN, INFO, SKIP
33
from fontbakery.message import Message
44
# used to inform get_module_profile whether and how to create a profile
55
from fontbakery.fonts_profile import profile_factory # NOQA pylint: disable=unused-import
@@ -329,3 +329,40 @@ def com_google_fonts_check_code_pages(ttFont):
329329
" ulCodePageRange1 and CodePageRange2 fields.")
330330
else:
331331
yield PASS, "At least one code page is defined."
332+
333+
334+
@check(
335+
id = 'com.thetypefounders/check/vendor_id',
336+
rationale = """
337+
When a font project's Vendor ID is specified explicitely on FontBakery's
338+
configuration file, all binaries must have a matching vendor identifier
339+
value in the OS/2 table.
340+
""",
341+
proposal = 'https://github.com/googlefonts/fontbakery/pull/3941'
342+
)
343+
def com_thetypefounders_check_vendor_id(config, ttFont):
344+
"""Checking OS/2 achVendID against configuration."""
345+
346+
if "vendor_id" not in config:
347+
yield SKIP, ("Add the `vendor_id` key to a `fontbakery.yaml` file"
348+
" on your font project directory to enable this check.\n"
349+
"You'll also need to use the `--configuration` flag when"
350+
" invoking fontbakery.")
351+
return
352+
353+
if "OS/2" not in ttFont:
354+
yield FAIL,\
355+
Message("lacks-OS/2",
356+
"The required OS/2 table is missing.")
357+
return
358+
359+
config_vendor_id = config['vendor_id']
360+
font_vendor_id = ttFont['OS/2'].achVendID
361+
362+
if config_vendor_id != font_vendor_id:
363+
yield FAIL,\
364+
Message("bad-vendor-id",
365+
f"OS/2 VendorID is '{font_vendor_id}',"
366+
f" but should be '{config_vendor_id}'.")
367+
else:
368+
yield PASS, f"OS/2 VendorID '{font_vendor_id}' is correct."

tests/profiles/os2_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from fontbakery.checkrunner import (INFO, WARN, FAIL)
1010
from fontbakery.codetesting import (assert_PASS,
11+
assert_SKIP,
1112
assert_results_contain,
1213
CheckTester,
1314
portable_path,
@@ -219,3 +220,26 @@ def test_check_code_pages():
219220
FAIL, "no-code-pages",
220221
'with a font with no code page declared.')
221222

223+
def test_check_vendor_id():
224+
""" Check vendor id against the configured value """
225+
check = CheckTester(opentype_profile,
226+
"com.thetypefounders/check/vendor_id")
227+
228+
ttFont = TTFont(TEST_FILE("merriweather/Merriweather-Regular.ttf"))
229+
assert (ttFont['OS/2'].achVendID == 'STC ')
230+
231+
# If there is no configured vendor_id value, SKIP the check
232+
assert_SKIP(check(ttFont))
233+
234+
config = { "vendor_id": "STC " }
235+
assert_PASS(check({
236+
"config": config,
237+
"ttFont": ttFont,
238+
}))
239+
240+
ttFont['OS/2'].achVendID = 'TEST'
241+
assert_results_contain(check({
242+
"config": config,
243+
"ttFont": ttFont,
244+
}), FAIL, "bad-vendor-id", "OS/2 VendorID is 'TEST', but should be 'STC '")
245+

0 commit comments

Comments
 (0)