Fix chaining context backtrack matching order#372
Open
lehni wants to merge 1 commit into
Open
Conversation
- Backtrack arrays are stored in reverse buffer order per OT spec - Reverse before matching so backtrack[0] aligns with position before input
22cd36c to
789c8bd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The chaining-context lookup (GSUB type 6, formats 1–3) stores backtrack coverage/class/glyph arrays in reverse buffer order per the OpenType spec:
backtrack[0]is the glyph immediately before the input,backtrack[1]is one further back, etc. The current matcher feeds the stored order directly tosequenceMatches(-N, …), which iterates forward — so it ends up comparingbacktrack[0]against the position farthest from the input. When all backtrack positions accept the same coverage (the common case) the bug is invisible, but rules with distinct positions silently fail to fire.The fix reverses the backtrack array before matching, in all three chain-context formats.
Test
Added a shaping test using Noto Sans Syriac Estrangela's
caltchain rule where:backtrack[0]accepts a mark glyph (uni0731/uni0734/uni0737)backtrack[1]accepts a positional consonant (uni0712.Init/uni0712.Medi/uni071A.Medi)uni0713.Fina, substituted touni0713.FinaWideInput
ܒܱܓ(U+0712 U+0731 U+0713) joins to[uni0712.Init, uni0731, uni0713.Fina]. Per spec the rule fires and producesuni0713.FinaWide(matching HarfBuzz); without the fix fontkit leavesuni0713.Finaunsubstituted.