In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Investigating Japanese Device Fonts

Get Adobe Flash player
by 9re 25 Dec 2009
/**
 * Copyright 9re ( http://wonderfl.net/user/9re )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8ZiL
 */

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.text.TextFormat;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	
	public class TestGetCharBoundaries extends Sprite
	{
		
		public function TestGetCharBoundaries() 
		{
			var tf:TextField = new TextField;
			var rect:Rectangle;
			var bounds:Rectangle;
			var tfm:TextFormat = new TextFormat("_ゴシック", 18, 0, true);
			
			tf.defaultTextFormat = tfm;
			tf.text = '日本語デバイスフォント';
			resizeTextField(tf);						
			var bd:BitmapData = new BitmapData(tf.width, tf.height, true, 0xffffffff);
			bd.draw(tf);
			var bm:Bitmap = new Bitmap(bd);
			bm.x = 50;
			bm.y = 100;
			addChild(bm);
			
			tf = new TextField;
			rect = bd.getColorBoundsRect(0xffffff, 0);
			tf.text = rect.toString();			
			tf.y = 50;
			resizeTextField(tf);
			addChild(tf);
			
			bd.fillRect(rect, 0x3f0000ff);
			//bd.fillRect(tf.getBounds(this), 0x3f0000ff);
			
			tf = new TextField;
			tf.defaultTextFormat = tfm;
			tf.text = '日本語デバイスフォント';
			resizeTextField(tf);
			
			bd.draw(tf);
			
			function resizeTextField($textField:TextField):void {
				$textField.width = $textField.textWidth + 4;
				$textField.height = $textField.textHeight + 4;
			}
		}
		
	}

}