Conditional feature code breaks other code in the same feature

I don’t know if I messed up with my code or if it is potentially a bug.
I’m working on a variable Arabic font at the moment and I added conditional replacement to some letters.

Problem: the rlig feature, which is recommended for use in this case, already contains lam-alef required ligatures. Putting the conditional code in the same feature seems to lead to unexpected behaviour.

Example : Let’s say I switch kaf-ar to kafswash-ar over 40 wdth. I combine this code with the lam-alef substitution.

#ifdef VARIABLE

condition 40 < wdth < 100;
sub kaf-ar.init by kafswash-ar.init; 
sub kaf-ar.medi by kafswash-ar.medi;

#endif

script arab;
lookup rlig_arab_0 {
	lookupflag IgnoreMarks;
	sub lam-ar.init alef-ar.fina by lam_alef-ar;
	sub lam-ar.medi alef-ar.fina by lam_alef-ar.fina;
} rlig_arab_0;

The above code doesn’t change the kaf. The lam-alef ligature works as expected.
By reversing the order of both, it changes the kaf, but the lam-alef ligature breaks over 40 wdth.

I’ve found that by putting the conditional code in an empty feature (in my case, liga or any stylistic set) resolves the problem. But it’s not appropriate since it can be deactivated by the user. I already use rclt too, and for some reason I can’t get rvrn to work on InDesign. I don’t know what to do to make it hidden to the user and working at the same time.

Thanks in advance.

I think there are two issues with the code.

  1. The condition will apply to the whole feature, so you need to add a separate condition to the lam-alef ligature lookup for it to be active at the full width range.
  2. The script arab; line should be at the start of the feature or not there at all. (@GeorgSeifert is there any reason why the autogenerated rlig feature gets script arab; explicitly, but init/medi/fina don’t?)
1 Like

Thank you so much Jens! That was actually the problem. I still can’t believe how stupid that problem was. I think I have too much if/else logic coming from other programming languages. It might be worth mentioning in the documentation that applying a condition affects the entire feature.