Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

TextMesh Pro RTL Text Mesh Pro. Free and Open-Source plugin to add Persian and Arabic support to TextMeshPro

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by sorencoder, Jun 12, 2018.

  1. sorencoder

    sorencoder

    Joined:
    Mar 27, 2017
    Posts:
    57
    Hi. I finally created a plugin to add Persian and Arabic support to TextMeshPro.

    Github link: https://github.com/sorencoder/RTLTMPro

    Features
    Realtime RTL Text
    You don't need to convert, copy and paste texts. Start writing and texts will be converted right away.



    Rich Text
    All Text Mesh Pro's tags are available in RTL Text Mesh Pro



    RTL InputField (See known issues)
    Realtime InputField is supported.



    Multiline
    Yes, This plugin has no problem with multiline RTL texts.



    AutoSize
    Auto Font Size is fully supported.



    English, Farsi and Arabic digits are supported


    Arabic Tashkeel
    Arabic tashkeel are supported. Also you can turn them off or on for every RTL Text Mesh Pro object.



    To see usage instructions visit github page:
    https://github.com/sorencoder/RTLTMPro

    Known Issues
    • Multiline has issues with English text.
    • InputField (and anything that was designed to work with TextMeshProUGUI script) will not work.
      Why it doesn't work? We need to override the text property of TextMeshProUGUI. But the text property is not defined virtual. You need to manually make the property virtual.
      • Open TMP_Text.cs from TextMeshPro source code
      • add virtual keyword to text property.
      • Open RTLTextMeshPro.cs and uncomment the top line where it says
        //#define RTL_OVERRIDE
      • Now you can use InputFields (and Dropdowns in future)

    @Stephan_B Would you make `text` property virtual in the source code so users don't have to make it virtual everytime they update? Would you gift a "virtual" keyword to all of users that want to use RTL languages?

    Have fun!
     
    Last edited: Jun 12, 2018
  2. GrassWhooper

    GrassWhooper

    Joined:
    Mar 25, 2016
    Posts:
    41
    i am using it for arabic, and i must say, you sir are a legend :) this worked like magic.
     
    sorencoder likes this.
  3. stgs73

    stgs73

    Joined:
    Mar 23, 2015
    Posts:
    44
    would love it if this could get officially incorporated.
     
    sorencoder and GrassWhooper like this.
  4. classicalguss

    classicalguss

    Joined:
    Apr 15, 2018
    Posts:
    6
    Our Input Fields are not working. I followed your steps of making the text virual in TMP_ Text.cs
    And then proceed to enable
    #define RTL_OVERRIDE
    on the file RTLTextMeshPro.cs

    We keep getting this error when we want to write something on the input field.
    IndexOutOfRangeException: Index was outside the bounds of the array.
    TMPro.TMP_InputField.GenerateCaret (UnityEngine.UI.VertexHelper vbo, UnityEngine.Vector2 roundingOffset) (at /Users/ghassanbarghouti/Library/Unity/cache/packages/packages.unity.com/com.unity.textmeshpro@1.2.4/Scripts/Runtime/TMP_InputField.cs:2817)
    TMPro.TMP_InputField.OnFillVBO (UnityEngine.Mesh vbo) (at /Users/ghassanbarghouti/Library/Unity/cache/packages/packages.unity.com/com.unity.textmeshpro@1.2.4/Scripts/Runtime/TMP_InputField.cs:2771)
    TMPro.TMP_InputField.UpdateGeometry () (at /Users/ghassanbarghouti/Library/Unity/cache/packages/packages.unity.com/com.unity.textmeshpro@1.2.4/Scripts/Runtime/TMP_InputField.cs:2716)
    TMPro.TMP_InputField.Rebuild (UnityEngine.UI.CanvasUpdate update) (at /Users/ghassanbarghouti/Library/Unity/cache/packages/packages.unity.com/com.unity.textmeshpro@1.2.4/Scripts/Runtime/TMP_InputField.cs:2670)
    UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:150)
    UnityEngine.Canvas:SendWillRenderCanvases()

    Kindly advise.
     
  5. sorencoder

    sorencoder

    Joined:
    Mar 27, 2017
    Posts:
    57
    Which version of the library are you using?
    Can you please check if the same thing happens with TextMeshPro 1.3 and RTLTMPro 3.1.1?
     
  6. classicalguss

    classicalguss

    Joined:
    Apr 15, 2018
    Posts:
    6
    The newest version of TextMeshPro is 1.2.2 though
     
  7. sorencoder

    sorencoder

    Joined:
    Mar 27, 2017
    Posts:
    57
    I'm referring to the PackageManager version:
    upload_2018-10-9_18-36-41.png
     
  8. classicalguss

    classicalguss

    Joined:
    Apr 15, 2018
    Posts:
    6
    Alright thanks, I'll check it out
     
  9. classicalguss

    classicalguss

    Joined:
    Apr 15, 2018
    Posts:
    6
    Thank you, it's working almost correctly. One problem I'm having is that I want to display the Arabic ي but instead I'm getting this ى (It's probably Persian). The Farsi checkbox can't be turned off, and I'm trying to disable it from the code but it also doesn't work (It only does when I re-click it while on play mode and on the editor).

    Kindly advise.
     
  10. classicalguss

    classicalguss

    Joined:
    Apr 15, 2018
    Posts:
    6
    I forced it to always be false from the Library, and it's working now.
     
  11. Lukas_Andriejunas

    Lukas_Andriejunas

    Unity Technologies

    Joined:
    Aug 19, 2016
    Posts:
    6
    Hi,

    Thank you for providing a plugin which fixes the issue of certain fonts not working correctly with TextMesh Pro.

    I have created a bug report about these fonts not being rendered out-of-the-box with TextMesh Pro.
    The progress of the report can be followed here: https://issuetracker.unity3d.com/product/unity/issues/guid/1090143/

    Regards,
    Lukas A.
    Unity QA Team
     
    MGGDev and sorencoder like this.
  12. Amin_Shiravand

    Amin_Shiravand

    Joined:
    Aug 1, 2018
    Posts:
    2
    Hi
    Dear @sorencoder the plugin you have written has an issue with HTML tags in Arabic and Persian Texts.
    For example texts like the one below:
    "سلام" + "<color=#A7DF40FF>" + یونیتی+ "</color>";
    don't display correctly.
    could you please have a check and help me if possible.
     
  13. bsweileh

    bsweileh

    Joined:
    Jun 1, 2018
    Posts:
    3
    This looks great! I have a question though:

    When typing Arabic text into the RTL text input box (as shown above), is it possible to make the Arabic text input appear joined together? My question is referring to how the text appears in the Unity editor inspector window - not the rendered TextMeshPro element in the scene view. Please advise. Thanks.
     
  14. sorencoder

    sorencoder

    Joined:
    Mar 27, 2017
    Posts:
    57
    Hi guys,
    Sorry for late reply, I have been very busy these days.

    There's a bug in tag detection that it doesn't detect tags with uppercase characters. It means that you need to write your color codes as #a7df40ff instead of #A7DF40FF.
    This bug will be fixed in next release.

    No. It's really hard and complicated to fix the text as you write it.
    In order for it to work, we need to track which characters have been fixed and which characters have not so we don't refix characters.
     
  15. Amin_Shiravand

    Amin_Shiravand

    Joined:
    Aug 1, 2018
    Posts:
    2
    Thank u so much @sorenc for your help
    I wish best for you.
     
  16. unity_Ns1DKIxVuImm6w

    unity_Ns1DKIxVuImm6w

    Joined:
    Dec 31, 2018
    Posts:
    1
    Hi Dear,

    Thanks for creating this marvelous plugin.

    I had followed all the steps but couldn't find any RTLTMP menu in GameObject/UI/*****

    Kindly help me to sort out this. New Picture (2).jpg
     
  17. drordoit

    drordoit

    Joined:
    Sep 7, 2013
    Posts:
    36
    Hi ,
    Thanks for this great plug.
    If I have a specific cheater that don't connect to the other character's, what can be the problem? is it a missing Unicode? Or something else?
    Thanks Dror
     
  18. sorencoder

    sorencoder

    Joined:
    Mar 27, 2017
    Posts:
    57
    Hi,
    Please check if you have any compile errors or not. Compilation error causes unity to stop compiling RTLTMPro files.
    However, You can add
    RTLTextMeshPro
    script to an empty gameobject to turn it into a text gameobject.

    If it shows the character as a box it means that the unicode is missing, otherwise it's more likely that plugin doesn't know that character. Post the whole sentence and a picture of the character shown correctly.
     
  19. drordoit

    drordoit

    Joined:
    Sep 7, 2013
    Posts:
    36
    the sentence is "اضغطوا على المفتاح الطويل." . As you can see the " على." isn't connected.
    upload_2019-2-19_22-35-15.png
     

    Attached Files:

  20. YaserDev

    YaserDev

    Joined:
    Aug 17, 2016
    Posts:
    18
    @drordoit I have tried to solve the linked "Alef Maqsora" problem, the only thing that worked is using a font that the fontAssetCreator can generate the linked Alef Maqsoora character from, the following fonts have worked for me:
    -Changa
    -Markazi
    I think this has to do with the range you set in the fontAssetCreator, so don't forget to set the following range for the Arabic language:
    0600-06FF,0750-077F,08A0-08FF,FB50-FDFF,FE70-FEFF,10E60-10E7F,1EE00-1EEFF

    @sorencoder
    Thanks for providing this plugin for free and open sourcing it.
    I have a question: how did you manage to get the Auto Font Size feature to work?
    Updating the text whenever the Rect-Transform size changes didn't work for me.
    I just wanna know since I'm trying to build a custom solution while relying on the default TMPro component.
    Any help would be appreciated.
     
  21. AAK_Lebanon

    AAK_Lebanon

    Joined:
    May 30, 2015
    Posts:
    56
    Hi, I have used this plug-in before and it was worked, however, today a started using Unity 2019.1 and TMPPro version 2.0.0 with the latest release of your plug-in from Github, I also added the 'virtual' keyword to the TMP_Text.cs and uncommented '#define RTL_OVERRIDE' in the RTLTextMeshPro.cs (as described in the introduction), however, I am unable to enter any test in the RTL Input Box, I always get this error:

    NullReferenceException: Object reference not set to an instance of an object
    RTLTMPro.RTLTextMeshProEditor.OnInspectorGUI () (at Assets/RTLTMPro/Scripts/Editor/RTLTextMeshProEditor.cs:50)
    UnityEditor.UIElements.InspectorElement+<CreateIMGUIInspectorFromEditor>c__AnonStorey1.<>m__0 () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorElement.cs:445)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    Also I always get this warning and I don't know how to fix it (or if I can fix or should fix it):

    The character used for Underline and Strikethrough is not available in font asset [al-mujahed free SDF].
    UnityEngine.Debug:LogWarning(Object, Object)
    TMPro.TMP_Text:GetSpecialCharacters(TMP_FontAsset) (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMP_Text.cs:5451)
    TMPro.TextMeshProUGUI:LoadFontAsset() (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMPro_UGUI_Private.cs:561)
    TMPro.TextMeshProUGUI:OnValidate() (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMPro_UGUI_Private.cs:294)
    UnityEditor.SerializedObject:ApplyModifiedProperties()
    TMPro.EditorUtilities.TMP_BaseEditorPanel:OnInspectorGUI() (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Editor/TMP_BaseEditorPanel.cs:272)
    RTLTMPro.RTLTextMeshProEditor:OnInspectorGUI() (at Assets/RTLTMPro/Scripts/Editor/RTLTextMeshProEditor.cs:60)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    and also this one:


    The character used for Ellipsis is not available in font asset [al-mujahed free SDF].
    UnityEngine.Debug:LogWarning(Object, Object)
    TMPro.TMP_Text:GetSpecialCharacters(TMP_FontAsset) (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMP_Text.cs:5463)
    TMPro.TextMeshProUGUI:LoadFontAsset() (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMPro_UGUI_Private.cs:561)
    TMPro.TextMeshProUGUI:OnValidate() (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMPro_UGUI_Private.cs:294)
    UnityEditor.SerializedObject:ApplyModifiedProperties()
    TMPro.EditorUtilities.TMP_BaseEditorPanel:OnInspectorGUI() (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Editor/TMP_BaseEditorPanel.cs:272)
    RTLTMPro.RTLTextMeshProEditor:OnInspectorGUI() (at Assets/RTLTMPro/Scripts/Editor/RTLTextMeshProEditor.cs:60)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    Any help will be appreciated ...
     
    nimaestakhri likes this.
  22. sorencoder

    sorencoder

    Joined:
    Mar 27, 2017
    Posts:
    57
    Auto size is handled by text mesh pro itself.

    @AAK_Lebanon
    I have not checked the compatibility of the plugin with Unity 2019.1.
    Will take a look when I get a chance.
     
    AAK_Lebanon likes this.
  23. AAK_Lebanon

    AAK_Lebanon

    Joined:
    May 30, 2015
    Posts:
    56
    @sorencoder thanks for you and for your plugin, it is really useful.

    actually, I investigated in the code and I discovered a solution for me (or a problem, I don't know:)
    this 3 lines of code on the OnEnable in RTLTextMeshProEditor.cs will always return null:

    Code (CSharp):
    1.  havePropertiesChangedProp = serializedObject.FindProperty("m_havePropertiesChanged");
    2.             inputSourceProp = serializedObject.FindProperty("m_inputSource");
    3.             isInputPasingRequiredProp = serializedObject.FindProperty("m_isInputParsingRequired");
    So I changed them in TMP_Text.cs and added the serialized attribute (that it was commented)

    now it works, but I still have the warning, and I can't get the Arabic letter on the screen and I think it is because of my font. I don't know why many many Arabic fonts do not have (I think) the right Unicode mapping...

    however, I don't know if there is a more clean solution, because now, on every update for the TextMesh Pro, I will lose these modifications...
     
    sorencoder likes this.