-
Notifications
You must be signed in to change notification settings - Fork 27
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
[skrifa] autohint: cycle detection for GSUB lookups #1296
Conversation
Adds a stack to detect cycles in GSUB lookups while computing shaper coverage for autohinting. Fixes #1295
/// Called when we finish processing a single lookup. | ||
fn exit_lookup(&mut self) { | ||
self.lookup_depth = self.lookup_depth.saturating_sub(1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love that this makes it relatively easy to add code that enters without calling exit. This would be somewhat harder if it was directly in the process lookup fn? - depicted below. Or by a guard that reduces depth on drop but I suppose that path takes you towards multiple mut refs.
fn process_lookup(&mut self, lookup_index: u16) {
// Guard: don't cycle and don't go exceed depth limit
// Note: we use a linear search here under the assumption that
// most fonts have shallow contextual lookup chains
if self.lookup_depth != 0
&& (self.lookup_depth == MAX_NESTING_DEPTH
|| self.lookup_stack[..self.lookup_depth].contains(&lookup_index))
{
return;
}
self.lookup_stack[self.lookup_depth] = lookup_index;
self.lookup_depth += 1;
// Actually process the lookup
self.process_lookup_inner(lookup_index);
// Out we go again
self.lookup_depth -= 1;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the sentiment but I kept the stack ops separate to support isolated unit testing of that functionality. If we embed them then we need to build a lookup list with the desired structure which seems less clear and more fragile to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have thought we need to build lookups with good/bad structure (one that cycles, one that has max depth, one that has max depth + 1, etc) to unit test regardless so... that's kind of fine?
skrifa/src/outline/autohint/shape.rs
Outdated
} | ||
} | ||
|
||
fn process_lookup_inner(&mut self, lookup_index: u16) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might as well mark inline always?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm
For reference, contextual lookup depth in all of Google Fonts and Noto (10604 font files):
|
inline stack ops and add tests for bad lookups that cycle and exceed max depth
Adds a stack to detect cycles in GSUB lookups while computing shaper coverage for autohinting.
Fixes #1295