Handling harakat collisions with contextual alternates in Arabic

I’m working on an Arabic font and ran into an issue with contextual alternates and mark positioning.

I currently have a calt substitution like this:

sub reh' yeh by reh01;

This works fine in terms of substitution, but I’m running into a problem when the yeh has harakat. The alternate glyph reh01 ends up sitting on top of the marks attached to the yeh.

What I’m trying to achieve is:

  • Keep the contextual substitution

  • Avoid collisions with harakat on the following glyph

What would be the correct approach to deal with this?

You need to be carful if you like to have lookupflag IgnoreMarks; or lookupflag UseMarkFilteringSet @class or not. That decides if intermediate marks are considered context or not.