2020-10-20 00:58:15 +02:00

74 lines
2.0 KiB
ActionScript
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.utils
{
import flash.text.*;
/**
* Utility class for text fields
*
* @author Tripp Bridges
*/
public class TextUtil
{
/**
* Returns the width of a text field based on a <code>TextFormat</code> object and a string to be displayed
*
* @param textValue The text
* @param tf
*
* @return Number
*/
public static function getTextWidth(textValue:String, tf:TextFormat):Number
{
var textField:TextField = new TextField();
textField.selectable = false;
textField.autoSize = TextFieldAutoSize.LEFT;
textField.text = textValue;
textField.setTextFormat(tf);
return Math.max(textField.textWidth, textField.width);
}
/**
* Returns the height of a text field based on a <code>TextFormat</code> object and a string to be displayed
*
* @param textValue The text
* @param tf
*
* @return Number
*/
public static function getTextHeight(textValue:String, tf:TextFormat):Number
{
var textField:TextField = new TextField();
textField.selectable = false;
textField.autoSize = TextFieldAutoSize.LEFT;
textField.text = textValue;
textField.setTextFormat(tf);
return textField.textHeight;
}
/**
* Changes individual property of a <code>TextFormat</code> object
*/
public static function changeTextFormatProps(tf:TextFormat, tfProps:Object):TextFormat
{
for(var i:String in tfProps)
{
tf[i] = tfProps[i];
}
return tf;
}
/**
* Creates a copy of a <code>TextFormat</code> object
*/
public static function cloneTextFormat(tf:TextFormat):TextFormat
{
return new TextFormat(tf.font, tf.size, tf.color, tf.bold, tf.italic, tf.underline, tf.url, tf.target, tf.align, tf.leftMargin, tf.rightMargin, tf.indent, tf.leading);
}
}
}