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

Is Wrap not supported? #21

Closed yassir-a-p closed 7 years ago

yassir-a-p commented 7 years ago

I don't know if this is known or not, but if it isn't then I'm surprised that it is no one use this Wrap mode before. You can see in the screenshot that the text' horizontal overflow is set to Wrap and it is then flowing from bottom to top. I'm currently working on simple project to make digitized version of text book (e-book), and it certainly contain lots of texts that it has to be in Wrap mode. So if this Wrap mode is not supported, do I have to write every single line as seperated gameobjects? I think this is important feature to support.

wraptruncate flowing bottom to top

MohHeader commented 7 years ago

You can use TextMeshPro :) will fix it for you ( you still may need to make a small hack due to a bug in their system. )

yassir-a-p commented 7 years ago

@MohHeader Would you please address the bug and how to fix it?

MohHeader commented 7 years ago

I am using the function below to fix the issue ( based on TextMeshPro forum,, you shouldn't need this hack )

But for me,, it didn't work !

public static string FixText (string s)
{
    string[] lines = s.Split (new string[]{ System.Environment.NewLine }, System.StringSplitOptions.None);
    for (int i = 0; i < lines.Length; i++)
    {
        List<StringData> data = new List<StringData> ();

        string temp = lines [i];

        int SafeCounter = 10;

        while (SafeCounter > 0 && (temp.Contains ("<") || temp.Contains (">")))
        {
            SafeCounter--;
            int index1 = temp.IndexOf ("<");
            int index2 = temp.IndexOf (">");

            if (index1 > index2)
            {
                temp.Remove (index2, 1);
                continue;
            }

            data.Add (new StringData (temp.Substring (index1, index2 - index1 + 1), index1));
            temp = temp.Remove (index1, index2 - index1 + 1);
        }

        lines [i] = ArabicSupport.ArabicFixer.Fix (temp);

        char[] charArray = lines [i].ToCharArray ();

        System.Array.Reverse (charArray);

        lines [i] = new string (charArray);
        temp = lines [i];

        for (int d = data.Count - 1; d >= 0; d--)
        {
            temp = temp.Insert (Mathf.Max (0, Mathf.Min (data [d].index, temp.Length - 1)), data [d].text);
        }
        lines [i] = temp;
    }

    return string.Join (System.Environment.NewLine, lines);
}

This hack would support Rich text ( HTML tags ) ,, but I have a minor bug that can easily be fixed using a whitespace,,, but if you don't use any HTML tags,, no need to worry about it ;)

yassir-a-p commented 7 years ago

@MohHeader I don't really understand the whole code, but I think i understand that it kinda reverse the array of letters, right? Actually, i've been thinking to make some texts be clickable using hyperlink and highlighting them. Since I don't really understand the code, would you tell me where would I put the code? Do I put it inside the ArabicSupport.cs, and replace a certain code or write them in a separate script?

MohHeader commented 7 years ago

it is a static function/method,,, you can put it anywhere :) ,,, and in this line

lines [i] = ArabicSupport.ArabicFixer.Fix (temp);

it uses the ArabicSupport.cs lib.

Konash commented 7 years ago

Just to be clear. Word wrapping is not a responsibility of the plugin. So technically, this is not even and "Issue". Lookup how to do manual word wrapping and you should be able to solve your problem.

yassir-a-p commented 7 years ago

Hmm.. That's unfortunate :( Anyway thanks for your hard works. 👍 Really appreciate what you guys have done. جزاكم الله خيرا

tamimzoabi commented 5 years ago

السلام عليكم هل وجدت حل للمشكله ؟

Brutalxnor commented 2 years ago

I am using the function below to fix the issue ( based on TextMeshPro forum,, you shouldn't need this hack )

But for me,, it didn't work !

public static string FixText (string s)
{
  string[] lines = s.Split (new string[]{ System.Environment.NewLine }, System.StringSplitOptions.None);
  for (int i = 0; i < lines.Length; i++)
  {
      List<StringData> data = new List<StringData> ();

      string temp = lines [i];

      int SafeCounter = 10;

      while (SafeCounter > 0 && (temp.Contains ("<") || temp.Contains (">")))
      {
          SafeCounter--;
          int index1 = temp.IndexOf ("<");
          int index2 = temp.IndexOf (">");

          if (index1 > index2)
          {
              temp.Remove (index2, 1);
              continue;
          }

          data.Add (new StringData (temp.Substring (index1, index2 - index1 + 1), index1));
          temp = temp.Remove (index1, index2 - index1 + 1);
      }

      lines [i] = ArabicSupport.ArabicFixer.Fix (temp);

      char[] charArray = lines [i].ToCharArray ();

      System.Array.Reverse (charArray);

      lines [i] = new string (charArray);
      temp = lines [i];

      for (int d = data.Count - 1; d >= 0; d--)
      {
          temp = temp.Insert (Mathf.Max (0, Mathf.Min (data [d].index, temp.Length - 1)), data [d].text);
      }
      lines [i] = temp;
  }

  return string.Join (System.Environment.NewLine, lines);
}

This hack would support Rich text ( HTML tags ) ,, but I have a minor bug that can easily be fixed using a whitespace,,, but if you don't use any HTML tags,, no need to worry about it ;)

What is StringData data type?