diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b13ed9..4b9a4d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ # Changelog These are the release notes for the TextMesh Pro UPM package which was first introduced with Unity 2018.1. Please see the following link for the Release Notes for prior versions of TextMesh Pro. http://digitalnativestudios.com/forum/index.php?topic=1363.0 +## [1.5.5] - 2021-04-02 +## [2.1.5] +## [3.0.5] +### Changes +- Added compiler conditional to address error related to missing RectMask2D padding property which was added in Unity 2019.4.12f1. See [forum post](https://forum.unity.com/threads/update-textmesh-pro-to-latest-in-2019-4.945332/#post-6906851) for details. +- Fixed GetPreferredValues(string text) and GetPreferredValues(string text, float width, float height) incorrectly changing the text. See [forum post](https://forum.unity.com/threads/preferred-width-height-sometimes-0.980022/#post-6991058) for details. +- Fixed potential crash when FontEngine.GetGlyphIndex is called on a font asset that was previously unloaded or deleted. See [forum post](https://forum.unity.com/threads/tmpro-tmp_fontasset-addsynthesizedcharacter-causes-crash-when-calling-fontengine-getglyphindex.1071452/) for details. +- Fixed potential crash when trying to add new glyphs to a dynamic font asset whose atlas texture is set to non readable. Case #1319567 +- Fixed Format Exception error when using the Project Text Spacing Conversion Tool when the Language Region Format is not English. Case #1320544 +- Fixed text rendering issue due to incorrectly SDF scaling when using a CanvasScaler and resizing the game view. +- Fixed TextMeshPro component Sorting Layer field in the Inspector's Extra Settings not showing the correct layer. Case #1326985 + ## [1.5.4] - 2021-02-19 ## [2.1.4] ## [3.0.4] diff --git a/Scripts/Editor/TMP_EditorPanel.cs b/Scripts/Editor/TMP_EditorPanel.cs index 5b3a404..4c4560a 100644 --- a/Scripts/Editor/TMP_EditorPanel.cs +++ b/Scripts/Editor/TMP_EditorPanel.cs @@ -111,12 +111,14 @@ private void DrawSortingLayer() EditorGUI.BeginProperty(rect, k_SortingLayerLabel, sortingLayerIDProp); EditorGUI.BeginChangeCheck(); - int newLayerIndex = EditorGUI.Popup(rect, k_SortingLayerLabel, sortingLayerProp.intValue, k_SortingLayerNames); + + int currentLayerIndex = SortingLayerHelper.GetSortingLayerIndexFromSortingLayerID(sortingLayerIDProp.intValue); + int newLayerIndex = EditorGUI.Popup(rect, k_SortingLayerLabel, currentLayerIndex, k_SortingLayerNames); if (EditorGUI.EndChangeCheck()) { - sortingLayerProp.intValue = newLayerIndex; sortingLayerIDProp.intValue = SortingLayer.NameToID(k_SortingLayerNames[newLayerIndex]); + sortingLayerProp.intValue = SortingLayer.GetLayerValueFromName(k_SortingLayerNames[newLayerIndex]); m_HavePropertiesChanged = true; // Sync Sorting Layer ID change on potential sub text object. diff --git a/Scripts/Editor/TMP_PackageUtilities.cs b/Scripts/Editor/TMP_PackageUtilities.cs index 29a2ce2..b386766 100644 --- a/Scripts/Editor/TMP_PackageUtilities.cs +++ b/Scripts/Editor/TMP_PackageUtilities.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Collections; using System.Collections.Generic; +using System.Globalization; using System.Threading; using TMPro.EditorUtilities; @@ -413,7 +414,7 @@ static void ScanProjectFile(AssetFileRecord fileRecord) { if (line.Contains(k_FontSizeProperty)) { - fontSize = float.Parse(line.Split(':')[1]); + fontSize = float.Parse(line.Split(':')[1], NumberStyles.Float, CultureInfo.InvariantCulture); readingFlag = 3; continue; } @@ -425,7 +426,7 @@ static void ScanProjectFile(AssetFileRecord fileRecord) // Read character spacing if (line.Contains(k_CharacterSpacingProperty)) { - characterSpacingValue = float.Parse(line.Split(':')[1]); + characterSpacingValue = float.Parse(line.Split(':')[1], NumberStyles.Float, CultureInfo.InvariantCulture); if (characterSpacingValue != 0) { // Convert character spacing value. @@ -441,7 +442,7 @@ static void ScanProjectFile(AssetFileRecord fileRecord) if (line.Contains(k_WordSpacingProperty)) { // Get the character spacing value - wordSpacingValue = float.Parse(line.Split(':')[1]); + wordSpacingValue = float.Parse(line.Split(':')[1], NumberStyles.Float, CultureInfo.InvariantCulture); if (wordSpacingValue != 0) { // Convert character spacing value. @@ -457,7 +458,7 @@ static void ScanProjectFile(AssetFileRecord fileRecord) if (line.Contains(k_LineSpacingProperty)) { // Get the value of line spacing value - lineSpacingValue = float.Parse(line.Split(':')[1]); + lineSpacingValue = float.Parse(line.Split(':')[1], NumberStyles.Float, CultureInfo.InvariantCulture); if (lineSpacingValue != 0) { // Convert line spacing value. @@ -473,7 +474,7 @@ static void ScanProjectFile(AssetFileRecord fileRecord) if (line.Contains(k_ParagraphSpacingProperty)) { // Get the value of line spacing value - paragraphSpacingValue = float.Parse(line.Split(':')[1]); + paragraphSpacingValue = float.Parse(line.Split(':')[1], NumberStyles.Float, CultureInfo.InvariantCulture); if (paragraphSpacingValue != 0) { // Convert line spacing value. diff --git a/Scripts/Editor/TMPro_SortingLayerHelper.cs b/Scripts/Editor/TMPro_SortingLayerHelper.cs index c36f9f8..8ef1b2b 100644 --- a/Scripts/Editor/TMPro_SortingLayerHelper.cs +++ b/Scripts/Editor/TMPro_SortingLayerHelper.cs @@ -28,5 +28,31 @@ static string[] GetSortingLayerNames() return layerNames; } + + internal static int GetSortingLayerIndexFromValue(int value) + { + int layerCount = SortingLayer.layers.Length; + + for (int i = 0; i < layerCount; i++) + { + if (value == SortingLayer.layers[i].value) + return i; + } + + return -1; + } + + internal static int GetSortingLayerIndexFromSortingLayerID(int id) + { + int layerCount = SortingLayer.layers.Length; + + for (int i = 0; i < layerCount; i++) + { + if (id == SortingLayer.layers[i].id) + return i; + } + + return -1; + } } } diff --git a/Scripts/Editor/TMPro_TexturePostProcessor.cs b/Scripts/Editor/TMPro_TexturePostProcessor.cs index 6f5480c..51d6297 100644 --- a/Scripts/Editor/TMPro_TexturePostProcessor.cs +++ b/Scripts/Editor/TMPro_TexturePostProcessor.cs @@ -1,7 +1,6 @@ using System; using UnityEngine; using UnityEditor; -using System.Collections; namespace TMPro.EditorUtilities @@ -10,7 +9,7 @@ namespace TMPro.EditorUtilities /// Asset post processor used to handle text assets changes. /// This includes tracking of changes to textures used by sprite assets as well as font assets potentially getting updated outside of the Unity editor. /// - public class TMPro_TexturePostProcessor : AssetPostprocessor + internal class TMPro_TexturePostProcessor : AssetPostprocessor { private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { @@ -20,72 +19,28 @@ private static void OnPostprocessAllAssets(string[] importedAssets, string[] del if (asset.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase) == false) continue; - if (AssetDatabase.GetMainAssetTypeAtPath(asset) == typeof(TMP_FontAsset)) + Type assetType = AssetDatabase.GetMainAssetTypeAtPath(asset); + + if (assetType == typeof(TMP_FontAsset)) { TMP_FontAsset fontAsset = AssetDatabase.LoadAssetAtPath(asset, typeof(TMP_FontAsset)) as TMP_FontAsset; - if (fontAsset != null) + // Only refresh font asset definition if font asset was previously initialized. + if (fontAsset != null && fontAsset.m_CharacterLookupDictionary != null) TMP_EditorResourceManager.RegisterFontAssetForDefinitionRefresh(fontAsset); } - if (AssetDatabase.GetMainAssetTypeAtPath(asset) == typeof(Texture2D)) + if (assetType == typeof(Texture2D)) { Texture2D tex = AssetDatabase.LoadAssetAtPath(asset, typeof(Texture2D)) as Texture2D; - if (tex != null) - TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, tex); + if (tex == null) + continue; + + TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, tex); + Resources.UnloadAsset(tex); } } } } - - //public class TMPro_PackageImportPostProcessor : AssetPostprocessor - //{ - // static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) - // { - // for (int i = 0; i < importedAssets.Length; i++) - // { - // if (importedAssets[i].Contains("TextMesh Pro/Resources/TMP Settings.asset")) - // { - // Debug.Log("New TMP Settings file was just imported."); - - // // TMP Settings file was just re-imported. - // // Check if project already contains - // } - - - // if (importedAssets[i].Contains("com.unity.TextMeshPro/Examples")) - // { - // //Debug.Log("New TMP Examples folder was just imported."); - // } - - // //Debug.Log("[" + importedAssets[i] + "] was just imported."); - // } - - - - // //for (int i = 0; i < deletedAssets.Length; i++) - // //{ - // // if (deletedAssets[i] == "Assets/TextMesh Pro") - // // { - // // //Debug.Log("Asset [" + deletedAssets[i] + "] has been deleted."); - // // string currentBuildSettings = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup); - - // // //Check for and inject TMP_PRESENT - // // if (currentBuildSettings.Contains("TMP_PRESENT;")) - // // { - // // currentBuildSettings = currentBuildSettings.Replace("TMP_PRESENT;", ""); - - // // PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currentBuildSettings); - // // } - // // else if (currentBuildSettings.Contains("TMP_PRESENT")) - // // { - // // currentBuildSettings = currentBuildSettings.Replace("TMP_PRESENT", ""); - - // // PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currentBuildSettings); - // // } - // // } - // //} - // } - //} } diff --git a/Scripts/Runtime/TMP_DefaultControls.cs b/Scripts/Runtime/TMP_DefaultControls.cs index d3acdda..7d770a8 100644 --- a/Scripts/Runtime/TMP_DefaultControls.cs +++ b/Scripts/Runtime/TMP_DefaultControls.cs @@ -184,7 +184,7 @@ public static GameObject CreateInputField(Resources resources) // Use UI.Mask for Unity 5.0 - 5.1 and 2D RectMask for Unity 5.2 and up RectMask2D rectMask = textArea.AddComponent(); - #if UNITY_2019_4_OR_NEWER + #if UNITY_2019_4_OR_NEWER && !UNITY_2019_4_1 && !UNITY_2019_4_2 && !UNITY_2019_4_3 && !UNITY_2019_4_4 && !UNITY_2019_4_5 && !UNITY_2019_4_6 && !UNITY_2019_4_7 && !UNITY_2019_4_8 && !UNITY_2019_4_9 && !UNITY_2019_4_10 && !UNITY_2019_4_11 rectMask.padding = new Vector4(-8, -5, -8, -5); #endif diff --git a/Scripts/Runtime/TMP_FontAsset.cs b/Scripts/Runtime/TMP_FontAsset.cs index 326486f..582b1f8 100644 --- a/Scripts/Runtime/TMP_FontAsset.cs +++ b/Scripts/Runtime/TMP_FontAsset.cs @@ -540,114 +540,6 @@ public static TMP_FontAsset CreateFontAsset(Font font, int samplingPointSize, in } - /* - /// - /// Create new font asset using default settings from path to source font file. - /// - /// Path to source font file. - /// - public static TMP_FontAsset CreateFontAsset(string fontFilePath) - { - return CreateFontAsset(fontFilePath, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, AtlasPopulationMode.Dynamic); - } - - public static TMP_FontAsset CreateFontAsset(string fontFilePath, int samplingPointSize, int atlasPadding, GlyphRenderMode renderMode, int atlasWidth, int atlasHeight, AtlasPopulationMode atlasPopulationMode = AtlasPopulationMode.Dynamic, bool enableMultiAtlasSupport = true) - { - // Initialize FontEngine - FontEngine.InitializeFontEngine(); - - // Load Font Face - if (FontEngine.LoadFontFace(fontFilePath, samplingPointSize) != FontEngineError.Success) - { - //Debug.LogWarning("Unable to load font face for [" + font.name + "]. Make sure \"Include Font Data\" is enabled in the Font Import Settings.", font); - return null; - } - - // Create new font asset - TMP_FontAsset fontAsset = ScriptableObject.CreateInstance(); - - fontAsset.m_Version = "1.1.0"; - fontAsset.faceInfo = FontEngine.GetFaceInfo(); - - // Set font reference and GUID - if (atlasPopulationMode == AtlasPopulationMode.Dynamic) - fontAsset.sourceFontFile = font; - - // Set persistent reference to source font file in the Editor only. - #if UNITY_EDITOR - string guid; - long localID; - - UnityEditor.AssetDatabase.TryGetGUIDAndLocalFileIdentifier(font, out guid, out localID); - fontAsset.m_SourceFontFileGUID = guid; - fontAsset.m_SourceFontFile_EditorRef = font; - #endif - - fontAsset.atlasPopulationMode = atlasPopulationMode; - - fontAsset.atlasWidth = atlasWidth; - fontAsset.atlasHeight = atlasHeight; - fontAsset.atlasPadding = atlasPadding; - fontAsset.atlasRenderMode = renderMode; - - // Initialize array for the font atlas textures. - fontAsset.atlasTextures = new Texture2D[1]; - - // Create and add font atlas texture. - Texture2D texture = new Texture2D(0, 0, TextureFormat.Alpha8, false); - - //texture.name = assetName + " Atlas"; - fontAsset.atlasTextures[0] = texture; - - fontAsset.isMultiAtlasTexturesEnabled = enableMultiAtlasSupport; - - // Add free rectangle of the size of the texture. - int packingModifier; - if (((GlyphRasterModes)renderMode & GlyphRasterModes.RASTER_MODE_BITMAP) == GlyphRasterModes.RASTER_MODE_BITMAP) - { - packingModifier = 0; - - // Optimize by adding static ref to shader. - Material tmp_material = new Material(ShaderUtilities.ShaderRef_MobileBitmap); - - //tmp_material.name = texture.name + " Material"; - tmp_material.SetTexture(ShaderUtilities.ID_MainTex, texture); - tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, atlasWidth); - tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, atlasHeight); - - fontAsset.material = tmp_material; - } - else - { - packingModifier = 1; - - // Optimize by adding static ref to shader. - Material tmp_material = new Material(ShaderUtilities.ShaderRef_MobileSDF); - - //tmp_material.name = texture.name + " Material"; - tmp_material.SetTexture(ShaderUtilities.ID_MainTex, texture); - tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, atlasWidth); - tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, atlasHeight); - - tmp_material.SetFloat(ShaderUtilities.ID_GradientScale, atlasPadding + packingModifier); - - tmp_material.SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle); - tmp_material.SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle); - - fontAsset.material = tmp_material; - } - - fontAsset.freeGlyphRects = new List(8) { new GlyphRect(0, 0, atlasWidth - packingModifier, atlasHeight - packingModifier) }; - fontAsset.usedGlyphRects = new List(8); - - // TODO: Consider adding support for extracting glyph positioning data - - fontAsset.ReadFontAssetDefinition(); - - return fontAsset; - } - */ - void Awake() { // Check version number of font asset to see if it needs to be upgraded. @@ -829,47 +721,49 @@ internal void AddSynthesizedCharactersAndFaceMetrics() { k_AddSynthesizedCharactersMarker.Begin(); + bool isFontFaceLoaded = false; + if (m_AtlasPopulationMode == AtlasPopulationMode.Dynamic) - FontEngine.LoadFontFace(sourceFontFile, m_FaceInfo.pointSize); + isFontFaceLoaded = FontEngine.LoadFontFace(sourceFontFile, m_FaceInfo.pointSize) == FontEngineError.Success; // Only characters not present in the source font file will be synthesized. // Non visible and control characters with no metrics // Add End of Text \u0003 - AddSynthesizedCharacter(0x03, true); + AddSynthesizedCharacter(0x03, isFontFaceLoaded, true); // Add Tab \u0009 - AddSynthesizedCharacter(0x09, true); + AddSynthesizedCharacter(0x09, isFontFaceLoaded, true); // Add Line Feed (LF) \u000A - AddSynthesizedCharacter(0x0A); + AddSynthesizedCharacter(0x0A, isFontFaceLoaded); // Add Vertical Tab (VT) \u000B - AddSynthesizedCharacter(0x0B); + AddSynthesizedCharacter(0x0B, isFontFaceLoaded); // Add Carriage Return (CR) \u000D - AddSynthesizedCharacter(0x0D); + AddSynthesizedCharacter(0x0D, isFontFaceLoaded); // Add Arabic Letter Mark \u061C - AddSynthesizedCharacter(0x061C); + AddSynthesizedCharacter(0x061C, isFontFaceLoaded); // Add Zero Width Space \u2000B - AddSynthesizedCharacter(0x200B); + AddSynthesizedCharacter(0x200B, isFontFaceLoaded); // Add Left-To-Right Mark \u200E - AddSynthesizedCharacter(0x200E); + AddSynthesizedCharacter(0x200E, isFontFaceLoaded); // Add Right-To-Left Mark \u200F - AddSynthesizedCharacter(0x200F); + AddSynthesizedCharacter(0x200F, isFontFaceLoaded); // Add Line Separator \u2028 - AddSynthesizedCharacter(0x2028); + AddSynthesizedCharacter(0x2028, isFontFaceLoaded); // Add Paragraph Separator \u2029 - AddSynthesizedCharacter(0x2029); + AddSynthesizedCharacter(0x2029, isFontFaceLoaded); // Add Word Joiner / Zero Width Non-Breaking Space \u2060 - AddSynthesizedCharacter(0x2060); + AddSynthesizedCharacter(0x2060, isFontFaceLoaded); // Set Cap Line using the capital letter 'X' if (m_FaceInfo.capLine == 0 && m_CharacterLookupDictionary.ContainsKey('X')) @@ -888,7 +782,7 @@ internal void AddSynthesizedCharactersAndFaceMetrics() k_AddSynthesizedCharactersMarker.End(); } - void AddSynthesizedCharacter(uint unicode, bool addImmediately = false) + void AddSynthesizedCharacter(uint unicode, bool isFontFaceLoaded, bool addImmediately = false) { // Check if unicode is already present in the font asset if (m_CharacterLookupDictionary.ContainsKey(unicode)) @@ -896,7 +790,7 @@ void AddSynthesizedCharacter(uint unicode, bool addImmediately = false) Glyph glyph; - if (m_AtlasPopulationMode == AtlasPopulationMode.Dynamic) + if (isFontFaceLoaded) { // Check if unicode is present in font file if (FontEngine.GetGlyphIndex(unicode) != 0) @@ -2165,18 +2059,18 @@ internal bool TryAddCharacterInternal(uint unicode, out TMP_Character character) // } //} - // Resize the Atlas Texture to the appropriate size - if (m_AtlasTextures[m_AtlasTextureIndex].width == 0 || m_AtlasTextures[m_AtlasTextureIndex].height == 0) + // Make sure atlas texture is readable. + if (m_AtlasTextures[m_AtlasTextureIndex].isReadable == false) { - // TODO: Need texture to be readable. - if (m_AtlasTextures[m_AtlasTextureIndex].isReadable == false) - { - Debug.LogWarning("Unable to add the requested character to font asset [" + this.name + "]'s atlas texture. Please make the texture [" + m_AtlasTextures[m_AtlasTextureIndex].name + "] readable.", m_AtlasTextures[m_AtlasTextureIndex]); + Debug.LogWarning("Unable to add the requested character to font asset [" + this.name + "]'s atlas texture. Please make the texture [" + m_AtlasTextures[m_AtlasTextureIndex].name + "] readable.", m_AtlasTextures[m_AtlasTextureIndex]); - k_TryAddCharacterMarker.End(); - return false; - } + k_TryAddCharacterMarker.End(); + return false; + } + // Resize the Atlas Texture to the appropriate size + if (m_AtlasTextures[m_AtlasTextureIndex].width == 0 || m_AtlasTextures[m_AtlasTextureIndex].height == 0) + { m_AtlasTextures[m_AtlasTextureIndex].Resize(m_AtlasWidth, m_AtlasHeight); FontEngine.ResetAtlasTexture(m_AtlasTextures[m_AtlasTextureIndex]); } diff --git a/Scripts/Runtime/TMP_InputField.cs b/Scripts/Runtime/TMP_InputField.cs index 2f7dc05..f52aca4 100644 --- a/Scripts/Runtime/TMP_InputField.cs +++ b/Scripts/Runtime/TMP_InputField.cs @@ -1349,8 +1349,8 @@ static string clipboard private bool InPlaceEditing() { - if (m_TouchKeyboardAllowsInPlaceEditing || (TouchScreenKeyboard.isSupported && (Application.platform == RuntimePlatform.WSAPlayerX86 || Application.platform == RuntimePlatform.WSAPlayerX64 || Application.platform == RuntimePlatform.WSAPlayerARM))) - return true; + if (Application.platform == RuntimePlatform.WSAPlayerX86 || Application.platform == RuntimePlatform.WSAPlayerX64 || Application.platform == RuntimePlatform.WSAPlayerARM) + return !TouchScreenKeyboard.isSupported || m_TouchKeyboardAllowsInPlaceEditing; if (TouchScreenKeyboard.isSupported && shouldHideSoftKeyboard) return true; diff --git a/Scripts/Runtime/TMP_Text.cs b/Scripts/Runtime/TMP_Text.cs index 0300b1f..f96141c 100644 --- a/Scripts/Runtime/TMP_Text.cs +++ b/Scripts/Runtime/TMP_Text.cs @@ -1742,31 +1742,6 @@ protected virtual float GetPaddingForMaterial(Material mat) public virtual void ForceMeshUpdate(bool ignoreActiveState = false, bool forceTextReparsing = false) { } - /// - /// Method used for resetting vertex layout when switching to and from Volumetric Text mode. - /// - /// - //protected virtual void ResetVertexLayout() { } - - - /// - /// Internal function used by the Text Input Field to populate TMP_TextInfo data. - /// - internal void SetTextInternal(string text) - { - m_text = text; - m_renderMode = TextRenderFlags.DontRender; - ForceMeshUpdate(); - m_renderMode = TextRenderFlags.Render; - } - - /// - /// Function to force the regeneration of the text object. - /// - /// Flags to control which portions of the geometry gets uploaded. - //public virtual void ForceMeshUpdate(TMP_VertexDataUpdateFlags flags) { } - - /// /// Function to update the geometry of the main and sub text objects. /// @@ -2058,44 +2033,6 @@ void PopulateTextBackingArray(char[] sourceText, int start, int length) m_TextBackingArray.Count = writeIndex; } - /// - /// Convert source text to Unicode (uint) and populate internal text backing array. - /// - /// int array containing the source text to be converted - /// Index of the first element of the source array to be converted and copied to the internal text backing array. - /// Number of elements in the array to be converted and copied to the internal text backing array. - void PopulateTextBackingArray(int[] sourceText, int start, int length) - { - int readIndex; - int writeIndex = 0; - - // Range check - if (sourceText == null) - { - readIndex = 0; - length = 0; - } - else - { - readIndex = Mathf.Clamp(start, 0, sourceText.Length); - length = Mathf.Clamp(length, 0, start + length < sourceText.Length ? length : sourceText.Length - start); - } - - // Make sure array size is appropriate - if (length >= m_TextBackingArray.Capacity) - m_TextBackingArray.Resize((length)); - - int end = readIndex + length; - for (; readIndex < end; readIndex++) - { - m_TextBackingArray[writeIndex] = (uint)sourceText[readIndex]; - writeIndex += 1; - } - - // Terminate array with zero as we are not clearing the array on new invocation of this function. - m_TextBackingArray[writeIndex] = 0; - } - /// /// /// @@ -2330,6 +2267,25 @@ void PopulateTextProcessingArray() m_InternalTextProcessingArraySize = writeIndex; } + /// + /// Function used in conjunction with GetPreferredValues + /// + /// + void SetTextInternal(string sourceText) + { + int srcLength = sourceText == null ? 0 : sourceText.Length; + + PopulateTextBackingArray(sourceText, 0, srcLength); + + // Set input source + TextInputSources currentInputSource = m_inputSource; + m_inputSource = TextInputSources.TextString; + + PopulateTextProcessingArray(); + + m_inputSource = currentInputSource; + } + /// /// This function is the same as using the text property to set the text. /// @@ -3734,7 +3690,7 @@ public Vector2 GetPreferredValues(string text) { m_isCalculatingPreferredValues = true; - SetText(text); + SetTextInternal(text); SetArraySizes(m_TextProcessingArray); Vector2 margin = k_LargePositiveVector2; @@ -3758,7 +3714,7 @@ public Vector2 GetPreferredValues(string text, float width, float height) { m_isCalculatingPreferredValues = true; - SetText(text); + SetTextInternal(text); SetArraySizes(m_TextProcessingArray); Vector2 margin = new Vector2(width, height); diff --git a/Scripts/Runtime/TMPro_UGUI_Private.cs b/Scripts/Runtime/TMPro_UGUI_Private.cs index 0e8833f..2cbe5ef 100644 --- a/Scripts/Runtime/TMPro_UGUI_Private.cs +++ b/Scripts/Runtime/TMPro_UGUI_Private.cs @@ -23,6 +23,7 @@ public partial class TextMeshProUGUI private Vector3[] m_RectTransformCorners = new Vector3[4]; private CanvasRenderer m_canvasRenderer; private Canvas m_canvas; + private float m_CanvasScaleFactor; private bool m_isFirstAllocation; // Flag to determine if this is the first allocation of the buffers. @@ -1553,8 +1554,17 @@ protected override void OnRectTransformDimensionsChange() if (!this.gameObject.activeInHierarchy) return; + // Check if Canvas scale factor has changed as this requires an update of the SDF Scale. + bool hasCanvasScaleFactorChanged = false; + if (m_canvas != null && m_CanvasScaleFactor != m_canvas.scaleFactor) + { + m_CanvasScaleFactor = m_canvas.scaleFactor; + hasCanvasScaleFactorChanged = true; + } + // Ignore changes to RectTransform SizeDelta that are very small and typically the result of rounding errors when using RectTransform in Anchor Stretch mode. - if (rectTransform != null && + if (hasCanvasScaleFactorChanged == false && + rectTransform != null && Mathf.Abs(m_rectTransform.rect.width - m_PreviousRectTransformSize.x) < 0.0001f && Mathf.Abs(m_rectTransform.rect.height - m_PreviousRectTransformSize.y) < 0.0001f && Mathf.Abs(m_rectTransform.pivot.x - m_PreviousPivotPosition.x) < 0.0001f && Mathf.Abs(m_rectTransform.pivot.y - m_PreviousPivotPosition.y) < 0.0001f) { diff --git a/ValidationExceptions.json b/ValidationExceptions.json new file mode 100644 index 0000000..1631092 --- /dev/null +++ b/ValidationExceptions.json @@ -0,0 +1,9 @@ +{ + "ErrorExceptions": + [ + { + "ValidationTest": "API Validation", + "PackageVersion": "1.5.5" + } + ] +} \ No newline at end of file diff --git a/ValidationExceptions.json.meta b/ValidationExceptions.json.meta new file mode 100644 index 0000000..91e0542 --- /dev/null +++ b/ValidationExceptions.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c5aeade3b36c0b246936762b3673d9bf +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index 1d4efec..9933a92 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "com.unity.textmeshpro", "displayName": "TextMeshPro", - "version": "1.5.4", - "unity": "2018.3", + "version": "1.5.5", + "unity": "2018.4", "description": "TextMeshPro is the ultimate text solution for Unity. It's the perfect replacement for Unity's UI Text and the legacy Text Mesh.\n\nPowerful and easy to use, TextMeshPro (also known as TMP) uses Advanced Text Rendering techniques along with a set of custom shaders; delivering substantial visual quality improvements while giving users incredible flexibility when it comes to text styling and texturing.\n\nTextMeshPro provides Improved Control over text formatting and layout with features like character, word, line and paragraph spacing, kerning, justified text, Links, over 30 Rich Text Tags available, support for Multi Font & Sprites, Custom Styles and more.\n\nGreat performance. Since the geometry created by TextMeshPro uses two triangles per character just like Unity's text components, this improved visual quality and flexibility comes at no additional performance cost.", "keywords": [ "TextMeshPro", @@ -15,9 +15,9 @@ "repository": { "url": "https://github.cds.internal.unity3d.com/unity/com.unity.textmeshpro.git", "type": "git", - "revision": "3823ba08e13befd244d498c936552ad7a509985c" + "revision": "e1c33d4a2d4ae82d0e2fc1b4c3ad87da2e60642e" }, "upmCi": { - "footprint": "f6107a8653d916f9b584ca30a3de00db2376c0aa" + "footprint": "3695e1f1fa69f38e1cc55ddc5209ed2e156f6d1c" } }