Currently, applying Kashida is by adding "ـ" U+0640 ARABIC TATWEEL between letters. However, a more elegant way is by stretching a specific letter within the word. This method is popular with old scriptures, calligraphy, and handwritten messages.
Here is a rough estimate of the algorithm for the improved Kashida.
Start with the last word in a line, and apply stretching to the final letter in that word.
However, if the letter is not "stretch-able" (e.g: Arabic Meem م), then look for middle-form Kaaf (ك) and stretch that
If there is no Kaaf, apply the fallback Kashida by adding TATWEEL between letters.
TATWEEL is usually added to the last two connected letters. These letters are not necessarily the last letters of the word since they could be in isolated form (e.g: "الماء" --> "المـــاء") Notice that "اء" are isolated (they cannot connect).
Currently, applying Kashida is by adding "ـ" U+0640 ARABIC TATWEEL between letters. However, a more elegant way is by stretching a specific letter within the word. This method is popular with old scriptures, calligraphy, and handwritten messages.
Here is a rough estimate of the algorithm for the improved Kashida.
Examples: (Taken from KFGQPC print of Quran).
Single-letter Kashida applied to initial form "كـ" and final "ـى"
Applied to "ـكـ" and "ـب" in "الكتب"
Applied to "كـ" and "ـف" in "كيف"
Applied to "ـكـ"
Applied to last two connected letters in "الناس" (notice that س and ا are not connected) and last two connected letters in "عظيم".
Here is an example for a line. The algorithm works by