[
https://issues.apache.org/jira/browse/FLEX-14317?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Justin Mclean updated FLEX-14317:
---------------------------------
Labels: easytest (was: )
> mx.core.UITextField.truncateToFit() removes all text formatting if text needs
> to be truncated
> ---------------------------------------------------------------------------------------------
>
> Key: FLEX-14317
> URL: https://issues.apache.org/jira/browse/FLEX-14317
> Project: Apache Flex
> Issue Type: Bug
> Components: mx: Text
> Affects Versions: Adobe Flex SDK Previous
> Environment: Affected OS(s): All OS Platforms
> Affected OS(s): All OS Platforms
> Language Found: English
> Reporter: Adobe JIRA
> Priority: Minor
> Labels: easytest
>
> Steps to reproduce:
> 1. Assign bold formatting to a Label, Text, or anything using a UITextField.
> 2. Reduce the width of the component so that the text cannot be fully
> displayed
> 3. call component.truncateToFit() to truncate the obscured text and replace
> it with an ellipsis
>
> Actual Results:
>
> The text is truncated, but the formatting is changed back to the text field's
> default format. If this causes a transition from bold back to normal
> formatting, it is likely that the ellipsis replacement will be too agressive,
> since the normal text now takes up less width than the bold text.
> Further, any code calling truncateToFit() needs to reformat the resulting
> text.
>
> Expected Results:
>
> The text should retain its formatting, and just put the ellipsis where it
> needs to go.
>
> Workaround (if any):
>
> Here's my suggested code fix. It works (and least, it works for text where
> everything is the same format):
> // Need to check if we should truncate, but it
> // could be due to rounding error. Let's check that it's not.
> // Examples of rounding errors happen with "South Africa" and "Game"
> // with verdana.ttf.
> if (originalText != "" && measuredWidth > w + 0.00000000000001)
> {
> // This should get us into the ballpark.
> var s:String = super.text = originalText;
> var tf:TextFormat = textField.getTextFormat();
> while (s.length > 1 && measuredWidth > w)
> {
> s = s.slice(0, -1);
> super.text = s + truncationIndicator;
> setTextFormat( tf );
> }
>
> return true;
> }
> I tried a variant that didn't save/restore the TextFormat object, and instead
> called replaceText( s.length - 2, s.length, truncationIndicator );, but that
> seemed to cause an infinite event dispatch loop. If that infinite loop could
> be fixed, then the replaceText method would be even better, since it would
> even work for text with multiple TextRuns of different formats.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira