When I using string “RecastTileGenerator:GenerateCompressedLayers-> GenerateRecasFilter” write in the TextMeshPro, and the text component setting is normal, and I add a ContentSizeFitter and use unconstraint width and preferred height setting, and then when I change the width in rectTransform, the height will not fit the whole text correctly sometime. (the string I write above, there is special character ‘:’ you need to notice, this character unicode is in chinese set range, not ascii ‘:’, if I use another chinese character instead, this bug also occur, you need to use one font can show the chinese to
reproduce the bug, the bug is not going to occur when you using english TMP font, these font just show square replacing the charater ‘:’, and no bug occur.)
I Fixed this bug base on the TextMeshPro 4.0.0-pre.1,In the function CalculatePreferredValue(ref float fontSize, Vector2 marginSize, bool isTextAutoSizingEnabled, bool isWordWrappingEnabled) in the file named TMP_Text.cs. The changes i make listed below. My unity version is 2021.3.6f1 and use TextMeshPro 3.0.6.
(1) Line 4561: after the code “lineMarginRight = m_marginRight;”, add the additional code:
//compute preferred Width & Height
renderedHeight = m_maxTextAscender - m_ElementDescender;
(2) Line 4723: after the code “if (IsFirstWordOfLine || isLeadingCharacter == false)”, change code as below:
else if (m_isNotBreakingSpace == false && …)//this line is same as the old code
{
if (isLeadingCharacter == false)
{
if (isFollowingCharacter == false)
{
SaveWordWrappingState(ref internalWordWrapState, i, m_characterCount);
isFirstWordOfLine = false;
}
if (isFirstWordOfLline)
{
//Special handling for non-breaking space and soft line breaks
if (isWhiteSpace)
SaveWordWrappingState(ref internalSoftLineBreak, i, m_characterCount);
SaveWordWrappingState(ref internalWordWrapState, i, m_characterCount);
}
}
else
{
if (isFirstWordOfLine && isFirstCharacterOfLine)
{
//Special handling for non-breaking space and soft line breaks
if (isWhiteSpace)
SaveWordWrappingState(ref m_SavedSoftLineBreakState, i, m_characterCount);
SaveWordWrappingState(ref m_SavedWordWrapState, i, m_characterCount);
}
}
else if (isFirstWordOfLine)
{
//Special handling for non-breaking space and soft line breaks
if (isWhiteSpace && charCode != 0xAD || (charCode == 0xAD && isSoftHyphenIgnored == false)
SaveWordWrappingState(ref internalSoftLineBreak, i, m_characterCount);
SaveWordWrappingState(ref internalWordWrapState, i, m_characterCount);
}
}