Skip to content

Commit

Permalink
Fix outermost path detection
Browse files Browse the repository at this point in the history
The code which detects the outermost contour assumed that later paths would be contained within earlier paths, which is of course rubbish. Paths can be in any order they like, so we have to do the O(n^2) thing to find the outermost ones.

com.google.fonts/check/outline_direction
On the Outline profile.

(issue #4719 and googlefonts/fontmake#1093)
  • Loading branch information
simoncozens committed May 17, 2024
1 parent bf8fba9 commit 7fdfa31
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ Below are the noteworthy changes from each release.
A more detailed list of changes is available in the corresponding milestones for each release in the Github issue tracker (https://github.com/googlefonts/fontbakery/milestones?state=closed).

## Upcoming release: 0.12.7 (2024-May-??)
- ...

#### On the Outline profile
- **[com.google.fonts/check/outline_direction]:** fixed an error where the outermost path was not correctly detected. (issue #4719)

## 0.12.6 (2024-May-13)
- Fixed race condition with `--auto-jobs` caused by the current working directory changing (issue #4700)
Expand Down
4 changes: 3 additions & 1 deletion Lib/fontbakery/checks/outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ def bounds_contains(bb1, bb2):
outline_bounds = [path.bounds() for path in outlines]
is_within = defaultdict(list)
for i, my_bounds in enumerate(outline_bounds):
for j in range(i + 1, len(outline_bounds)):
for j in range(0, len(outline_bounds)):
if i == j:
continue
their_bounds = outline_bounds[j]
if bounds_contains(my_bounds, their_bounds):
is_within[j].append(i)
Expand Down
Binary file added data/test/wonky_paths/OutlineTest.ttf
Binary file not shown.
Binary file modified data/test/wonky_paths/WonkySourceSansPro-Regular.ttf
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/checks/outline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ def test_check_outline_direction():
assert_results_contain(results, WARN, "ccw-outer-contour")
messages = "".join([m.message.message for m in results])
assert "A (U+0041) has a counter-clockwise outer contour" in messages

font = TEST_FILE("wonky_paths/OutlineTest.ttf")
assert_PASS(check(font))

0 comments on commit 7fdfa31

Please sign in to comment.