Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Assets/RTLTMPro/Ranges/UniversalRanges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0D,20-7E,60C,61B,61F,621-63A,640-669,670,67E,686,698,6A9,6AF,6CC,6F0-6F9,FB57-FB59,FB7B-FB7D,FB8B,FB8D,FB8F-FB91,FB93-FB95,FBFD-FBFF,FC5E-FC63,FE82,FE84,FE86,FE88,FE8A-FE8C,FE8E,FE90-FE92,FE94,FE96-FE98,FE9A-FE9C,FE9E-FEA0,FEA2-FEA4,FEA6-FEA8,FEAA,FEAC,FEAE,FEB0,FEB2-FEB4,FEB6-FEB8,FEBA-FEBC,FEBE-FEC0,FEC2-FEC4,FEC6-FEC8,FECA-FECC,FECE-FED0,FED2-FED4,FED6-FED8,FEDA-FEDC,FEDE-FEE0,FEE2-FEE4,FEE6-FEE8,FEEA-FEEC,FEEE,FEF0,FEF2-FEFC
7 changes: 7 additions & 0 deletions Assets/RTLTMPro/Ranges/UniversalRanges.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 54 additions & 5 deletions Assets/RTLTMPro/Scripts/Runtime/RTLTextMeshPro.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TMPro;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

namespace RTLTMPro
Expand Down Expand Up @@ -94,6 +95,8 @@ public bool ForceFix

protected readonly FastStringBuilder finalText = new FastStringBuilder(RTLSupport.DefaultBufferSize);

readonly List<string> currentArabicWordBuffer = new List<string>();

protected void Update()
{
if (havePropertiesChanged)
Expand All @@ -107,10 +110,55 @@ public void UpdateText()
if (originalText == null)
originalText = "";

if (ForceFix == false && TextUtils.IsRTLInput(originalText) == false)
if (!ForceFix && !TextUtils.IsRTLInput(originalText))
{
isRightToLeftText = false;
base.text = originalText;

string final = "";
string[] words = originalText.Split(' ');

//preprocess
int idx = -1;
int wIdx = 0;
foreach (string w in words) {
if (TextUtils.IsRTLInput(w)) {
if (idx == -1)
idx = wIdx;

currentArabicWordBuffer.Add(w);
}
else if (idx > -1) {
//we had a word buffer already
currentArabicWordBuffer.Reverse();
for (int i = idx; i < wIdx; i++) {
words[i] = currentArabicWordBuffer[i - idx];
}

currentArabicWordBuffer.Clear();
idx = -1;
}

wIdx++;
}

if (idx > -1) {
currentArabicWordBuffer.Reverse();
for (int i = idx; i < wIdx; i++) {
words[i] = currentArabicWordBuffer[i - idx];
}

currentArabicWordBuffer.Clear();
}

foreach (string w in words) {
string txt = TextUtils.IsRTLInput(w) ? GetFixedText(w, false) : w;
final += txt + ' ';
}

if (words.Length > 0)
final = final.Remove(final.Length - 1);

base.text = final;
} else
{
isRightToLeftText = true;
Expand All @@ -120,14 +168,15 @@ public void UpdateText()
havePropertiesChanged = true;
}

private string GetFixedText(string input)
private string GetFixedText(string input, bool reverse = true)
{
if (string.IsNullOrEmpty(input))
return input;

finalText.Clear();
RTLSupport.FixRTL(input, finalText, farsi, fixTags, preserveNumbers);
finalText.Reverse();
if (reverse)
finalText.Reverse();

return finalText.ToString();
}
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# MRK
Forked to fix LTR character starting sentences containing RTL words, letters, etc.

### Old Behaviour
"I'm مرك دا جودز aka MRK Da Gods على جيت هاب (on github)"

![](Screenshots/Old.png)

### New Behaviour
Tada!!

![](Screenshots/New.png)

### Ranges
I've also added a UniversalRanges.txt file in Assets/RTLTMPro/Ranges to fully include English & Arabic in the font atlas texture.

# RTL Text Mesh Pro
This plugin adds Right-to-left language support to "Text Mesh Pro" Unity plugin.
You need to have `TextMeshPro` plugin in your project. You can install TMPro via `Package Manager`.
Expand Down
Binary file added Screenshots/New.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/Old.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.