Konash / arabic-support-unity

This plugin allows you to use accurate and correct Arabic text in your game or 3D application. Supports Tashkeel and Hindu numbers. Supports C# and JavaScript. Supports 4 Persian Characters.
MIT License
220 stars 64 forks source link

combined Tashkeel cases. #10

Closed MohHeader closed 7 years ago

MohHeader commented 7 years ago

Some Tashkeel are printed as separate letters instead of using the combined version.

Example Shaddah + Fatha should use the combined version of : 0xFC60 unicode. https://www.compart.com/en/unicode/U+FC60

Working on a fix. if fixed it,, will do a Merge Request ( or post the solution here )

Thanks

MohHeader commented 7 years ago
    internal static string RemoveTashkeel(string str, out List<TashkeelLocation> tashkeelLocation)
    {
        tashkeelLocation = new List<TashkeelLocation>();
        char[] letters = str.ToCharArray();

        int index = 0;
        for (int i = 0; i < letters.Length; i++) {
            if (letters [i] == (char)0x064B) { // Tanween Fatha
                tashkeelLocation.Add (new TashkeelLocation ((char)0x064B, i));
                index++;
            } else if (letters [i] == (char)0x064C) { // DAMMATAN
                tashkeelLocation.Add (new TashkeelLocation ((char)0x064C, i));
                index++;
            } else if (letters [i] == (char)0x064D){ // KASRATAN
                tashkeelLocation.Add (new TashkeelLocation ((char)0x064D, i));
                index++;
            }else if (letters [i] == (char)0x064E) { // FATHA
                if(index > 0)
                {
                    if(tashkeelLocation[index-1].tashkeel == (char)0x0651 ) // SHADDA
                    {
                        tashkeelLocation [index - 1].tashkeel = (char)0xFC60; // Shadda With Fatha
                        continue;
                    }
                }

                tashkeelLocation.Add (new TashkeelLocation ((char)0x064E, i));
                index++;
            } else if (letters [i] == (char)0x064F) { // DAMMA
                if (index > 0) {
                    if (tashkeelLocation [index - 1].tashkeel == (char)0x0651) { // SHADDA
                        tashkeelLocation [index - 1].tashkeel = (char)0xFC61; // Shadda With DAMMA
                        continue;
                    }
                }
                tashkeelLocation.Add (new TashkeelLocation ((char)0x064F, i));
                index++;
            } else if (letters [i] == (char)0x0650) { // KASRA
                if (index > 0) {
                    if (tashkeelLocation [index - 1].tashkeel == (char)0x0651) { // SHADDA
                        tashkeelLocation [index - 1].tashkeel = (char)0xFC62; // Shadda With KASRA
                        continue;
                    }
                }
                tashkeelLocation.Add (new TashkeelLocation ((char)0x0650, i));
                index++;
            } else if (letters [i] == (char)0x0651) { // SHADDA
                if(index > 0)
                {
                    if(tashkeelLocation[index-1].tashkeel == (char)0x064E ) // FATHA
                    {
                        tashkeelLocation [index - 1].tashkeel = (char)0xFC60; // Shadda With Fatha
                        continue;
                    }

                    if(tashkeelLocation[index-1].tashkeel == (char)0x064F ) // DAMMA
                    {
                        tashkeelLocation [index - 1].tashkeel = (char)0xFC61; // Shadda With DAMMA
                        continue;
                    }

                    if(tashkeelLocation[index-1].tashkeel == (char)0x0650 ) // KASRA
                    {
                        tashkeelLocation [index - 1].tashkeel = (char)0xFC62; // Shadda With KASRA
                        continue;
                    }
                }

                tashkeelLocation.Add (new TashkeelLocation ((char)0x0651, i));
                index++;
            } else if (letters [i] == (char)0x0652) { // SUKUN
                tashkeelLocation.Add (new TashkeelLocation ((char)0x0652, i));
                index++;
            } else if (letters [i] == (char)0x0653) { // MADDAH ABOVE
                tashkeelLocation.Add (new TashkeelLocation ((char)0x0653, i));
                index++;
            }
        }

        string[] split = str.Split(new char[]{(char)0x064B,(char)0x064C,(char)0x064D,
            (char)0x064E,(char)0x064F,(char)0x0650,
            (char)0x0651,(char)0x0652,(char)0x0653,(char)0xFC60,(char)0xFC61,(char)0xFC62});

        str = "";

        foreach(string s in split)
        {
            str += s;
        }

        return str;
    }
Konash commented 7 years ago

Is that the solution? I would recommend a merge if so.

MohHeader commented 7 years ago

It is working ( at least for me ),,, Will create a merge request, 👍

MohHeader commented 7 years ago

11

Konash commented 7 years ago

Don't forget to make test cases as well.

On Aug 8, 2017 12:47 AM, "Mohammed Header" notifications@github.com wrote:

11 https://github.com/Konash/arabic-support-unity/pull/11

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Konash/arabic-support-unity/issues/10#issuecomment-320849009, or mute the thread https://github.com/notifications/unsubscribe-auth/ALtBUlEPlHBOBbwb1emtaZZFRFw8_iXNks5sV-htgaJpZM4OfZrf .