Skip to content

Commit

Permalink
migrate designspace checks to universal profile
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesanches committed Aug 25, 2021
1 parent 0f2bae8 commit a99ef86
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 207 deletions.
29 changes: 0 additions & 29 deletions Lib/fontbakery/commands/check_designspace.py

This file was deleted.

173 changes: 0 additions & 173 deletions Lib/fontbakery/profiles/designspace.py

This file was deleted.

12 changes: 12 additions & 0 deletions Lib/fontbakery/profiles/shared_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ def variable_font_filename(ttFont):
return f"{familyname}{tags}.ttf"


@condition
def designspace(font):
from fontTools.designspaceLib import DesignSpaceDocument
return DesignSpaceDocument.fromfile(font)


@condition
def designspace_sources(designspace):
import defcon
return designspace.loadSourceFonts(defcon.Font)


@condition
def family_directory(font):
"""Get the path of font project directory."""
Expand Down
84 changes: 84 additions & 0 deletions Lib/fontbakery/profiles/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@
'com.google.fonts/check/superfamily/vertical_metrics',
]

DESIGNSPACE_CHECKS = [
'com.google.fonts/check/designspace_has_sources',
'com.google.fonts/check/designspace_has_default_master',
'com.google.fonts/check/designspace_has_consistent_glyphset',
'com.google.fonts/check/designspace_has_consistent_codepoints',
]

UNIVERSAL_PROFILE_CHECKS = \
DESIGNSPACE_CHECKS + \
OPENTYPE_PROFILE_CHECKS + \
OUTLINE_PROFILE_CHECKS + \
SHAPING_PROFILE_CHECKS + \
Expand All @@ -55,6 +63,7 @@
'com.google.fonts/check/rupee'
]


@check(
id = 'com.google.fonts/check/name/trailing_spaces',
proposal = 'https://github.com/googlefonts/fontbakery/issues/2417'
Expand Down Expand Up @@ -1089,6 +1098,81 @@ def com_google_fonts_check_rupee(ttFont):
'Please add a glyph for Indian Rupee Sign “₹” at codepoint U+20B9.')
else:
yield PASS, "Looks good!"


@check(
id = "com.google.fonts/check/designspace_has_sources"
)
def com_google_fonts_check_designspace_has_sources(designspace_sources):
"""See if we can actually load the source files."""
if not designspace_sources:
yield FAIL, "Unable to load source files."
else:
yield PASS, "OK"


@check(
id = "com.google.fonts/check/designspace_has_default_master"
)
def com_google_fonts_check_designspace_has_default_master(designspace):
"""Ensure a default master is defined."""
if not designspace.findDefault():
yield FAIL, "Unable to find a default master."
else:
yield PASS, "We located a default master."


@check(
id = "com.google.fonts/check/designspace_has_consistent_glyphset",
conditions = ["designspace_sources"]
)
def com_google_fonts_check_designspace_has_consistent_glyphset(designspace):
"""Ensure non-default masters don't have glyphs not present in the default."""
default_glyphset = set(designspace.findDefault().font.keys())
failures = []
for source in designspace.sources:
master_glyphset = set(source.font.keys())
outliers = master_glyphset - default_glyphset
if outliers:
outliers = ", ".join(list(outliers))
failures.append(f"Source {source.filename} has glyphs not present"
f" in the default master: {outliers}")
if failures:
yield FAIL,\
Message("inconsistent-glyphset",
f"Glyphsets were not consistent:\n"
f"{bullet_list(failures)}")
else:
yield PASS, "Glyphsets were consistent."


@check(
id = "com.google.fonts/check/designspace_has_consistent_codepoints",
conditions = ["designspace_sources"]
)
def com_google_fonts_check_designspace_has_consistent_unicodes(designspace):
"""Ensure Unicode assignments are consistent across sources."""
default_source = designspace.findDefault()
default_unicodes = {g.name: g.unicode for g in default_source.font}
failures = []
for source in designspace.sources:
for g in source.font:
if g.name not in default_unicodes:
# Previous test will cover this
continue

if g.unicode != default_unicodes[g.name]:
failures.append(f"Source {source.filename} has"
f" {g.name}={g.unicode};"
f" default master has"
f" {g.name}={default_unicodes[g.name]}"))
if failures:
yield FAIL,\
Message("inconsistent-unicodes",
f"Unicode assignments were not consistent:\n"
f"{bullet_list(failures)}")
else:
yield PASS, "Unicode assignments were consistent."


profile.auto_register(globals())
Expand Down
11 changes: 6 additions & 5 deletions Lib/fontbakery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ def pretty_print_list(values, shorten=10, sep=", ", glue="and"):
str(values[-1]))


def bullet_list(values, bullet="-"):
return f" {bullet} " + pretty_print_list(values,
shorten=False,
sep=f"\n {bullet} ",
glue=f"\n {bullet}")
def bullet_list(items, bullet="-", indentation="\t"):
return = f"{indentation}{bullet} " +\
pretty_print_list(items,
sep=f"\n{indentation}{bullet} ",
glue=f"\n{indentation}{bullet} ")


def get_regular(fonts):
# TODO: Maybe also support getting a regular instance from a variable font?
Expand Down

0 comments on commit a99ef86

Please sign in to comment.