Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved Issue #124 The underlines are not correctly displayed in RTL #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
695 changes: 695 additions & 0 deletions Assets/RTLTMPro/Scenes/Underline.unity

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Assets/RTLTMPro/Scenes/Underline.unity.meta

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

110 changes: 108 additions & 2 deletions Assets/RTLTMPro/Scripts/Editor/RTLTextMeshProEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using TMPro.EditorUtilities;
using System.Reflection;
using TMPro;
using TMPro.EditorUtilities;
using UnityEditor;
using UnityEngine;

Expand All @@ -13,6 +15,15 @@ namespace RTLTMPro
[CustomEditor(typeof(RTLTextMeshPro)), CanEditMultipleObjects]
public class RTLTextMeshProEditor : TMP_UiEditorPanel
{
static readonly GUIContent k_RtlToggleLabel = new GUIContent("Enable RTL Editor", "Reverses text direction and allows right to left editing.");
static readonly GUIContent k_StyleLabel = new GUIContent("Text Style", "The style from a style sheet to be applied to the text.");

FieldInfo m_inputSourceField;
FieldInfo m_TextStyleField;

RTLTextMeshPro rTLTextMeshPro;

private SerializedProperty enableRTLProp;
private SerializedProperty originalTextProp;
private SerializedProperty preserveNumbersProp;
private SerializedProperty farsiProp;
Expand All @@ -24,8 +35,14 @@ public class RTLTextMeshProEditor : TMP_UiEditorPanel

protected override void OnEnable()
{
rTLTextMeshPro = (RTLTextMeshPro)target;
base.OnEnable();
foldout = true;

m_inputSourceField = m_TextComponent.GetType().GetField("m_TextComponent", BindingFlags.Instance | BindingFlags.NonPublic);
m_TextStyleField = m_TextComponent.GetType().GetField("m_TextStyle", BindingFlags.Instance | BindingFlags.NonPublic);

enableRTLProp = serializedObject.FindProperty("enalbeRTL");
preserveNumbersProp = serializedObject.FindProperty("preserveNumbers");
farsiProp = serializedObject.FindProperty("farsi");
fixTagsProp = serializedObject.FindProperty("fixTags");
Expand All @@ -49,7 +66,26 @@ public override void OnInspectorGUI()

serializedObject.ApplyModifiedProperties();

base.OnInspectorGUI();
// Make sure Multi selection only includes TMP Text objects.
if (IsMixSelectionTypes())
return;

serializedObject.Update();

DrawTextInput();

DrawMainSettings();

DrawExtraSettings();

EditorGUILayout.Space();

if (serializedObject.ApplyModifiedProperties() || m_HavePropertiesChanged)
{
m_TextComponent.havePropertiesChanged = true;
m_HavePropertiesChanged = false;
EditorUtility.SetDirty(target);
}

foldout = EditorGUILayout.Foldout(foldout, "RTL Settings", TMP_UIStyleManager.boldFoldout);
if (foldout)
Expand Down Expand Up @@ -109,5 +145,75 @@ protected virtual void ListenForZeroWidthNoJoiner()
Event.current.Use();
Repaint();
}

protected new void DrawTextInput()
{
EditorGUILayout.Space();

Rect rect = EditorGUILayout.GetControlRect(false, 22);
GUI.Label(rect, new GUIContent("<b>Text Input</b>"), TMP_UIStyleManager.sectionHeader);

EditorGUI.indentLevel = 0;

// If the text component is linked, disable the text input box.
if (m_ParentLinkedTextComponentProp.objectReferenceValue != null)
{
EditorGUILayout.HelpBox("The Text Input Box is disabled due to this text component being linked to another.", MessageType.Info);
}
else
{
// Display RTL Toggle
float labelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 110f;

enableRTLProp.boolValue = EditorGUI.Toggle(new Rect(rect.width - 120, rect.y + 3, 130, 20), k_RtlToggleLabel, enableRTLProp.boolValue);

EditorGUIUtility.labelWidth = labelWidth;

EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_TextProp, GUIContent.none);

// Need to also compare string content due to issue related to scroll bar drag handle
if (EditorGUI.EndChangeCheck() && m_TextProp.stringValue != m_TextComponent.text)
{
m_inputSourceField.SetValue(m_TextComponent, 0);
m_HavePropertiesChanged = true;
}

if (enableRTLProp.boolValue)
{
GUILayout.Label("RTL Text Input");

EditorGUI.BeginChangeCheck();
rTLTextMeshPro.rtlText = EditorGUILayout.TextArea(rTLTextMeshPro.rtlText, TMP_UIStyleManager.wrappingTextArea, GUILayout.Height(EditorGUI.GetPropertyHeight(m_TextProp) - EditorGUIUtility.singleLineHeight), GUILayout.ExpandWidth(true));

if (EditorGUI.EndChangeCheck())
{
m_TextProp.stringValue = rTLTextMeshPro.rtlText;
}
}

// TEXT STYLE
if (m_StyleNames != null)
{
rect = EditorGUILayout.GetControlRect(false, 17);

EditorGUI.BeginProperty(rect, k_StyleLabel, m_TextStyleHashCodeProp);

m_TextStyleIndexLookup.TryGetValue(m_TextStyleHashCodeProp.intValue, out m_StyleSelectionIndex);

EditorGUI.BeginChangeCheck();
m_StyleSelectionIndex = EditorGUI.Popup(rect, k_StyleLabel, m_StyleSelectionIndex, m_StyleNames);
if (EditorGUI.EndChangeCheck())
{
m_TextStyleHashCodeProp.intValue = m_Styles[m_StyleSelectionIndex].hashCode;
m_TextStyleField.SetValue(m_TextComponent, m_Styles[m_StyleSelectionIndex]);
m_HavePropertiesChanged = true;
}

EditorGUI.EndProperty();
}
}
}
}
}
13 changes: 13 additions & 0 deletions Assets/RTLTMPro/Scripts/Runtime/FastStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,18 @@ private static void Copy(int[] src, int[] dst) {
for (int i = 0; i < src.Length; i++)
dst[i] = src[i];
}

public void Join(FastStringBuilder output, params FastStringBuilder[] inputs)
{
output.Clear();

foreach (var input in inputs)
{
for (int i = 0; i < input.length; i++)
{
output.Append(input.Get(i));
}
}
}
}
}
12 changes: 10 additions & 2 deletions Assets/RTLTMPro/Scripts/Runtime/LigatureFixer.cs.meta

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

13 changes: 8 additions & 5 deletions Assets/RTLTMPro/Scripts/Runtime/RTLSupport.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// ReSharper disable IdentifierTypo
// ReSharper disable IdentifierTypo
// ReSharper disable CommentTypo

using UnityEngine;

namespace RTLTMPro
{
public static class RTLSupport
Expand Down Expand Up @@ -38,16 +40,17 @@ public static void FixRTL(
GlyphFixer.Fix(inputBuilder, glyphFixerOutput, preserveNumbers, farsi, fixTextTags);
//Restore tashkeel to their places.
TashkeelFixer.RestoreTashkeel(glyphFixerOutput);

TashkeelFixer.FixShaddaCombinations(glyphFixerOutput);

// Fix flow of the text and put the result in FinalLetters field
LigatureFixer.Fix(glyphFixerOutput, output, farsi, fixTextTags, preserveNumbers);
if (fixTextTags)
{
RichTextFixer.Fix(output);
RichTextFixer.CorrectTagOrder(output);
}

inputBuilder.Clear();
}

}
}
}
3 changes: 2 additions & 1 deletion Assets/RTLTMPro/Scripts/Runtime/RTLTMPro.asmdef
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "RTLTMPro",
"rootNamespace": "",
"references": [
"Unity.TextMeshPro"
"GUID:6055be8ebefd69e48b49212b09b47b2f"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
23 changes: 14 additions & 9 deletions Assets/RTLTMPro/Scripts/Runtime/RTLTextMeshPro.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using TMPro;
using TMPro;
using UnityEngine;

namespace RTLTMPro
Expand All @@ -25,6 +25,8 @@ public override string text
}
}

public string rtlText;

public string OriginalText
{
get { return originalText; }
Expand Down Expand Up @@ -76,12 +78,15 @@ public bool ForceFix
{
if (forceFix == value)
return;


forceFix = value;
havePropertiesChanged = true;
}
}

[SerializeField] protected bool enalbeRTL = true;

[SerializeField] protected bool preserveNumbers;

[SerializeField] protected bool farsi = true;
Expand All @@ -106,15 +111,16 @@ public void UpdateText()
{
if (originalText == null)
originalText = "";

if (ForceFix == false && TextUtils.IsRTLInput(originalText) == false)
if (!enalbeRTL || (ForceFix == false && TextUtils.IsRTLInput(originalText) == false))
{
isRightToLeftText = false;
rtlText = string.Empty;
base.text = originalText;
} else
}
else
{
isRightToLeftText = true;
base.text = GetFixedText(originalText);
rtlText = GetFixedText(originalText);
base.text = rtlText;
}

havePropertiesChanged = true;
Expand All @@ -127,8 +133,7 @@ private string GetFixedText(string input)

finalText.Clear();
RTLSupport.FixRTL(input, finalText, farsi, fixTags, preserveNumbers);
finalText.Reverse();
return finalText.ToString();
}
}
}
}
Loading