- uint32_t cp = out_cp[o];
- uint32_t next = o < cp_count - 1 ? out_cp[o + 1] : 0;
- uint32_t tcp = get_presentation_form_b_of_char(prev, next, cp);
- if( tcp != (uint32_t)-1 ) {
- out_cp[s] = tcp;
+ uint32_t cp = out_cp[o];
+
+ if (!is_tashkil_letter(cp)) {
+ uint32_t next = o < cp_count - 1 ? out_cp[o + 1] : 0;
+
+ if (is_tashkil_letter(next))
+ next = (o + 1) < cp_count - 1 ? out_cp[o + 2] : 0;
+
+ uint32_t tcp = get_presentation_form_b_of_char(prev, next, cp);
+ if( tcp != (uint32_t)-1 ) {
+ out_cp[s] = tcp;
+ ++s;
+ }
+ prev = cp;
+ } else {
+ out_cp[s] = cp;