Skip to content

Commit

Permalink
Improve compatibility checker (#1052)
Browse files Browse the repository at this point in the history
* Check for contextual anchors

* Improve display of error

* Update tests

* Make flake8 happier
  • Loading branch information
simoncozens authored Nov 2, 2023
1 parent f5bde9d commit dae37e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 21 additions & 2 deletions Lib/fontmake/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ def check_glyph(self, glyphs):
anchors,
"anchors",
)
# Context for contextual anchors
libs = [g.lib for g in glyphs]
for each_anchors in zip(*anchors):
if each_anchors[0].name[0] == "*":
objectlibs = [
libs[font_ix]
.get("public.objectLibs", {})
.get(anchor.identifier, {})
for font_ix, anchor in enumerate(each_anchors)
]
with Context(self, f"anchor {each_anchors[0].name}"):
self.ensure_all_same(
lambda lib: lib.get("GPOS_Context", "None").strip(),
objectlibs,
"GPOS context",
)

components = [g.components for g in glyphs]
if self.ensure_all_same(len, components, "number of components"):
Expand All @@ -68,14 +84,17 @@ def ensure_all_same(self, func, objs, what):
if len(values) < 2:
logger.debug(f"All fonts had same {what} in {context}")
return True
logger.error(f"Fonts had differing {what} in {context}:")
report = f"\nFonts had differing {what} in {context}:\n"
debug_enabled = logger.isEnabledFor(logging.DEBUG)
for value, fonts in values.items():
if debug_enabled or len(fonts) <= 6:
key = ", ".join(fonts)
else:
key = f"{len(fonts)} fonts"
logger.error(f" * {key} had {value}")
if len(str(value)) > 20:
value = "\n " + str(value)
report += f" * {key} had: {value}\n"
logger.error(report)
self.okay = False
return False

Expand Down
4 changes: 2 additions & 2 deletions tests/test_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def test_compatibility_checker(data_dir, caplog):

CompatibilityChecker([s.font for s in designspace.sources]).check()
assert "differing number of contours in glyph A" in caplog.text
assert "Incompatible Sans Regular had 2" in caplog.text
assert "Incompatible Sans Regular had: 2" in caplog.text

assert "differing number of points in glyph B, contour 0" in caplog.text

assert "differing anchors in glyph A" in caplog.text
assert 'Incompatible Sans Bold had "foo"' in caplog.text
assert 'Incompatible Sans Bold had: "foo"' in caplog.text

assert "Fonts had differing number of components in glyph C" in caplog.text

Expand Down

0 comments on commit dae37e6

Please sign in to comment.