From 6776b83ce6ace33900daa8314c644218e67fd5e4 Mon Sep 17 00:00:00 2001 From: Tom Conkling Date: Wed, 2 Jul 2008 00:50:51 +0000 Subject: [PATCH] Account for kerning by always measuring the width of the truncated text field with the truncation string git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@559 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flash/TextFieldUtil.as | 25 +++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/as/com/threerings/flash/TextFieldUtil.as b/src/as/com/threerings/flash/TextFieldUtil.as index d3d02161..f12fa8ec 100644 --- a/src/as/com/threerings/flash/TextFieldUtil.as +++ b/src/as/com/threerings/flash/TextFieldUtil.as @@ -64,26 +64,23 @@ public class TextFieldUtil width /= tf.scaleX; var truncated :Boolean; - if (tf.textWidth > width && tf.text.length > 0) { - // subtract the width of our truncationString from our target width - var tmp :String = tf.text; - tf.text = truncationString; - width -= tf.textWidth; - tf.text = tmp; - + var setText :String = tf.text; + while (tf.textWidth + WIDTH_PAD > width && setText.length > 0) { // Drop characters from our string until we hit our target width. // Flash doesn't appear to provide a nicer way to get text metrics than // sticking stuff in a TextField and calling textWidth. - do { - tf.text = tf.text.substr(0, tf.text.length - 1); - } while (tf.textWidth > width && tf.text.length > 0); + setText = setText.substr(0, setText.length - 1); + tf.text = setText + truncationString; - // strip whitespace characters from the end of the truncated string - tf.text = StringUtil.trimEnd(tf.text); - - tf.appendText(truncationString); truncated = true; + } + if (truncated) { + // strip whitespace characters from the end of the truncated string + setText = StringUtil.trimEnd(setText); + tf.text = setText + truncationString; + + // resize the TextField tf.width = tf.textWidth + WIDTH_PAD; tf.height = tf.textHeight + HEIGHT_PAD; }