Skip to content

Commit

Permalink
com.unity.textmeshpro@3.2.0-pre.8
Browse files Browse the repository at this point in the history
## [3.2.0-pre.8] - 2024-01-30
### Changes
- Fix Dropdown creation causing a crash after undoing.
- Addressed issue surrounding dropdown not closing correctly in certain situations
- Resolves issue in editor where a null mesh may be set with still present submesh data, not having the canvas update.
- Ensure enabling and disabling Canvases does not cause a regeneration of the text.
- Fixed un-detected sprite asset changes after adding new sprites.
- Ensure Kerning is not applied to Sprites
  • Loading branch information
Unity Technologies committed Jan 30, 2024
1 parent aee719b commit 067fd10
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 48 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# 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

## [3.2.0-pre.8] - 2024-01-30
### Changes
- Fix Dropdown creation causing a crash after undoing.
- Addressed issue surrounding dropdown not closing correctly in certain situations
- Resolves issue in editor where a null mesh may be set with still present submesh data, not having the canvas update.
- Ensure enabling and disabling Canvases does not cause a regeneration of the text.
- Fixed un-detected sprite asset changes after adding new sprites.
- Ensure Kerning is not applied to Sprites

## [3.2.0-pre.7] - 2023-12-17
### Changes
Expand Down
1 change: 1 addition & 0 deletions Scripts/Editor/TMP_SpriteAssetMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ internal static void UpdateSpriteAsset(TMP_SpriteAsset spriteAsset)
spriteAsset.SortGlyphTable();
spriteAsset.UpdateLookupTables();
TMPro_EventManager.ON_SPRITE_ASSET_PROPERTY_CHANGED(true, spriteAsset);
EditorUtility.SetDirty(spriteAsset);

}

Expand Down
84 changes: 52 additions & 32 deletions Scripts/Runtime/TMP_DefaultControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@ private static GameObject CreateUIElementRoot(string name, Vector2 size)
GameObject root;

#if UNITY_EDITOR
root = ObjectFactory.CreateGameObject(name);
root = ObjectFactory.CreateGameObject(name, typeof(RectTransform));
var rt = root.GetComponent<RectTransform>();
rt.sizeDelta = size;
#else
root = new GameObject(name);
#endif

RectTransform rectTransform = root.AddComponent<RectTransform>();
rectTransform.sizeDelta = size;
#endif

return root;
}

static GameObject CreateUIObject(string name, GameObject parent)
{
GameObject go = new GameObject(name);
GameObject go;
#if UNITY_EDITOR
go = ObjectFactory.CreateGameObject(name, typeof(RectTransform));
#else
go = new GameObject(name);
go.AddComponent<RectTransform>();
#endif
SetParentAndAlign(go, parent);
return go;
}
Expand Down Expand Up @@ -102,12 +109,12 @@ public static GameObject CreateScrollbar(Resources resources)
GameObject sliderArea = CreateUIObject("Sliding Area", scrollbarRoot);
GameObject handle = CreateUIObject("Handle", sliderArea);

Image bgImage = scrollbarRoot.AddComponent<Image>();
Image bgImage = AddComponent<Image>(scrollbarRoot);
bgImage.sprite = resources.background;
bgImage.type = Image.Type.Sliced;
bgImage.color = s_DefaultSelectableColor;

Image handleImage = handle.AddComponent<Image>();
Image handleImage = AddComponent<Image>(handle);
handleImage.sprite = resources.standard;
handleImage.type = Image.Type.Sliced;
handleImage.color = s_DefaultSelectableColor;
Expand All @@ -120,7 +127,7 @@ public static GameObject CreateScrollbar(Resources resources)
RectTransform handleRect = handle.GetComponent<RectTransform>();
handleRect.sizeDelta = new Vector2(20, 20);

Scrollbar scrollbar = scrollbarRoot.AddComponent<Scrollbar>();
Scrollbar scrollbar = AddComponent<Scrollbar>(scrollbarRoot);
scrollbar.handleRect = handleRect;
scrollbar.targetGraphic = handleImage;
SetDefaultColorTransitionValues(scrollbar);
Expand All @@ -132,19 +139,25 @@ public static GameObject CreateButton(Resources resources)
{
GameObject buttonRoot = CreateUIElementRoot("Button", s_ThickElementSize);

GameObject childText = new GameObject("Text (TMP)");
GameObject childText;
#if UNITY_EDITOR
childText = ObjectFactory.CreateGameObject("Text (TMP)", typeof(RectTransform));
#else
childText = new GameObject("Text (TMP)");
childText.AddComponent<RectTransform>();
#endif

SetParentAndAlign(childText, buttonRoot);

Image image = buttonRoot.AddComponent<Image>();
Image image = AddComponent<Image>(buttonRoot);
image.sprite = resources.standard;
image.type = Image.Type.Sliced;
image.color = s_DefaultSelectableColor;

Button bt = buttonRoot.AddComponent<Button>();
Button bt = AddComponent<Button>(buttonRoot);
SetDefaultColorTransitionValues(bt);

TextMeshProUGUI text = childText.AddComponent<TextMeshProUGUI>();
TextMeshProUGUI text = AddComponent<TextMeshProUGUI>(childText);
text.text = "Button";
text.alignment = TextAlignmentOptions.Center;
SetDefaultTextValues(text);
Expand All @@ -162,8 +175,7 @@ public static GameObject CreateText(Resources resources)
GameObject go = null;

#if UNITY_EDITOR
go = ObjectFactory.CreateGameObject("Text (TMP)");
ObjectFactory.AddComponent<TextMeshProUGUI>(go);
go = ObjectFactory.CreateGameObject("Text (TMP)", typeof(TextMeshProUGUI));
#else
go = CreateUIElementRoot("Text (TMP)", s_TextElementSize);
go.AddComponent<TextMeshProUGUI>();
Expand All @@ -172,7 +184,6 @@ public static GameObject CreateText(Resources resources)
return go;
}


public static GameObject CreateInputField(Resources resources)
{
GameObject root = CreateUIElementRoot("InputField (TMP)", s_ThickElementSize);
Expand All @@ -181,15 +192,15 @@ public static GameObject CreateInputField(Resources resources)
GameObject childPlaceholder = CreateUIObject("Placeholder", textArea);
GameObject childText = CreateUIObject("Text", textArea);

Image image = root.AddComponent<Image>();
Image image = AddComponent<Image>(root);
image.sprite = resources.inputField;
image.type = Image.Type.Sliced;
image.color = s_DefaultSelectableColor;

TMP_InputField inputField = root.AddComponent<TMP_InputField>();
TMP_InputField inputField = AddComponent<TMP_InputField>(root);
SetDefaultColorTransitionValues(inputField);

RectMask2D rectMask = textArea.AddComponent<RectMask2D>();
RectMask2D rectMask = AddComponent<RectMask2D>(textArea);
rectMask.padding = new Vector4(-8, -5, -8, -5);

RectTransform textAreaRectTransform = textArea.GetComponent<RectTransform>();
Expand All @@ -200,14 +211,14 @@ public static GameObject CreateInputField(Resources resources)
textAreaRectTransform.offsetMax = new Vector2(-10, -7);


TextMeshProUGUI text = childText.AddComponent<TextMeshProUGUI>();
TextMeshProUGUI text = AddComponent<TextMeshProUGUI>(childText);
text.text = "";
text.textWrappingMode = TextWrappingModes.NoWrap;
text.extraPadding = true;
text.richText = true;
SetDefaultTextValues(text);

TextMeshProUGUI placeholder = childPlaceholder.AddComponent<TextMeshProUGUI>();
TextMeshProUGUI placeholder = AddComponent<TextMeshProUGUI>(childPlaceholder);
placeholder.text = "Enter text...";
placeholder.fontSize = 14;
placeholder.fontStyle = FontStyles.Italic;
Expand All @@ -220,7 +231,7 @@ public static GameObject CreateInputField(Resources resources)
placeholder.color = placeholderColor;

// Add Layout component to placeholder.
placeholder.gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
AddComponent<LayoutElement>(placeholder.gameObject).ignoreLayout = true;

RectTransform textRectTransform = childText.GetComponent<RectTransform>();
textRectTransform.anchorMin = Vector2.zero;
Expand Down Expand Up @@ -275,28 +286,28 @@ public static GameObject CreateDropdown(Resources resources)

// Setup item UI components.

TextMeshProUGUI itemLabelText = itemLabel.AddComponent<TextMeshProUGUI>();
TextMeshProUGUI itemLabelText = AddComponent<TextMeshProUGUI>(itemLabel);
SetDefaultTextValues(itemLabelText);
itemLabelText.alignment = TextAlignmentOptions.Left;

Image itemBackgroundImage = itemBackground.AddComponent<Image>();
Image itemBackgroundImage = AddComponent<Image>(itemBackground);
itemBackgroundImage.color = new Color32(245, 245, 245, 255);

Image itemCheckmarkImage = itemCheckmark.AddComponent<Image>();
Image itemCheckmarkImage = AddComponent<Image>(itemCheckmark);
itemCheckmarkImage.sprite = resources.checkmark;

Toggle itemToggle = item.AddComponent<Toggle>();
Toggle itemToggle = AddComponent<Toggle>(item);
itemToggle.targetGraphic = itemBackgroundImage;
itemToggle.graphic = itemCheckmarkImage;
itemToggle.isOn = true;

// Setup template UI components.

Image templateImage = template.AddComponent<Image>();
Image templateImage = AddComponent<Image>(template);
templateImage.sprite = resources.standard;
templateImage.type = Image.Type.Sliced;

ScrollRect templateScrollRect = template.AddComponent<ScrollRect>();
ScrollRect templateScrollRect = AddComponent<ScrollRect>(template);
templateScrollRect.content = (RectTransform)content.transform;
templateScrollRect.viewport = (RectTransform)viewport.transform;
templateScrollRect.horizontal = false;
Expand All @@ -305,28 +316,28 @@ public static GameObject CreateDropdown(Resources resources)
templateScrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
templateScrollRect.verticalScrollbarSpacing = -3;

Mask scrollRectMask = viewport.AddComponent<Mask>();
Mask scrollRectMask = AddComponent<Mask>(viewport);
scrollRectMask.showMaskGraphic = false;

Image viewportImage = viewport.AddComponent<Image>();
Image viewportImage = AddComponent<Image>(viewport);
viewportImage.sprite = resources.mask;
viewportImage.type = Image.Type.Sliced;

// Setup dropdown UI components.

TextMeshProUGUI labelText = label.AddComponent<TextMeshProUGUI>();
TextMeshProUGUI labelText = AddComponent<TextMeshProUGUI>(label);
SetDefaultTextValues(labelText);
labelText.alignment = TextAlignmentOptions.Left;

Image arrowImage = arrow.AddComponent<Image>();
Image arrowImage = AddComponent<Image>(arrow);
arrowImage.sprite = resources.dropdown;

Image backgroundImage = root.AddComponent<Image>();
Image backgroundImage = AddComponent<Image>(root);
backgroundImage.sprite = resources.standard;
backgroundImage.color = s_DefaultSelectableColor;
backgroundImage.type = Image.Type.Sliced;

TMP_Dropdown dropdown = root.AddComponent<TMP_Dropdown>();
TMP_Dropdown dropdown = AddComponent<TMP_Dropdown>(root);
dropdown.targetGraphic = backgroundImage;
SetDefaultColorTransitionValues(dropdown);
dropdown.template = template.GetComponent<RectTransform>();
Expand Down Expand Up @@ -400,5 +411,14 @@ public static GameObject CreateDropdown(Resources resources)

return root;
}

private static T AddComponent<T>(GameObject go) where T : Component
{
#if UNITY_EDITOR
return ObjectFactory.AddComponent<T>(go);
#else
return go.AddComponent<T>();
#endif
}
}
}
7 changes: 4 additions & 3 deletions Scripts/Runtime/TMP_Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4168,12 +4168,13 @@ protected virtual Vector2 CalculatePreferredValues(ref float fontSize, Vector2 m
#region Handle Kerning
GlyphValueRecord glyphAdjustments = new GlyphValueRecord();
float characterSpacingAdjustment = m_characterSpacing;
if (m_enableKerning)
// Make sure the current character and the next are Characters (not Sprite).
if (m_enableKerning && m_textElementType == TMP_TextElementType.Character)
{
GlyphPairAdjustmentRecord adjustmentPair;
uint baseGlyphIndex = m_cached_TextElement.m_GlyphIndex;

if (m_characterCount < totalCharacterCount - 1)
if (m_characterCount < totalCharacterCount - 1 && m_textInfo.characterInfo[m_characterCount + 1].elementType == TMP_TextElementType.Character)
{
uint nextGlyphIndex = m_textInfo.characterInfo[m_characterCount + 1].textElement.m_GlyphIndex;
uint key = nextGlyphIndex << 16 | baseGlyphIndex;
Expand All @@ -4190,7 +4191,7 @@ protected virtual Vector2 CalculatePreferredValues(ref float fontSize, Vector2 m
uint previousGlyphIndex = m_textInfo.characterInfo[m_characterCount - 1].textElement.m_GlyphIndex;
uint key = baseGlyphIndex << 16 | previousGlyphIndex;

if (m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
if (textInfo.characterInfo[m_characterCount - 1].elementType == TMP_TextElementType.Character && m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
{
glyphAdjustments += adjustmentPair.secondAdjustmentRecord.glyphValueRecord;
characterSpacingAdjustment = (adjustmentPair.featureLookupFlags & UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments) == UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;
Expand Down
6 changes: 3 additions & 3 deletions Scripts/Runtime/TextMeshPro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2558,14 +2558,14 @@ protected virtual void GenerateTextMesh()
#region Handle Kerning
GlyphValueRecord glyphAdjustments = new GlyphValueRecord();
float characterSpacingAdjustment = m_characterSpacing;
if (kerning)
if (kerning && m_textElementType == TMP_TextElementType.Character)
{
k_HandleGPOSFeaturesMarker.Begin();

GlyphPairAdjustmentRecord adjustmentPair;
uint baseGlyphIndex = m_cached_TextElement.m_GlyphIndex;

if (m_characterCount < totalCharacterCount - 1)
if (m_characterCount < totalCharacterCount - 1 && m_textInfo.characterInfo[m_characterCount + 1].elementType == TMP_TextElementType.Character)
{
uint nextGlyphIndex = m_textInfo.characterInfo[m_characterCount + 1].textElement.m_GlyphIndex;
uint key = nextGlyphIndex << 16 | baseGlyphIndex;
Expand All @@ -2582,7 +2582,7 @@ protected virtual void GenerateTextMesh()
uint previousGlyphIndex = m_textInfo.characterInfo[m_characterCount - 1].textElement.m_GlyphIndex;
uint key = baseGlyphIndex << 16 | previousGlyphIndex;

if (m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
if (textInfo.characterInfo[m_characterCount - 1].elementType == TMP_TextElementType.Character && m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
{
glyphAdjustments += adjustmentPair.secondAdjustmentRecord.glyphValueRecord;
characterSpacingAdjustment = (adjustmentPair.featureLookupFlags & UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments) == UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;
Expand Down
8 changes: 3 additions & 5 deletions Scripts/Runtime/TextMeshProUGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2291,8 +2291,6 @@ protected override void OnCanvasHierarchyChanged()
TMP_UpdateManager.UnRegisterTextObjectForUpdate(this);
else if (m_IsTextObjectScaleStatic == false)
TMP_UpdateManager.RegisterTextObjectForUpdate(this);

m_havePropertiesChanged = true;
}


Expand Down Expand Up @@ -2911,14 +2909,14 @@ protected virtual void GenerateTextMesh()
#region Handle Kerning
GlyphValueRecord glyphAdjustments = new GlyphValueRecord();
float characterSpacingAdjustment = m_characterSpacing;
if (kerning)
if (kerning && m_textElementType == TMP_TextElementType.Character)
{
k_HandleGPOSFeaturesMarker.Begin();

GlyphPairAdjustmentRecord adjustmentPair;
uint baseGlyphIndex = m_cached_TextElement.m_GlyphIndex;

if (m_characterCount < totalCharacterCount - 1)
if (m_characterCount < totalCharacterCount - 1 && textInfo.characterInfo[m_characterCount + 1].elementType == TMP_TextElementType.Character)
{
uint nextGlyphIndex = m_textInfo.characterInfo[m_characterCount + 1].textElement.m_GlyphIndex;
uint key = nextGlyphIndex << 16 | baseGlyphIndex;
Expand All @@ -2935,7 +2933,7 @@ protected virtual void GenerateTextMesh()
uint previousGlyphIndex = m_textInfo.characterInfo[m_characterCount - 1].textElement.m_GlyphIndex;
uint key = baseGlyphIndex << 16 | previousGlyphIndex;

if (m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
if (textInfo.characterInfo[m_characterCount - 1].elementType == TMP_TextElementType.Character && m_currentFontAsset.m_FontFeatureTable.m_GlyphPairAdjustmentRecordLookup.TryGetValue(key, out adjustmentPair))
{
glyphAdjustments += adjustmentPair.secondAdjustmentRecord.glyphValueRecord;
characterSpacingAdjustment = (adjustmentPair.featureLookupFlags & UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments) == UnityEngine.TextCore.LowLevel.FontFeatureLookupFlags.IgnoreSpacingAdjustments ? 0 : characterSpacingAdjustment;
Expand Down
2 changes: 1 addition & 1 deletion ValidationExceptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[
{
"ValidationTest": "API Validation",
"PackageVersion": "3.2.0-pre.2"
"PackageVersion": "3.2.0-pre.8"
}
]
}
Loading

0 comments on commit 067fd10

Please sign in to comment.