If I edit tk2dTextMesh.cs and change "private Vector2 GetMeshDimensionsForString()" to "public Vector2 GetMeshDimensionsForString()", I can iterate over each of my strings and add newlines (\n) as needed to give it a "word wrap" ability on a per-pixel (as opposed to a per-character) basis. This is especially useful when I use a variable-width font, since character-counting makes lines of lowercase "LLLL" and uppercase "WWWW" break very differently.
That said, if I try to determine the height of the text, I notice that the GetMeshDimensionsForString() calculates its height off of the font's lineHeight variable. That height is often different from the actual height of the glyphs being used (the tallest of my glyphs reaches about 42 pixels, while the .fnt file defines lineHeight to be 64).
The attached screenshot shows a popup I've created with a TextMesh, as well as the properties for that TextMesh. I have added a child GameObject and attached a BoxCollider to it to indicate to my word wrap code how large the "word wrap box" needs to be. That makes it easier for my developers to eyeball things without changing (or forgetting to change) the dimensions somewhere.
It does not correctly chop off the last line, however. What I want to do is calculate the height of the font, calculate the height of this GameObject+BoxCollider combo, and chop off anything that spills over. I should have lines 1-5, but line 6 (which has the text, "excrement at you. Stand back!") needs to actually be removed (I might add an ellipsis '...' to the end of "they will fling", but that's more of an aside).
Is there a way to calculate the height of the used glyphs, instead of relying on the lineHeight property? I assume it would take the character's 'height' and 'yoffset' into account to ensure that the tall characters (like a pipe '|') and hanging letters (like lowercase 'g' or 'y') are all handled. It might also take the lineSpacing multiplied by some scaling factor into account.
...Unless I'm just reinventing the wheel here and you already have some sort of "concatenate long lines" option that I can just call.
Ideas?