Copy link to clipboard
Copied
Some of my single line, centre aligned TLF text fields overlap words on top of each other.
What I'm trying to do is have text fields with a fixed width and height, and a maximum font size. The text fields are dynamic but not editable (the text is assigned with AS3). When the text property is set, it starts off at the maximum font size. If the text is too big for the text box (textHeight or textWidth is bigger than the width and height dimenions I gave the textfield), then lower the font size by 1, and keep doing this until the text fits inside the textfield.
The reason I need to do this is because of localisation. A button with the word 'Ok' on it might be a 5 character word in another language, so I need the text to scale down to fit within the button.
I seemed to have this working ok with TLF 1.0 runtime, but since we upgraded to CS 5.5 with the TLF 2.0 runtime, a number of textfields are now broken.
This seems to be the problem code:
while ((m_tlfText.textWidth > m_originalDims.x) || (m_tlfText.textHeight > m_originalDims.y))
{
m_textFormat.size = int(m_textFormat.size) - 1;
m_tlfText.setTextFormat(m_textFormat);
}
m_tlfText is the TLFTextfield that has been initialised and had text assigned to it. m_originalDims is a Point containing the original length (x) and height (y) I gave the TLFTextfield during initialisation. The text cannot extend these bounds. m_textFormat is a TextFormat object containing the font size, which starts at the maximum font size I set.
This code is producing weird results. m_tlfText.textWidth and m_tlfText.textHeight seems to be changing at weird times, such as directly after the while statement. If I debug and step through the code slowly, the overlapping is not as bad. For example, if the text is "how now brown cow", if I step through the code, it will show "how now brown" correctly, but "cow" will overlap "now". But if I just run the program without stepping through code, then all 4 words will overlap each in the centre. So it seems dt is somehow affecting that while loop.
Copy link to clipboard
Copied
Set textfield lineHeight value of the text fields.