Hi all,
I’m looking to implement a custom tag parsing/tokenization system, and TMP seemed like a good way to allow my custom effects to modify text in meaningful ways.
However I’ve hit a bit of a wall when trying to implement my own version of a ‘Bold’ effect, I’m attemtping to change the Style of a specific TMP_CharacterInfo to include Bold, which as far as I can tell, is being performed fine, however there’s no visual change in the game, so I need to call a specific Update method afterwards?
textInfo.characterInfo[characterIndex].style |= FontStyles.Bold
From looking around I found a different thread saying how the textInfo class was more for reading than editing, in which case does TMP support changing data for specific characters outside of explicit vertex/colour data? How would I change a specific character’s size programmatically for example. There’s good examples for modifying vertex and colour data, allowing character displacement and colour changing, but I haven’t found anything for styles or other data.
Thanks in advance!
I would also like to know how to do this. What I’ve found is that you can adjust characterInfo
data, and it persists, but it has no effect on how the character is displayed.
The content of the TextInfo which includes the CharacterInfo reflect the results of the text parsing and layout phase…As such, modifying the content of these data structures has no effect.
These data structures are there for query purposes like knowing the position of characters, words, lines, etc. to enable you for instance to highlight characters or display text metrics like the TMP_TextInfoDebugTool.cs doe or position the caret at specific characters like the Input Field does.
This information is also used to modify the geometry of the text contained in the MeshInfo as it is done in some of the examples included with TMP like the “Animating Vertex Attributes” scene included in the TMP Examples & Extras.
The content of the TextInfo can indirectly be used to modify the rendered text as it is done in the example scene referenced above where we first query the textInfo.characterInfo[index] to figure out what vertices a given character or word uses. Once we have this vertex index, we can then modify its vertex color or position if desired and then re-push the modified geometry to the Canvas or MeshRenderer. Again take a look at this example and related scripts to get a better understanding.
In terms of styling and more specifically bold. Bold can be achieved in two ways. (1) use a fallback font asset that contains the true bold design of the primary font asset or (2) fake bold which is done by applying dilation to a given character. When using Signed Distance Field (SDF) we can apply visual FX to the text like Dilation which inflates the text. Bold is done by telling the shader to dilate a given character. This is achieved by encoding / hinting to the shader that a character is bold by setting its SDF Scale to a negative value. In older versions of TMP SDF Scale was contained in the Y component of UV2 of the text geometry. In never versions of TMP (3.2.0-pre.x) the SDF Scale is now contained in the W component of UV0. Therefore, if you were to change the SDF scale of a character (all 4 UV0.w) to have a negative scale, those characters would be bold.
I realize the above is complicated if you seek to do this by tweaking the geometry. In some cases, it might be easier to just modify the string of text.
I’ve seen this explanation in the few threads about this I’ve found, and I’m sure it’s thankless to have to repeat it each time, so I’m sorry about that. I think the characterInfo
object and its properties (not just textInfo
) need to be marked as read only (or documented in-line as such?) for people to understand this fully. When noodling around with the API, there’s no real indication that these are not actually editable properties, mainly because you can edit them.
What I’m interested in is an API that lets me change the properties of a single character or subset of characters at runtime without modifying the text string by adding rich text tags, and without having to muck around with lower level properties manually. If it means having to “refresh” a few things and costing some efficiency, that’s okay.
My project is pretty strict about typography, so I can’t really do any SDF tricks to emulate font styles (I’m using alt/fallback font assets, which is a fantastic feature). I’m also looking specifically to add UPPERCASE and lowercase styles. These change the dimensions of the glyph and impact the text flow.
I’ll look at the examples and see if there’s something I can do, but in the end I’ll probably just have to inject rich tags (and figure out how to track and remove them at runtime, too).
1 Like