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

by igawo forked from デバイスフォントの回転とかアンチエイリアスとか (diff: 2)
@author エスケイ
* デバイスフォントのtextFieldをBitmapDataに焼いて回転するテスト
* すごく適当。
♥0 | Line 35 | Modified 2010-06-15 19:33:36 | MIT License
play

ActionScript3 source code

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

// 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 = 30;
            
        }
    }
}
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Matrix;
class BakedTextBitmap extends Bitmap {
	
	private var bmpData:BitmapData;
	private var tf:TextFormat;
	
	public function BakedTextBitmap( textField:TextField )
	{
		//アンチエイリアスのための適当な拡大
		tf = textField.getTextFormat();
		/**
		 * drawの引数にmatrixぶち込めば良かったことに後から気づいた
		 */
		//var hoge:* = tf.size;
		//tf.size = ((typeof(hoge) === 'number')? hoge : 12 ) * 4;
		//textField.setTextFormat(tf);
		//textField.width *= 4;
		//textField.height *= 4;
		
		bmpData = new BitmapData( textField.width*4, textField.height*4 );
		bmpData.draw(textField, new Matrix(4,0,0,4));
		super( bmpData );
		//拡大を元に戻しとく。
		width /= 4;
		height /= 4;
	}
	
}