From 3ab5267d489889f491c823a73eb6066c9dbacae6 Mon Sep 17 00:00:00 2001 From: Alon Talmi Date: Sun, 30 Jul 2023 11:13:10 +0300 Subject: [PATCH 1/6] Added package.json --- Assets/RTLTMPro/package.json | 12 ++++++++++++ README.md | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 Assets/RTLTMPro/package.json diff --git a/Assets/RTLTMPro/package.json b/Assets/RTLTMPro/package.json new file mode 100644 index 0000000..be79e13 --- /dev/null +++ b/Assets/RTLTMPro/package.json @@ -0,0 +1,12 @@ +{ + "name": "com.pnarimani.rtltmpro", + "displayName": "RTLTMPro", + "version": "1.0.0", + "description": "This plugin adds Right-to-left language support to \"TextMeshPro\" Unity plugin. Currently Arabic, Farsi and Hebrew are supported.", + "author": "pnarimani", + "unity": "2021.3", + "unityRelease": "22f1", + "documentationUrl": "https://github.com/pnarimani/RTLTMPro", + "changelogUrl": "https://github.com/pnarimani/RTLTMPro", + "licensesUrl": "https://github.com/pnarimani/RTLTMPro/blob/master/LICENSE" +} diff --git a/README.md b/README.md index 6d698c9..8331c4c 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,9 @@ You can insert Zero-Width No-Joiner character with Ctrl+Shift+2 hotkey. ### from .unitypackage file Download the latest unitypackage file from the [releases](https://github.com/sorencoder/RTLTMPro/releases) section and import it into your project from "Assets -> Import Package -> Custom Package..." menu in Unity. +## from UPM +https://github.com/AlonTalmi/RTLTMPro.git?path=Assets/RTLTMPro + ### from OpenUPM [hk1ll3r](https://github.com/hk1ll3r/) maintains a package manager version of this repo on [OpenUPM](https://openupm.com/packages/com.nosuchstudio.rtltmpro/). From 1346536c4575bd9696bc5f12dcb13d9c7ff120f6 Mon Sep 17 00:00:00 2001 From: Alon Talmi Date: Sun, 30 Jul 2023 11:36:40 +0300 Subject: [PATCH 2/6] Add missing meta file --- Assets/RTLTMPro/package.json.meta | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Assets/RTLTMPro/package.json.meta diff --git a/Assets/RTLTMPro/package.json.meta b/Assets/RTLTMPro/package.json.meta new file mode 100644 index 0000000..cb1be90 --- /dev/null +++ b/Assets/RTLTMPro/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e8b93d176f22141119a445740668fb1b +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From a6f6168aebe10c9a504992d560375cc9bfece33a Mon Sep 17 00:00:00 2001 From: Alon Talmi Date: Sun, 30 Jul 2023 11:37:51 +0300 Subject: [PATCH 3/6] Junk files --- .DS_Store | Bin 0 -> 6148 bytes .../.idea.RTLTMPro.dir/.idea/indexLayout.xml | 8 +++ .../.idea/projectSettingsUpdater.xml | 6 ++ .idea/.idea.RTLTMPro.dir/.idea/workspace.xml | 65 ++++++++++++++++++ Assets/.DS_Store | Bin 0 -> 6148 bytes 5 files changed, 79 insertions(+) create mode 100644 .DS_Store create mode 100644 .idea/.idea.RTLTMPro.dir/.idea/indexLayout.xml create mode 100644 .idea/.idea.RTLTMPro.dir/.idea/projectSettingsUpdater.xml create mode 100644 .idea/.idea.RTLTMPro.dir/.idea/workspace.xml create mode 100644 Assets/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2373d60946bebbef8642bd67229aa50a415b5f3e GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8CKMqDg&r5Y7EJv^@e*Tw0V8@)sfh_1jM>tp=1>Yb>kIiLK94iI zTcK1BUPQ`FnEj@+Gn?+0u#;hoaeo~57;_k77ARuFhT$8*dDI1I7*7+Bt2IhiL{%}2 zG8rvIljA=!fX{A~ov;F~gv~#{_h^`)wXVfM_C1BSdI%n99`qD z3n{Z`W{1&bnp6X4<5cElnC8hyC8TizAvafP9?Qy?<2)`@ZlEVD+qMTzXEND$-LBX> z>`l93a^YaOnn(`soRW2eGk61IZclM>pGEK=F<@@uB^c$I z%pbr%TMT1Jhyh}N7+7)!%#mlcmwcbJJz{_u_&o!7J_t}m&tR=l9UU;J767mXZY5x2 zFM&D2pl7hw2s0pDrvmC!Zdwek)4?xHoM*7ssM8rY%?CGk=B7j8>h7?PO@-2bZ}8i)a6U^yA!t$xt=VQ;3kF6 + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.RTLTMPro.dir/.idea/projectSettingsUpdater.xml b/.idea/.idea.RTLTMPro.dir/.idea/projectSettingsUpdater.xml new file mode 100644 index 0000000..4bb9f4d --- /dev/null +++ b/.idea/.idea.RTLTMPro.dir/.idea/projectSettingsUpdater.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.RTLTMPro.dir/.idea/workspace.xml b/.idea/.idea.RTLTMPro.dir/.idea/workspace.xml new file mode 100644 index 0000000..13be18f --- /dev/null +++ b/.idea/.idea.RTLTMPro.dir/.idea/workspace.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + 1681631661311 + + + + + + + + \ No newline at end of file diff --git a/Assets/.DS_Store b/Assets/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..32789495fd733dc94cd51e8ee632290de3191e0a GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8ZYV+y3OxqA7Hs`P@e*piDM(ZFpi&c4G#IlbY0aS&a@H5}Nqin> zcDJHLPl8C9f!S|5Kb!8CveRLV@y;Y{GiEc!1Sn#~g5?{*IBH2M##064YL8QP#!@DO zJR6m=$?+c=`YcPtVY}{(S@k+I}w7epOsEcdwUgqA|A5XH5 zpI+jpzLaq=xBcKe8s-Cg?MNnLKT3wFDu}`%q+DG@NhtG#&o*d zYBimm{r0TsOb@ou-rk$dEU~_^dDt5~#E*%5)?{+{-6>f$IENQ7O6Ll*+c<#liAkm4 zlb0s3Ozt2y-xTvmhyh}N7+63C%rz(K3wSm<5-~sw{Eh*<9~@9b*I=PhT^+Ef5dg3T zZY5yjEP*wSLDyiR5h5U5mjdciZbl5Q%fauMJl9~MQI|7rh7WF@%*}+t)ze{rN2N3F zYNVAIAO^lNfU_Tnjs5@l=lNeH(LxLm1B=N3uXVj{2hL`CYw48OYaP%VP!!B7G=7wT jp;|HIVk>TdDgnQP2B2%O& Date: Sun, 30 Jul 2023 11:38:02 +0300 Subject: [PATCH 4/6] Revert "Junk files" This reverts commit a6f6168aebe10c9a504992d560375cc9bfece33a. --- .DS_Store | Bin 6148 -> 0 bytes .../.idea.RTLTMPro.dir/.idea/indexLayout.xml | 8 --- .../.idea/projectSettingsUpdater.xml | 6 -- .idea/.idea.RTLTMPro.dir/.idea/workspace.xml | 65 ------------------ Assets/.DS_Store | Bin 6148 -> 0 bytes 5 files changed, 79 deletions(-) delete mode 100644 .DS_Store delete mode 100644 .idea/.idea.RTLTMPro.dir/.idea/indexLayout.xml delete mode 100644 .idea/.idea.RTLTMPro.dir/.idea/projectSettingsUpdater.xml delete mode 100644 .idea/.idea.RTLTMPro.dir/.idea/workspace.xml delete mode 100644 Assets/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 2373d60946bebbef8642bd67229aa50a415b5f3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5Z-O8CKMqDg&r5Y7EJv^@e*Tw0V8@)sfh_1jM>tp=1>Yb>kIiLK94iI zTcK1BUPQ`FnEj@+Gn?+0u#;hoaeo~57;_k77ARuFhT$8*dDI1I7*7+Bt2IhiL{%}2 zG8rvIljA=!fX{A~ov;F~gv~#{_h^`)wXVfM_C1BSdI%n99`qD z3n{Z`W{1&bnp6X4<5cElnC8hyC8TizAvafP9?Qy?<2)`@ZlEVD+qMTzXEND$-LBX> z>`l93a^YaOnn(`soRW2eGk61IZclM>pGEK=F<@@uB^c$I z%pbr%TMT1Jhyh}N7+7)!%#mlcmwcbJJz{_u_&o!7J_t}m&tR=l9UU;J767mXZY5x2 zFM&D2pl7hw2s0pDrvmC!Zdwek)4?xHoM*7ssM8rY%?CGk=B7j8>h7?PO@-2bZ}8i)a6U^yA!t$xt=VQ;3kF6 - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.RTLTMPro.dir/.idea/projectSettingsUpdater.xml b/.idea/.idea.RTLTMPro.dir/.idea/projectSettingsUpdater.xml deleted file mode 100644 index 4bb9f4d..0000000 --- a/.idea/.idea.RTLTMPro.dir/.idea/projectSettingsUpdater.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/.idea.RTLTMPro.dir/.idea/workspace.xml b/.idea/.idea.RTLTMPro.dir/.idea/workspace.xml deleted file mode 100644 index 13be18f..0000000 --- a/.idea/.idea.RTLTMPro.dir/.idea/workspace.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - 1681631661311 - - - - - - - - \ No newline at end of file diff --git a/Assets/.DS_Store b/Assets/.DS_Store deleted file mode 100644 index 32789495fd733dc94cd51e8ee632290de3191e0a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5Z-O8ZYV+y3OxqA7Hs`P@e*piDM(ZFpi&c4G#IlbY0aS&a@H5}Nqin> zcDJHLPl8C9f!S|5Kb!8CveRLV@y;Y{GiEc!1Sn#~g5?{*IBH2M##064YL8QP#!@DO zJR6m=$?+c=`YcPtVY}{(S@k+I}w7epOsEcdwUgqA|A5XH5 zpI+jpzLaq=xBcKe8s-Cg?MNnLKT3wFDu}`%q+DG@NhtG#&o*d zYBimm{r0TsOb@ou-rk$dEU~_^dDt5~#E*%5)?{+{-6>f$IENQ7O6Ll*+c<#liAkm4 zlb0s3Ozt2y-xTvmhyh}N7+63C%rz(K3wSm<5-~sw{Eh*<9~@9b*I=PhT^+Ef5dg3T zZY5yjEP*wSLDyiR5h5U5mjdciZbl5Q%fauMJl9~MQI|7rh7WF@%*}+t)ze{rN2N3F zYNVAIAO^lNfU_Tnjs5@l=lNeH(LxLm1B=N3uXVj{2hL`CYw48OYaP%VP!!B7G=7wT jp;|HIVk>TdDgnQP2B2%O& Date: Sun, 30 Jul 2023 11:40:56 +0300 Subject: [PATCH 5/6] Update to correct version --- Assets/RTLTMPro/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/RTLTMPro/package.json b/Assets/RTLTMPro/package.json index be79e13..d90bfd3 100644 --- a/Assets/RTLTMPro/package.json +++ b/Assets/RTLTMPro/package.json @@ -1,7 +1,7 @@ { "name": "com.pnarimani.rtltmpro", "displayName": "RTLTMPro", - "version": "1.0.0", + "version": "3.4.3", "description": "This plugin adds Right-to-left language support to \"TextMeshPro\" Unity plugin. Currently Arabic, Farsi and Hebrew are supported.", "author": "pnarimani", "unity": "2021.3", From 093e4177b49ff4c1eae72abd8c7cc5f157fe9061 Mon Sep 17 00:00:00 2001 From: Alon Talmi Date: Sun, 30 Jul 2023 15:45:37 +0300 Subject: [PATCH 6/6] Convert to RTLTMPro script --- .../Scripts/Editor/ConvertToTextMeshPro.cs | 235 ++++++++++++++++++ .../Editor/ConvertToTextMeshPro.cs.meta | 3 + 2 files changed, 238 insertions(+) create mode 100644 Assets/RTLTMPro/Scripts/Editor/ConvertToTextMeshPro.cs create mode 100644 Assets/RTLTMPro/Scripts/Editor/ConvertToTextMeshPro.cs.meta diff --git a/Assets/RTLTMPro/Scripts/Editor/ConvertToTextMeshPro.cs b/Assets/RTLTMPro/Scripts/Editor/ConvertToTextMeshPro.cs new file mode 100644 index 0000000..1c8c9db --- /dev/null +++ b/Assets/RTLTMPro/Scripts/Editor/ConvertToTextMeshPro.cs @@ -0,0 +1,235 @@ +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using TMPro; +using UnityEditor; +using UnityEngine; +using UnityEngine.UI; + +namespace RTLTMPro +{ + public class ConvertToTextMeshPro + { + [MenuItem("CONTEXT/Text/Convert to RTLTMPro")] + public static void ConvertLegacyText(MenuCommand command) + { + var text = (Text)command.context; + Convert(text); + } + + private static void Convert(Text from) + { + var gameObject = from.gameObject; + + var font = from.font; + var fontSize = from.fontSize; + var color = from.color; + var alignment = from.alignment; + var text = from.text; + var fontStyle = from.fontStyle; + var lineSpacing = from.lineSpacing; + var supportRichText = from.supportRichText; + var resizeTextMaxSize = from.resizeTextMaxSize; + var resizeTextMinSize = from.resizeTextMinSize; + var resizeTextForBestFit = from.resizeTextForBestFit; + var enabled = from.enabled; + var maskable = from.maskable; + var material = from.material; + var raycastTarget = from.raycastTarget; + var raycastPadding = from.raycastPadding; + + Undo.DestroyObjectImmediate(from); + var to = Undo.AddComponent(gameObject); + + EditorGUI.BeginChangeCheck(); + + to.text = text; + to.color = color; + to.alignment = alignment switch + { + TextAnchor.UpperLeft => TextAlignmentOptions.TopLeft, + TextAnchor.UpperCenter => TextAlignmentOptions.Top, + TextAnchor.UpperRight => TextAlignmentOptions.TopRight, + TextAnchor.MiddleLeft => TextAlignmentOptions.Left, + TextAnchor.MiddleCenter => TextAlignmentOptions.Center, + TextAnchor.MiddleRight => TextAlignmentOptions.Right, + TextAnchor.LowerLeft => TextAlignmentOptions.BottomLeft, + TextAnchor.LowerCenter => TextAlignmentOptions.Bottom, + TextAnchor.LowerRight => TextAlignmentOptions.BottomRight, + _ => throw new ArgumentOutOfRangeException() + }; + + var possibleFonts = AssetDatabase.FindAssets($"t:{nameof(TMP_FontAsset)}") + .Select(AssetDatabase.GUIDToAssetPath) + .Select(AssetDatabase.LoadAssetAtPath); + + bool IsMatchingFont(TMP_FontAsset f) + { + //We need to use reflection because the font property is null when population mode is set to static + const BindingFlags flags = BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic; + var fontSourceFile = typeof(TMP_FontAsset) + .GetField("m_SourceFontFile_EditorRef", flags) + !.GetValue(f) as Font; + + return fontSourceFile == font; + } + + to.font = possibleFonts.FirstOrDefault(IsMatchingFont); + to.fontSize = fontSize; + + to.fontStyle = fontStyle switch + { + FontStyle.Normal => FontStyles.Normal, + FontStyle.Bold => FontStyles.Bold, + FontStyle.Italic => FontStyles.Italic, + FontStyle.BoldAndItalic => FontStyles.Bold | FontStyles.Italic, + _ => throw new ArgumentOutOfRangeException() + }; + + to.lineSpacing = lineSpacing; + to.richText = supportRichText; + to.fontSizeMax = resizeTextMaxSize; + to.fontSizeMin = resizeTextMinSize; + to.enableAutoSizing = resizeTextForBestFit; + to.enabled = enabled; + to.maskable = maskable; + to.material = material; + to.raycastTarget = raycastTarget; + to.raycastPadding = raycastPadding; + + if (EditorGUI.EndChangeCheck()) + Undo.RecordObject(to, "Copy from old text"); + } + + [MenuItem("CONTEXT/TextMeshProUGUI/Convert to RTLTMPro", true)] + public static bool ConvertTextMeshProUGUIValidate(MenuCommand command) + => command.context is TextMeshProUGUI and not RTLTextMeshPro; + + [MenuItem("CONTEXT/TextMeshProUGUI/Convert to RTLTMPro")] + public static void ConvertTextMeshProUGUI(MenuCommand command) + { + var text = (TextMeshProUGUI)command.context; + Convert(text); + } + + /// + /// Unfortunately I'm not sure how to do GUID swapping, so references to the text component will break, but at least it should make the transition much safer and quicker + /// + /// + private static void Convert(TextMeshProUGUI from) + { + var gameObject = from.gameObject; + + var margins = from.margin; + var textPreprocessor = from.textPreprocessor; + var text = from.text; + var autoSizeTextContainer = from.autoSizeTextContainer; + var font = from.font; + var color = from.color; + var alignment = from.alignment; + var fontStyle = from.fontStyle; + var lineSpacing = from.lineSpacing; + var richText = from.richText; + var fontSize = from.fontSize; + var fontSizeMax = from.fontSizeMax; + var fontSizeMin = from.fontSizeMin; + var enableAutoSizing = from.enableAutoSizing; + var enabled = from.enabled; + var maskable = from.maskable; + var raycastTarget = from.raycastTarget; + var raycastPadding = from.raycastPadding; + var fontSharedMaterial = from.fontSharedMaterial; + var fontSharedMaterials = from.fontSharedMaterials; + var enableVertexGradient = from.enableVertexGradient; + var colorGradient = from.colorGradient; + var colorGradientPreset = from.colorGradientPreset; + var spriteAsset = from.spriteAsset; + var tintAllSprites = from.tintAllSprites; + var styleSheet = from.styleSheet; + var textStyle = from.textStyle; + var overrideColorTags = from.overrideColorTags; + var fontWeight = from.fontWeight; + var characterSpacing = from.characterSpacing; + var wordSpacing = from.wordSpacing; + var lineSpacingAdjustment = from.lineSpacingAdjustment; + var paragraphSpacing = from.paragraphSpacing; + var characterWidthAdjustment = from.characterWidthAdjustment; + var enableWordWrapping = from.enableWordWrapping; + var wordWrappingRatios = from.wordWrappingRatios; + var overflowMode = from.overflowMode; + var linkedTextComponent = from.linkedTextComponent; + + Undo.DestroyObjectImmediate(from); + var to = Undo.AddComponent(gameObject); + + EditorGUI.BeginChangeCheck(); + + to.UpdateText(); + + //Initialize the canvas renderer + _ = to.canvasRenderer; + + //Initialize the mesh using reflection + var mesh = new Mesh + { + hideFlags = HideFlags.HideAndDontSave, + name = "TextMeshPro UI Mesh" + }; + + typeof(TMP_Text) + .GetField("m_mesh", BindingFlags.Instance | BindingFlags.SetField | BindingFlags.NonPublic) + !.SetValue(to, mesh); + + to.GetTextInfo(to.text); + // rtlText.UpdateFontAsset(); + // rtlText.UpdateVertexData(); + _ = to.GetPreferredValues(); + + + + to.margin = margins; + to.fontSharedMaterials = fontSharedMaterials; + to.fontSharedMaterial = fontSharedMaterial; + to.textPreprocessor = textPreprocessor; + to.text = text; + to.autoSizeTextContainer = autoSizeTextContainer; + to.font = font; + to.color = color; + to.alignment = alignment; + to.fontStyle = fontStyle; + to.lineSpacing = lineSpacing; + to.richText = richText; + to.fontSize = fontSize; + to.fontSizeMax = fontSizeMax; + to.fontSizeMin = fontSizeMin; + to.enableAutoSizing = enableAutoSizing; + to.enabled = enabled; + to.maskable = maskable; + to.raycastTarget = raycastTarget; + to.raycastPadding = raycastPadding; + to.enableVertexGradient = enableVertexGradient; + to.colorGradient = colorGradient; + to.colorGradientPreset = colorGradientPreset; + to.spriteAsset = spriteAsset; + to.tintAllSprites = tintAllSprites; + to.styleSheet = styleSheet; + to.textStyle = textStyle; + to.overrideColorTags = overrideColorTags; + to.fontWeight = fontWeight; + to.characterSpacing = characterSpacing; + to.wordSpacing = wordSpacing; + to.lineSpacingAdjustment = lineSpacingAdjustment; + to.paragraphSpacing = paragraphSpacing; + to.characterWidthAdjustment = characterWidthAdjustment; + to.enableWordWrapping = enableWordWrapping; + to.wordWrappingRatios = wordWrappingRatios; + to.overflowMode = overflowMode; + to.linkedTextComponent = linkedTextComponent; + + + if (EditorGUI.EndChangeCheck()) + Undo.RecordObject(to, "Copy from old text"); + } + } +} \ No newline at end of file diff --git a/Assets/RTLTMPro/Scripts/Editor/ConvertToTextMeshPro.cs.meta b/Assets/RTLTMPro/Scripts/Editor/ConvertToTextMeshPro.cs.meta new file mode 100644 index 0000000..19fcc56 --- /dev/null +++ b/Assets/RTLTMPro/Scripts/Editor/ConvertToTextMeshPro.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1c4843c8b5f8430f94949fce71b4d40e +timeCreated: 1690706979 \ No newline at end of file