forked from esukei's デバイスフォントの回転とかアンチエイリアスとか

by esukei forked from デバイスフォントの回転とかアンチエイリアスとか (diff: 9)
@author エスケイ
* デバイスフォントのtextFieldをBitmapDataに焼いて回転するテスト
* すごく適当。
♥0 | Line 40 | Modified 2010-01-08 16:02:48 | MIT License
play

ActionScript3 source code

/**
 * Copyright esukei ( http://wonderfl.net/user/esukei )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rzBS
 */

// forked from esukei's デバイスフォントの回転とかアンチエイリアスとか
/**
 * @author エスケイ
 * デバイスフォントのtextFieldをBitmapDataに焼いて回転するテスト
 * すごく適当。
 */
package {
    import flash.display.Sprite;
    import flash.text.TextField;
    public class FlashTest extends Sprite {
    	
    		private var tf:TextField;
    		private var btBmp:BakedTextBitmap;
        public function FlashTest() {
            // write as3 code here..
            tf = new TextField();
            tf.text = 'ほげほげ';
            
            btBmp = new BakedTextBitmap( tf );
            addChild(btBmp);
            
            btBmp.x = 100;
            btBmp.y = 100;
            
            btBmp.rotation = 23;
            
        }
    }
}
import flash.display.IBitmapDrawable;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
class BakedTextBitmap extends Bitmap {
	
	private var bmpData:BitmapData;
	private var tf:TextFormat;
	
	public function BakedTextBitmap( textField:TextField )
	{
		//アンチエイリアスのための適当な拡大
		tf = textField.getTextFormat();
		var hoge:* = tf.size;
		tf.size = ((typeof(hoge) === 'number')? hoge : 12 ) * 2;
		textField.setTextFormat(tf);
		textField.width *= 2;
		textField.height *= 2;
		
		bmpData = new BitmapData( textField.width, textField.height );
		bmpData.draw(textField);
		super( bmpData, 'auto', false );
		//拡大を元に戻しとく。
		width /= 2;
		height /= 2;
	}
	
}