Skip to content

Commit

Permalink
add more checks
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rc1e committed May 1, 2020
1 parent 4bdbed5 commit 7bddcd8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 37 deletions.
Empty file added tests/__init__.py
Empty file.
32 changes: 26 additions & 6 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ def filter_checks(_, check_id, __):

ROBOTO_GENERAL_CHECKS += [
"com.roboto.fonts/check/italic_angle",
"com.roboto.fonts/check/meta_info",
"com.roboto.fonts/check/fs_type",
"com.roboto.fonts/check/vendorid",
"com.roboto.fonts/check/charset_coverage",
"com.roboto.fonts/check/digit_widths",
"com.roboto.fonts/check/name_copyright",
"com.roboto.fonts/check/name_unique_id",
"com.roboto.fonts/check/vertical_metrics",
]

profile_imports = ('fontbakery.profiles.universal',)
profile = profile_factory(default_section=Section("Roboto v3 general"))

Expand All @@ -57,6 +62,14 @@ def font_style(ttFont):
return subfamily_name.toUnicode()


def font_family(ttFont):
family_name = ttFont['name'].gtName(1, 3, 1, 1033)
typo_family_name = ttFont['name'].getName(16, 3, 1, 1033)
if typo_family_name:
return typo_family_name.toUnicode()
return family_name.toUnicode()


@check(
id="com.roboto.fonts/check/italic_angle",
conditions = ["is_italic"]
Expand All @@ -71,24 +84,30 @@ def com_roboto_fonts_check_italic_angle(ttFont):


@check(
id="com.roboto.fonts/check/meta_info",
id="com.roboto.fonts/check/fs_type",
)
def com_roboto_fonts_check_meta_info(ttFont):
def com_roboto_fonts_check_fs_type(ttFont):
"""Check metadata is correct"""
failed = False
if ttFont['OS/2'].fsType != 0:
yield FAIL, "OS/2.fsType must be 0"
else:
yield PASS, "OS/2.fsType is set correctly"


@check(
id="com.roboto.fonts/check/vendorid",
)
def com_roboto_fonts_check_vendorid(ttFont):
"""Check vendorID is correct"""
if ttFont["OS/2"].achVendID != "GOOG":
yield FAIL, "OS/2.achVendID must be set to 'GOOG'"
else:
yield PASS, "OS/2.achVendID is set corrrectly"


@check(
id="com/roboto.fonts/check/name_copyright",
id="com.roboto.fonts/check/name_copyright",
)
def com_roboto_fonts_check_copyright(ttFont):
"""Check font copyright is correct"""
Expand All @@ -101,12 +120,13 @@ def com_roboto_fonts_check_copyright(ttFont):


@check(
id="com/roboto.fonts/check/name_unique_id",
id="com.roboto.fonts/check/name_unique_id",
)
def com_roboto_fonts_check_name_unique_id(ttFont):
"""Check font unique id is correct"""
family_name = family_name(ttFont)
style = font_style(ttFont)
expected = f"Google:Roboto {style}:2016"
expected = f"Google:{family_name} {style}:2016"
font_unique_id = ttFont['name'].getName(3, 3, 1, 1033).toUnicode()
if font_unique_id == expected:
yield PASS, "Unique ID is correct"
Expand Down
64 changes: 33 additions & 31 deletions tests/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@
from fontbakery.callable import condition
from fontbakery.checkrunner import Section, PASS, FAIL, WARN
from fontbakery.fonts_profile import profile_factory
from fontbakery.profiles.universal import UNIVERSAL_PROFILE_CHECKS

# profile_imports = ('fontbakery.profiles.universal',)
profile = profile_factory(default_section=Section("Roboto v3"))
profile = profile_factory(default_section=Section("Roboto web v3"))

ROBOTO_PROFILE_CHECKS = [
"com.roboto.fonts/check/vertical_metrics",
"com.roboto.fonts/check/italic_angle",
"com.roboto.fonts/check/meta_info"
"com.roboto.fonts/check/oblique_bits_not_set",
"com.roboto.fonts/check/unique_id",
"com.roboto.fonts/check/hinting",
]


@condition
def is_italic(ttFont):
return True if "Italic" in ttFont.reader.file.name else False


@check(
id="com.roboto.fonts/check/vertical_metrics",
)
Expand All @@ -36,8 +31,8 @@ def com_roboto_fonts_check_vertical_metrics(ttFont):
# test OS/2 vertical metrics to be equal to old OS/2 win values
# since fsSelection bit 7 is now enabled
("OS/2", "sTypoDescender"): -512,
("OS/2", "sTypoAscender"): 1946,
("OS/2", "sTypoLineGap"): 0,
("OS/2", "sTypoAscender"): 1536,
("OS/2", "sTypoLineGap"): 102,
("OS/2", "usWinDescent"): 512,
("OS/2", "usWinAscent"): 1946,
}
Expand All @@ -58,34 +53,41 @@ def com_roboto_fonts_check_vertical_metrics(ttFont):


@check(
id="com.roboto.fonts/check/italic_angle",
conditions = ["is_italic"]
id="com.roboto.fonts/check/oblique_bits_not_set",
)
def com_roboto_fonts_check_italic_angle(ttFont):
"""Check vertical metrics are correct"""
failed = False
if ttFont['post'].italicAngle != -12:
yield FAIL, "post.italicAngle must be set to -12"
def com_roboto_fonts_check_oblique_bits_not_set(ttFont):
"""Check oblique bits are not set in fonts"""
if ttFont['OS/2'].fsSelection & (1 << 9) != 0:
yield FAIL, "fsSelection bit 9 (Oblique) must not be enabled"
else:
yield PASS, "post.italicAngle is set correctly"
yield PASS, "fsSelection bit 9 is disabled"

if ttFont["OS/2"].achVendID != "GOOG":
yield FAIL, "OS/2.achVendID must be set to 'GOOG'"
else:
yield PASS, "OS/2.achVendID is set corrrectly"

@check(
id="com.roboto.fonts/check/unique_id",
)
def com_roboto_fonts_check_unique_id(ttFont):
"""Check uniqueid is correct"""
pass
# Should be <familyname> <style> or just <familyname> for Reg fonts


@check(
id="com.roboto.fonts/check/meta_info",
id="com.roboto.fonts/check/hinting",
)
def com_roboto_fonts_check_meta_info(ttFont):
"""Check metadata is correct"""
failed = False
if ttFont['OS/2'].fsType != 0:
yield FAIL, "OS/2.fsType must be 0"
def com_roboto_fonts_check_hinting(ttFont):
"""Check glyphs have hinting"""
missing_hints = []
for glyph_name in ttFont.getGlyphOrder():
glyph = ttFont['glyf'][glyph_name]
if glyph.numberOfContours <= 0:
continue
if len(glyph.program.bytecode) <= 0:
missing_hints.append(glyph_name)
if missing_hints:
yield FAIL, f"Following glyphs are missing hinting {missing_hints}"
else:
yield PASS, "OS/2.fsType is set correctly"

yield PASS, "All glyphs are hinted"

profile.auto_register(globals())
profile.test_expected_checks(ROBOTO_PROFILE_CHECKS, exclusive=True)

0 comments on commit 7bddcd8

Please sign in to comment.