Author Topic: RTL Support in auto line breaks/wrapping  (Read 42761 times)

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: RTL Support in auto line breaks/wrapping
« Reply #30 on: March 24, 2016, 12:05:41 PM »
I can't remember the font but the Arabic character set is from Unicode Range (Hex) 600-6FF, 750-77F. For simple test if often use the Custom Characters option and copy paste them in the editor window.

Here is an example of the settings I used with Arial. Notice how Arial is missing several glyphs for Arabic.
[ Guests cannot view attachments ]

ARafay

  • Full Member
  • ***
  • Posts: 133
Re: RTL Support in auto line breaks/wrapping
« Reply #31 on: March 24, 2016, 12:38:01 PM »
Thanks to you im able to create font asset with arabic letters, now when i try to render a text it gets broken unlike your example which has complete words in it. Can you please guide here

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: RTL Support in auto line breaks/wrapping
« Reply #32 on: March 24, 2016, 01:21:42 PM »
Thanks to you im able to create font asset with arabic letters, now when i try to render a text it gets broken unlike your example which has complete words in it. Can you please guide here

Can you post examples of what you have? Since I am not fluent with Arabic, i need you to provide an example of what you have vs how it should be to be correct.

ARafay

  • Full Member
  • ***
  • Posts: 133
Re: RTL Support in auto line breaks/wrapping
« Reply #33 on: March 24, 2016, 01:42:09 PM »
Same here, Arabic is not my language as well.
But this image shows a working example and thats what i need.

Can you please find it or recreate it as unity project and share?


Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: RTL Support in auto line breaks/wrapping
« Reply #34 on: March 24, 2016, 04:17:04 PM »
If I recall correctly, I used this free asset which converts the text correctly since Unity's editor has issues. https://www.assetstore.unity3d.com/en/#!/content/2674

With this tool, I would copy the text from the internet and paste it into their Fix3D Text input. This would return a new string in the TextMesh editor. I would grab this new text and copy / paste in the lower Text Input Box of TextMesh Pro when RTL is enabled. I guess this is all needed to handle character substitution. Since this only involves altering the source text from the original text to this other format perhaps a TMP user fluent in the language could provide a script to handle this in a simpler manner. I also possibly could integrate that into TMP when RTL is selected.

Seems like the range for characters is larger than what I previously posted. Here is the latest range which includes all the Arabic characters. See https://en.wikipedia.org/wiki/Arabic_script_in_Unicode

New range 600-6FF,750-77F,8A0-8FF,FB50-FDFF,FE70-FEFF,10E60-10E7F,1EE00-1EEFF

Keep in mind that most fonts do not contain all or even most of those characters. ARIAL for instance only contains 540 of the potential 1520 characters.



This is a 1024 X 1024 with decent sampling point size of 61. I guess I could have increased the size to 2048 X 1024 and added the ASCII set plug punctuation in there too or simply use a ARIAL as Fallback which would be fine too.

Using this new font asset and process outlined above, I grabbed some text from the BBC sports page. Something about Soccer and here are the results.

« Last Edit: March 24, 2016, 06:18:10 PM by Stephan B. »

ARafay

  • Full Member
  • ***
  • Posts: 133
Re: RTL Support in auto line breaks/wrapping
« Reply #35 on: March 25, 2016, 03:34:20 AM »
Thanks, you are awesome :)

how can i set text programmatically? as now 2 text boxes appear when i set RTL enabled.
Should i simply use .text property of TMPUGUI?

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: RTL Support in auto line breaks/wrapping
« Reply #36 on: March 25, 2016, 04:06:57 AM »
You will need to use the API of that Arabic tool until I incorporate similar functionality in TMP.

Code: [Select]
void Start()
{
     TMP_Text obj = GetComponent<TMP_Text>();
     obj.text = ArabicSupport.ArabicFixer.Fix("فَتَعَالَى اللَّهُ الْمَلِكُ الْحَقُّ ۗ وَلَا تَعْجَلْ بِالْقُرْآنِ مِن قَبْلِ أَن يُقْضَىٰ إِلَيْكَ وَحْيُهُ ۖ وَقُل رَّبِّ زِدْنِي عِلْمًا ", true, true);
}

Make sure RTL is enabled and I believe the text might end up backwards but if you take the string and reverse it, it should work correctly. I simply forgot about the API part of this.

I'll work on this tomorrow as I now have another user who is fluent in Arabic who can provide feedback to make sure the is correct.

ARafay

  • Full Member
  • ***
  • Posts: 133
Re: RTL Support in auto line breaks/wrapping
« Reply #37 on: March 26, 2016, 11:04:39 PM »
You will need to use the API of that Arabic tool until I incorporate similar functionality in TMP.

Code: [Select]
void Start()
{
     TMP_Text obj = GetComponent<TMP_Text>();
     obj.text = ArabicSupport.ArabicFixer.Fix("فَتَعَالَى اللَّهُ الْمَلِكُ الْحَقُّ ۗ وَلَا تَعْجَلْ بِالْقُرْآنِ مِن قَبْلِ أَن يُقْضَىٰ إِلَيْكَ وَحْيُهُ ۖ وَقُل رَّبِّ زِدْنِي عِلْمًا ", true, true);
}

Make sure RTL is enabled and I believe the text might end up backwards but if you take the string and reverse it, it should work correctly. I simply forgot about the API part of this.

I'll work on this tomorrow as I now have another user who is fluent in Arabic who can provide feedback to make sure the is correct.


Awesome, i know you are already busy with TextInput so what we can do is make progress using that other asset for text reversing etc while you spare some time to render that text fine (which is already rendering fine in your example). I just started and let you know result soon. Meanwhile can you please invite other user here and ask what Arabic font should we use which will have all the elements.


EDIT
Text is working AMAZINGLY fine, Thanks Man :D
Now all i need to know where we can find fonts which support all the arabic unicode characters (no more missing characters issue)
« Last Edit: March 26, 2016, 11:30:53 PM by manofspirit »

ARafay

  • Full Member
  • ***
  • Posts: 133
Re: RTL Support in auto line breaks/wrapping
« Reply #38 on: March 27, 2016, 01:04:41 AM »
Just wanted to Say Thank You once again:)
Cant wait for Input Component that support export/import in HTML
« Last Edit: March 27, 2016, 01:23:34 AM by manofspirit »

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: RTL Support in auto line breaks/wrapping
« Reply #39 on: March 28, 2016, 11:54:22 PM »
Since I never added a property for RTL, one will need to be added.

First, you will need to modify the TMP_Text.cs file to add the new isRightToLeft property. I added this right below the text property.

Code: C#
  1. /// <summary>
  2. ///
  3. /// </summary>
  4. public bool isRightToLeftText
  5. {
  6.     get { return m_isRightToLeft; }
  7.     set { if (m_isRightToLeft == value) return; m_isRightToLeft = value; m_havePropertiesChanged = true; m_isCalculateSizeRequired = true; m_isInputParsingRequired = true; SetVerticesDirty(); SetLayoutDirty(); }
  8. }
  9. [SerializeField]
  10. protected bool m_isRightToLeft = false;
  11.  

Next, since the m_isRightToLeft field already exists so you will have to remove the duplicate declaration.

Lastly, create the following script and attached it to either type of TextMeshPro object.

Code: [Select]
using UnityEngine;
using System.Collections;
using TMPro;


public class SandBox_12 : MonoBehaviour {

    void Start()
    {
        TMP_Text textComponent = GetComponent<TMP_Text>();
        textComponent.isRightToLeftText = true;
        textComponent.alignment = TextAlignmentOptions.TopRight;

        string sourceText = ArabicSupport.ArabicFixer.Fix("فَتَعَالَى اللَّهُ الْمَلِكُ الْحَقُّ ۗ وَلَا تَعْجَلْ بِالْقُرْآنِ مِن قَبْلِ أَن يُقْضَىٰ إِلَيْكَ وَحْيُهُ ۖ وَقُل رَّبِّ زِدْنِي عِلْمًا ", true, true);

        textComponent.text = ReverseText(sourceText);
    }



    string ReverseText(string source)
    {
        char[] output = new char[source.Length];
        for (int i = 0; i < source.Length; i++)
        {
            output[(output.Length - 1) - i] = source[i];
        }
        return new string(output);
    }
}

Let me know if this works. This is a rough solution to allow you to get some text going.

ARafay

  • Full Member
  • ***
  • Posts: 133
Re: RTL Support in auto line breaks/wrapping
« Reply #40 on: March 29, 2016, 12:52:32 AM »
Thanks :), thats what i needed. You Rock

ARafay

  • Full Member
  • ***
  • Posts: 133
Re: RTL Support in auto line breaks/wrapping
« Reply #41 on: April 16, 2016, 08:41:34 AM »
Hi Steph,

For now Arabic support is working fine however there is only one issue remaining that require your attension,

Arabic character http://unicode.scarfboy.com/?s=U%2B0622 is not rendered properly because TextMesh doesnt know where to place that extra character on/over "I" like shape.

When i try to render this text
آم

it doesnt appear. Can you please take a look

ARafay

  • Full Member
  • ***
  • Posts: 133
Re: RTL Support in auto line breaks/wrapping
« Reply #42 on: April 17, 2016, 04:59:30 AM »
BUMP

Stephan B.

  • Administrator
  • Hero Member
  • *****
  • Posts: 5687
Re: RTL Support in auto line breaks/wrapping
« Reply #43 on: April 17, 2016, 08:05:37 AM »
I'll take a look later today and let you know what I find.

ARafay

  • Full Member
  • ***
  • Posts: 133
Re: RTL Support in auto line breaks/wrapping
« Reply #44 on: April 18, 2016, 04:21:28 AM »
I'll take a look later today and let you know what I find.

Any update?