Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility checker #1052

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading